• Create Account

### #Actualwngabh11

Posted 12 February 2013 - 02:01 AM

As far as I know, There are two way passing values to variables in HLSL constant buffer.


cbuffer cbGeometryRender : register( b0 )
{
float4x4 WorldMatrix;
float4x4 ViewMatrix;
float4x4 ProjMatrix;
float4x4 WVPMatrix;
float4x4 VPMatrix;
float3 EyePos;
float3 LightDir; // start at the sun
float4 SplitPos;
};


The first way is to use Effect11 Library. For example


ID3DX11Effect *pEffect; // initialize when compiling the fx file
ID3DX11EffectVectorVariable *pEyePos = pEffect->GetVariableByName("EyePos")->AsVector();
pEyePos->SetFloatVector(......);


The second way is to use the constant buffer created with the desc in the following.

 D3D11_BUFFER_DESC bd;
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof( CONSTANT_BUFFER_STRUCT );
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;
hr = pd3dDevice->CreateBuffer( &bd, NULL, &g_pCB );


On each frame, we map g_pCB to b0, assign the values, and then unmap it. After that, We set constant buffer for each stage.

IS Anyone who know what the differences are between these two methods?

which is better?

can Effect11 Library be used with deferred context?

Can these two ways be used together, i.e., using Effect Library compile the fx file and using the second way to pass the value to GPU?

### #1wngabh11

Posted 12 February 2013 - 01:47 AM

As far as I know, There are two way passing values to variables in HLSL constant buffer.


cbuffer cbGeometryRender : register( b0 )
{
float4x4 WorldMatrix;
float4x4 ViewMatrix;
float4x4 ProjMatrix;
float4x4 WVPMatrix;
float4x4 VPMatrix;
float3 EyePos;
float3 LightDir; // start at the sun
float4 SplitPos;
};


The first way is to use Effect11 Library. For example


ID3DX11Effect *pEffect; // initialize when compiling the fx file
ID3DX11EffectVectorVariable *pEyePos = pEffect->GetVariableByName("EyePos")->AsVector();
pEyePos->SetFloatVector(......);


The second way is to use the constant buffer created with the desc in the following.

 D3D11_BUFFER_DESC bd;
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof( CONSTANT_BUFFER_STRUCT );
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;
hr = pd3dDevice->CreateBuffer( &bd, NULL, &g_pCB );


On each frame, we map g_pCB to b0, assign the values, and then unmap it. After that, We set constant buffer for each stage.

IS Anyone who know what the differences are between these two methods?

Can these two ways be used together, i.e., using Effect Library compile the fx file and using the second way to pass the value to GPU?

PARTNERS