Help with directx resources

Started by
-1 comments, last by realm087 10 years, 8 months ago

Hi, I'm trying to make a game using directx but I'm finding some problems when trying to bind a structured buffer resource to my Geometry Shader. It simply won't even bother to bind the resource to a slot, despite it being created succefuly.

I'm creating the buffer like this:

D3D11_BUFFER_DESC descGPUBuffer;

ZeroMemory(&descGPUBuffer, sizeof(descGPUBuffer));

descGPUBuffer.BindFlags = D3D11_BIND_SHADER_RESOURCE;

descGPUBuffer.ByteWidth = vertexNum *

sizeof(UINT);

descGPUBuffer.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;

descGPUBuffer.StructureByteStride = sizeof(UINT);

UINT* colorIndices = new UINT[vertexNum];

ZeroMemory(colorIndices, vertexNum * sizeof(UINT));

for(int x = 0;x < vertexNum;x++)

{

colorIndices[x] = 1;

}

D3D11_SUBRESOURCE_DATA colorData;

ZeroMemory(&colorData, sizeof(colorData));

colorData.pSysMem = colorIndices;

dev->CreateBuffer(&descGPUBuffer, &colorData, &colorBuffer);

D3D11_BUFFER_DESC descBuf;

ZeroMemory( &descBuf, sizeof(descBuf) );

colorBuffer->GetDesc( &descBuf );

D3D11_SHADER_RESOURCE_VIEW_DESC descSRV;

ZeroMemory( &descSRV, sizeof(descSRV) );

descSRV.ViewDimension =

D3D11_SRV_DIMENSION_BUFFEREX;

descSRV.BufferEx.FirstElement = 0;

descSRV.Format =

DXGI_FORMAT_UNKNOWN;

descSRV.BufferEx.NumElements = descBuf.ByteWidth / descBuf.StructureByteStride;

dev->CreateShaderResourceView(colorBuffer.Get(), &descSRV, &colorSRV);

devcon->GSSetShaderResources(0, 1, &colorSRV);


and my shader where the structured buffer is declared is like this:

StructuredBuffer<uint> BufferColors: register(t0);

GSOutput calcVertex(float4 position, float3 normal)

{

GSOutput vertex;

float4 worldPosition;

vertex.position = mul(final, position);

vertex.normal = normal;

worldPosition = mul(position, world);

vertex.viewDirection = cameraPosition.xyz - worldPosition.xyz;

vertex.viewDirection = normalize(vertex.viewDirection);

return vertex;

}

[maxvertexcount(24)]

void main(point float4 input_point[1] : SV_POSITION, uint primID : SV_PrimitiveID,

inout TriangleStream< GSOutput > output)

etc...

Can you guys please help me? I'm desperate I can't really find the error.

This topic is closed to new replies.

Advertisement