Question

I'm having some trouble finding the source of my error. Everything works fine with the app yet I'm getting spammed with these 2 warnings:

D3D11 WARNING: ID3D11DeviceContext::DrawIndexedInstanced: Input vertex slot 1 has stride 12 which is less than the minimum stride logically expected from the current Input Layout (48 bytes). This is OK, as hardware is perfectly capable of reading overlapping data. However the developer probably did not intend to make use of this behavior.  [ EXECUTION WARNING #355: DEVICE_DRAW_VERTEX_BUFFER_STRIDE_TOO_SMALL]
D3D11 WARNING: ID3D11DeviceContext::DrawIndexedInstanced: Vertex Buffer at the input vertex slot 1 is not big enough for what the Draw*() call expects to traverse. This is OK, as reading off the end of the Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior.  [ EXECUTION WARNING #356: DEVICE_DRAW_VERTEX_BUFFER_TOO_SMALL]

It seems that my stride value is incorrect, yet I cannot find where I went wrong. The app just draws multiple textured boxes using instancing.

The input layout:

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
    { "WORLD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
    { "WORLD", 1, DXGI_FORMAT_R32G32B32_FLOAT, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
    { "WORLD", 2, DXGI_FORMAT_R32G32B32_FLOAT, 1, 24, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
    { "WORLD", 3, DXGI_FORMAT_R32G32B32_FLOAT, 1, 36, D3D11_INPUT_PER_INSTANCE_DATA, 1 }

};

// Create the input layout
D3DX11_PASS_DESC passDesc;
mTech->GetPassByIndex(0)->GetDesc(&passDesc);

HR(md3dDevice->CreateInputLayout(vertexDesc, 6, passDesc.pIAInputSignature, 
    passDesc.IAInputSignatureSize, &mInputLayout));

Relevant code in the draw function.

UINT stride[] = {sizeof(Vertex), sizeof(InstanceData)};
UINT offset[] = {0,0};
ID3D11Buffer* ivbs[2] = {mBoxVB, mInstancedBuffer};

md3dImmediateContext->IASetVertexBuffers(0, 2, ivbs, stride, offset);

md3dImmediateContext->DrawIndexedInstanced(24, 4, 0, 0, 0);

The structures that hold the data:

struct Vertex
{
XMFLOAT3 Pos;
XMFLOAT2 Tex;
};

struct InstanceData
{
XMFLOAT3 World; 
};

The right stride should be 12 since that is the bytesize of XMFLOAT3 and DXGI_FORMAT_R32G32B32_FLOAT which go into input slot 1. Yet I think it expects to total size of my instance buffer which I filled with an array of 4 holding XMFLOAT3 data (4*12=48 which fits the warning).

Instancebuffer:

InstanceData mInstanceData[4];

mInstanceData[0].World = XMFLOAT3(
                1.0f, 1.0f, 1.0f);

mInstanceData[1].World = XMFLOAT3(
                3.0f, 1.0f, 1.0f);

mInstanceData[2].World = XMFLOAT3(
                5.0f, 1.0f, 1.0f);

mInstanceData[3].World = XMFLOAT3(
                7.0f, 1.0f, 1.0f);

D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_DYNAMIC;
ibd.ByteWidth = sizeof(InstanceData) * 4;
ibd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
ibd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;

D3D11_SUBRESOURCE_DATA instanceData;
instanceData.pSysMem = mInstanceData;
instanceData.SysMemPitch = 0;
instanceData.SysMemSlicePitch = 0;


HR(md3dDevice->CreateBuffer(&ibd, &instanceData, &mInstancedBuffer));

Is it wrong to fill an array with the data and use it like that? the program still runs fine. Any help would be greatly appreciated.

Was it helpful?

Solution

UINT stride[] = {sizeof(Vertex), 4 * sizeof(InstanceData)}; instead of UINT stride[] = {sizeof(Vertex), sizeof(InstanceData)}; if you really use four float3 per instance.

If the instance data is really an unique float3, then the three extra semantics in the input layout are wrong instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top