Jump to content
  • Advertisement
Sign in to follow this  
littlekid

Dx10 usage of the different buffer type

This topic is 3812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently getting confuse by the usage of ConstantBuffer and Buffer. The SDK says that for ConstantBuffer, there is no need to bind the buffer to a view. Most of the SDK example use ConstantBuffer like:
cbuffer ChangesEveryFrame
{
    matrix World;
    float4 vMeshColor;
    float3 Eye;
    int Value;
};
The SDK say we can set cBuffer using any of the 2 methods: 1 (GS)(VS)(PS)SetConstantBuffer(); 2 pEffect->GetVariableByName("World")->AsMatrix()->SetMatrix((float*)&World); However if I am to use method 1, how to I populate the data inside ID3D10Buffer especially if the cbuffer contains different types like float and int. The next problem I have is how to use the values of the cBuffer in the HLSL code? Most SDK examples just uses variables like any normal HLSL variables. E.g: Color = TexColor * vMeshColor; But the SDK says to use the load function:
Quote:
http://msdn.microsoft.com/en-us/library/bb205133.aspx To read a shader-constant buffer from a shader, use the load intrinsic function. Each shader stage allows up to 15 shader-constant buffers; each buffer can hold up to 4096 constants.
If I am to use the load function, how am I suppose to write it? Plus the load intrinsic function seems to be only applicable for Texture objects.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by littlekid
However if I am to use method 1, how to I populate the data inside ID3D10Buffer especially if the cbuffer contains different types like float and int.

Either by using
ID3D10Buffer::Map or ID3D10Device::UpdateSubresource methods.

Quote:
But the SDK says to use the load function:

It is refering to buffers resources not constant buffers (that you are using).

Load instrict is used for Buffer type:
Buffer<float> my_buffer;

float temp = my_buffer.Load(10); // access 11-th element

Share this post


Link to post
Share on other sites
Thanks for the reply. I do know that I require the use of Map or UpdateSubresource to edit info in the buffer.

What I am wondering is if my constant buffer has float, int, uint, should I just do a memcpy to the memory of the buffer? E.g:

HLSL:
cBuffer FOO
{
float A;
int B;
uint C;
}

C++
void *pDest;
pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pDest);
memcpy(pDest, FloatVal, sizeof(float));
memcpy(pDest + sizeof(float), IntVal, sizeof(int));
memcpy(pDest + sizeof(float) + sizeof(int), uIntVal, sizeof(unsigned int));
pBuffer->Unmap();


Is that the right method to use?

For the load function, look at the section of the webpage.
Quote:

Figure 5. Conceptual Shader-Constant Buffer
Each element stores a 1-to-4 component constant, determined by the format of the data stored. To create a shader-constant buffer, call ID3D10Device::CreateBuffer and specify the constant-buffer bind flag D3D10_BIND_CONSTANT_BUFFER (see D3D10_BIND_FLAG).

To bind a shader-constant buffer to the pipeline, call one of these APIs: ID3D10Device::GSSetConstantBuffers, ID3D10Device::PSSetConstantBuffers, or ID3D10Device::VSSetConstantBuffers.

To read a shader-constant buffer from a shader, use the load intrinsic function. Each shader stage allows up to 15 shader-constant buffers; each buffer can hold up to 4096 constants.

Use a constant buffer to store the results of the stream-output stage.


Another question, that I have is the usage of Buffer<Type>. Is it alright to put any valid HLSL Type in it? The SDK was saying that Type can be any HLSL scalar Type.

struct FOO;
Buffer<float3x2> InstanceData;
Buffer<FOO> MyBuffer;

Are this valid?

Share this post


Link to post
Share on other sites
Quote:
Original post by littlekidIs that the right method to use?

Yes, but be careful about offsets. Compiled shader can have different offsets for struct members that C code struct. See in fxc generated assembly listing file for exact offsets.

Quote:
For the load function, look at the section of the webpage.

Hm.. Maybe you can use load instrict also like this: ChangesEveryFrame.Load(1); Dunno.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!