
CityMaterialCount is a constant that defines the length of g_txMats and the + 1 is for g_txDiffuse. The descriptor table for our SRVs contains CityMaterialCount + 1 entries. For the pixel shader, we define three things: a descriptor table for SRVs (our Texture2Ds), a descriptor table for Samplers and a single root constant. Now, let's look at the root signature definition, particularly, how we define the size of the unbounded array and link a root constant to matIndex. The following command line options are used to compile this shader with the Effect-Compiler Tool (FXC): fxc /Zi /E"PSSceneMain" /Od /Fo"dynamic_indexing_pixel.cso" /ps"_5_1" /nologo /enable_unbounded_descriptor_tables Additionally, to make use of unbounded arrays, the /enable_unbounded_descriptor_tables flag must also be used. To take advantage of the dynamic indexing features in HLSL requires that the shader be compiled with SM 5.1.

Both attributes are defined in the root signature of the pipeline state object used with the shader. The shader has no knowledge of the size or the array or the value of the index at compile-time. Dynamic indexing is used to index into g_txMats with matIndex, which is defined as a root constant. The unbounded array feature is illustrated by the g_txMats array as it does not specify an array size. Uint matIndex // Dynamically set index for looking up from g_txMats.ĬonstantBuffer materialConstants : register(b0, space0) įloat4 PSSceneMain(PSSceneIn input) : SV_Targetįloat3 diffuse = g_txDiffuse.Sample(g_sampler, input.tex).rgb įloat3 mat = g_txMats.Sample(g_sampler, input.tex).rgb Let's first look at the shader itself, which for this sample is a pixel shader.

