question

$$ANON_USER$$ avatar image
0 Votes"
$$ANON_USER$$ asked ·

Directx 12 Constant Buffer View in a UWP application skeleton.

 void Sample3DSceneRenderer::CreateDeviceDependentResources()
 {
     auto d3dDevice = m_deviceResources->GetD3DDevice();
    
     // Create a root signature with a single constant buffer slot.
     {
         CD3DX12_DESCRIPTOR_RANGE range;
         CD3DX12_ROOT_PARAMETER parameter;
    
         range.Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);
         parameter.InitAsDescriptorTable(1, &range, D3D12_SHADER_VISIBILITY_VERTEX);
    
         D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =
             D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | // Only the input assembler stage needs access to the constant buffer.
             D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |
             D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |
             D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS |
             D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS;
    
         CD3DX12_ROOT_SIGNATURE_DESC descRootSignature;
         descRootSignature.Init(1, &parameter, 0, nullptr, rootSignatureFlags);
    
         ComPtr<ID3DBlob> pSignature;
         ComPtr<ID3DBlob> pError;
         DX::ThrowIfFailed(D3D12SerializeRootSignature(&descRootSignature, D3D_ROOT_SIGNATURE_VERSION_1, pSignature.GetAddressOf(), pError.GetAddressOf()));
         DX::ThrowIfFailed(d3dDevice->CreateRootSignature(0, pSignature->GetBufferPointer(), pSignature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature)));
         NAME_D3D12_OBJECT(m_rootSignature);
     }


Based off what I know about DirectX12 and the skeleton app I have read through it leads me to make some presumptions.

  • That CD3DX12_ROOT_PARAMETER parameter is being used as a descriptor table and range is where the "stuff" to be contained will be located.

  • That the constant buffer should only be visible to the vertex shader as per "D3D12_SHADER_VISIBILITY_VERTEX"

  • That a constant buffer view will exist bound to "shaderResourceSlot0"


I am now lead to wonder what the constant buffer will actually contain or how it will be filled with "stuff"


In the SampleVertexShader.hlsl it contains this snippet:

 // A constant buffer that stores the three basic column-major matrices for composing geometry.
 cbuffer ModelViewProjectionConstantBuffer : register(b0)
 {
     matrix model;
     matrix view;
     matrix projection;
 };

I was curious if "b0" is the shaderResourceSlot0" as the range parameter combination is set to (or if b0 and shaderResourceSlot0 are the same). Also the constant buffer was initialized to a size of 1 but here in HLSL I see a cbuffer that contains three matrixes. Is it possible I could get some explanation as to how these things relate to each other and also how a size 1 constant buffer might contain three matrixes?

Thank You!




windows-uwp
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Based on this document, it mentions constant buffers contain shader constant data and can be accessed by any GPU shader, until it is necessary to change the data. A constant buffer that stores the three basic column-major matrices for composing geometry. Here describes some information about the ModelViewProjectionConstantBuffer, you can refer to it.

1 Vote 1 · ·

Have you solved your issue? Does Fay's reply make sense?

0 Votes 0 · ·

1 Answer

$$ANON_USER$$ avatar image
0 Votes"
$$ANON_USER$$ answered ·

OK. Setting up a constant buffer view and root signature. That's what I am getting right now with a D3D12_SHADER_VISIBILITY_VERTEX visibility level with a descriptor table. That's about what I was able to understand at this point and that there are packing rules.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.