git.s-ol.nu ~forks/DiligentCore / 294d42f
RunTimeResourceArray test: added samplers assiduous 6 months ago
3 changed file(s) with 23 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
22 #extension GL_EXT_nonuniform_qualifier : require
33
44 uniform texture2D g_Textures[];
5 uniform sampler g_Sampler;
5 uniform sampler g_Samplers[];
66
77 uniform g_ConstantBuffers
88 {
5959 StructBuffRefValues[2] = StructBuff_Ref2;
6060
6161 uint TexIdx = index % NUM_TEXTURES;
62 uint SamIdx = index % NUM_SAMPLERS;
6263 uint BuffIdx = index % NUM_CONST_BUFFERS;
6364 uint FmtBuffIdx = index % NUM_FMT_BUFFERS;
6465 uint StructBuffIdx = index % NUM_STRUCT_BUFFERS;
6566
6667 vec4 AllCorrect = vec4(1.0, 1.0, 1.0, 1.0);
67 AllCorrect *= CheckValue(textureLod(sampler2D(g_Textures[nonuniformEXT(TexIdx)], g_Sampler), coord, 0.0), TexRefValues[TexIdx]);
68 AllCorrect *= CheckValue(textureLod(sampler2D(g_Textures[nonuniformEXT(TexIdx)], g_Samplers[nonuniformEXT(SamIdx)]), coord, 0.0), TexRefValues[TexIdx]);
6869 AllCorrect *= CheckValue(g_ConstantBufferInst[nonuniformEXT(BuffIdx)].Data, ConstBuffRefValues[BuffIdx]);
6970 AllCorrect *= CheckValue(texelFetch(g_FormattedBuffers[nonuniformEXT(FmtBuffIdx)], 0), FmtBuffRefValues[FmtBuffIdx]);
7071 AllCorrect *= CheckValue(g_ConstantBufferInst[nonuniformEXT(StructBuffIdx)].Data, StructBuffRefValues[StructBuffIdx]);
00 Texture2D g_Textures[] : register(t0, space1);
1 SamplerState g_Sampler;
1 SamplerState g_Samplers[] : register(s4, space27);
22
33 struct CBData
44 {
5757 StructBuffRefValues[2] = StructBuff_Ref2;
5858
5959 uint TexIdx = index % NUM_TEXTURES;
60 uint SamIdx = index % NUM_SAMPLERS;
6061 uint ConstBuffIdx = index % NUM_CONST_BUFFERS;
6162 uint FmtBuffIdx = index % NUM_FMT_BUFFERS;
6263 uint StructBuffIdx = index % NUM_STRUCT_BUFFERS;
6364
6465 float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0);
65 AllCorrect *= CheckValue(g_Textures[NonUniformResourceIndex(TexIdx)].SampleLevel(g_Sampler, coord, 0.0), TexRefValues[TexIdx]);
66 AllCorrect *= CheckValue(g_Textures[NonUniformResourceIndex(TexIdx)].SampleLevel(g_Samplers[NonUniformResourceIndex(SamIdx)], coord, 0.0), TexRefValues[TexIdx]);
6667 AllCorrect *= CheckValue(g_ConstantBuffers[NonUniformResourceIndex(ConstBuffIdx)].Data, ConstBuffRefValues[ConstBuffIdx]);
6768 AllCorrect *= CheckValue(g_FormattedBuffers[NonUniformResourceIndex(FmtBuffIdx)].Load(0), FmtBuffRefValues[FmtBuffIdx]);
6869 AllCorrect *= CheckValue(g_StructuredBuffers[NonUniformResourceIndex(StructBuffIdx)][0].Data, StructBuffRefValues[StructBuffIdx]);
15791579 TEXTURE_VIEW_SHADER_RESOURCE //
15801580 };
15811581
1582 constexpr Uint32 SamArraySize = 3;
1583
15821584 constexpr Uint32 ConstBuffArraySize = 7;
15831585 ReferenceBuffers RefConstBuffers{
15841586 ConstBuffArraySize,
16101612 const PipelineResourceDesc Resources[] =
16111613 {
16121614 {SHADER_TYPE_COMPUTE, "g_Textures", TexArraySize, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
1613 {SHADER_TYPE_COMPUTE, "g_Sampler", 1, SHADER_RESOURCE_TYPE_SAMPLER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE},
1615 {SHADER_TYPE_COMPUTE, "g_Samplers", SamArraySize, SHADER_RESOURCE_TYPE_SAMPLER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16141616 {SHADER_TYPE_COMPUTE, "g_ConstantBuffers", ConstBuffArraySize, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16151617 {SHADER_TYPE_COMPUTE, "g_FormattedBuffers", FmtBuffArraySize, SHADER_RESOURCE_TYPE_BUFFER_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER | PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16161618 {SHADER_TYPE_COMPUTE, "g_StructuredBuffers", StructBuffArraySize, SHADER_RESOURCE_TYPE_BUFFER_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16171619 {SHADER_TYPE_COMPUTE, "g_OutImage", 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} //
16181620 };
16191621
1620 SamplerDesc SamLinearWrapDesc{
1621 FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR,
1622 TEXTURE_ADDRESS_WRAP, TEXTURE_ADDRESS_WRAP, TEXTURE_ADDRESS_WRAP};
1623 ImmutableSamplerDesc ImmutableSamplers[] = {{SHADER_TYPE_COMPUTE, "g_Sampler", SamLinearWrapDesc}};
1624
16251622 PipelineResourceSignatureDesc Desc;
1626 Desc.Resources = Resources;
1627 Desc.NumResources = _countof(Resources);
1628 Desc.ImmutableSamplers = ImmutableSamplers;
1629 Desc.NumImmutableSamplers = _countof(ImmutableSamplers);
1630 Desc.BindingIndex = 0;
1623 Desc.Resources = Resources;
1624 Desc.NumResources = _countof(Resources);
1625 Desc.BindingIndex = 0;
16311626
16321627 pDevice->CreatePipelineResourceSignature(Desc, &pSignature);
16331628 ASSERT_NE(pSignature, nullptr);
16341629 }
16351630
1631 SamplerDesc SamLinearWrapDesc{
1632 FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR,
1633 TEXTURE_ADDRESS_WRAP, TEXTURE_ADDRESS_WRAP, TEXTURE_ADDRESS_WRAP};
1634 RefCntAutoPtr<ISampler> pSampler;
1635 pDevice->CreateSampler(SamLinearWrapDesc, &pSampler);
1636 ASSERT_NE(pSampler, nullptr);
1637 IDeviceObject* ppSamplers[] = {pSampler, pSampler, pSampler};
1638 static_assert(_countof(ppSamplers) == SamArraySize, "Invalid sampler array size");
1639
16361640 ComputePipelineStateCreateInfo PSOCreateInfo;
16371641
16381642 auto& PSODesc = PSOCreateInfo.PSODesc;
16431647 ShaderMacroHelper Macros;
16441648
16451649 Macros.AddShaderMacro("NUM_TEXTURES", TexArraySize);
1650 Macros.AddShaderMacro("NUM_SAMPLERS", SamArraySize);
16461651 Macros.AddShaderMacro("NUM_CONST_BUFFERS", ConstBuffArraySize);
16471652 Macros.AddShaderMacro("NUM_FMT_BUFFERS", FmtBuffArraySize);
16481653 Macros.AddShaderMacro("NUM_STRUCT_BUFFERS", StructBuffArraySize);
16961701 ASSERT_TRUE(pTestingSwapChain);
16971702 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_OutImage")->Set(pTestingSwapChain->GetCurrentBackBufferUAV());
16981703 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_Textures")->SetArray(RefTextures.GetViewObjects(0), 0, TexArraySize);
1704 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_Samplers")->SetArray(ppSamplers, 0, SamArraySize);
16991705 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_ConstantBuffers")->SetArray(RefConstBuffers.GetBuffObjects(0), 0, ConstBuffArraySize);
17001706 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_FormattedBuffers")->SetArray(RefFmtBuffers.GetViewObjects(0), 0, FmtBuffArraySize);
17011707 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_StructuredBuffers")->SetArray(RefStructBuffers.GetViewObjects(0), 0, StructBuffArraySize);