Let's say I have the following registers in my HLSL 5.1 shader:

Texture2DArray g_texture_array : register(t1);
Texture2D g_texture[10] : register(t0);

I had in mind that maybe I could put all of those resources in the same descriptor heap, and then reference them through a single descriptor table using 2 seperate ranges. I'm not 100% clear if it's possible to do so, or if I absolutely have to create 2 seperate descriptor tables. This is what I have tried so far:

    std::array<D3D12_DESCRIPTOR_RANGE, 2> texture_ranges;
    D3D12_DESCRIPTOR_RANGE textures_range;
    textures_range.BaseShaderRegister = 0;
    textures_range.NumDescriptors = 10;
    textures_range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;//indicates this range should immediately follow the preceding range.
    textures_range.RegisterSpace = 0;

    texture_ranges[0] = textures_range;

    D3D12_DESCRIPTOR_RANGE texture_array_range;
    texture_array_range.BaseShaderRegister = 1;
    texture_array_range.NumDescriptors = 1;
    texture_array_range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;//indicates this range should immediately follow the preceding range.
    texture_array_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE::D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
    texture_array_range.RegisterSpace = 0;

    texture_ranges[1] = texture_array_range;

    D3D12_DESCRIPTOR_RANGE samplers_range = {};
    samplers_range.BaseShaderRegister = 0;
    samplers_range.NumDescriptors = 2;
    samplers_range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
    samplers_range.RegisterSpace = 0;

    CD3DX12_ROOT_PARAMETER root_parameter[6];
    root_parameter[0].InitAsDescriptorTable(2, texture_ranges.data(), D3D12_SHADER_VISIBILITY::D3D12_SHADER_VISIBILITY_PIXEL);

The API seem to suggest to me that a descriptor table can accept multiple ranges. Is that not the case?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.