git.s-ol.nu ~forks/DiligentCore / 9586772
RunTimeResourceArray Test: added RW formatted buffers assiduous 6 months ago
3 changed file(s) with 31 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
2323 vec4 Data;
2424 }g_RWStructBuffersInst[];
2525
26
27 layout(rgba32f) uniform imageBuffer g_RWFormattedBuffers[];
2628
2729 vec4 CheckValue(vec4 Val, vec4 Expected)
2830 {
7173 RWTexRefValues[1] = RWTex2D_Ref1;
7274 RWTexRefValues[2] = RWTex2D_Ref2;
7375
74 float4 RWStructBuffRefValues[NUM_RWSTRUCT_BUFFERS];
76 vec4 RWStructBuffRefValues[NUM_RWSTRUCT_BUFFERS];
7577 RWStructBuffRefValues[0] = RWStructBuff_Ref0;
7678 RWStructBuffRefValues[1] = RWStructBuff_Ref1;
7779 RWStructBuffRefValues[2] = RWStructBuff_Ref2;
7880 RWStructBuffRefValues[3] = RWStructBuff_Ref3;
81
82 vec4 RWFmtBuffRefValues[NUM_RWFMT_BUFFERS];
83 RWFmtBuffRefValues[0] = RWFmtBuff_Ref0;
84 RWFmtBuffRefValues[1] = RWFmtBuff_Ref1;
7985
8086 uint TexIdx = index % NUM_TEXTURES;
8187 uint SamIdx = index % NUM_SAMPLERS;
8490 uint StructBuffIdx = index % NUM_STRUCT_BUFFERS;
8591 uint RWTexIdx = index % NUM_RWTEXTURES;
8692 uint RWStructBuffIdx = index % NUM_RWSTRUCT_BUFFERS;
93 uint RWFmtBuffIdx = index % NUM_RWFMT_BUFFERS;
8794
8895 vec4 AllCorrect = vec4(1.0, 1.0, 1.0, 1.0);
8996 AllCorrect *= CheckValue(textureLod(sampler2D(g_Textures[nonuniformEXT(TexIdx)], g_Samplers[nonuniformEXT(SamIdx)]), coord, 0.0), TexRefValues[TexIdx]);
9299 AllCorrect *= CheckValue(g_StructuredBufferInst[nonuniformEXT(StructBuffIdx)].Data, StructBuffRefValues[StructBuffIdx]);
93100 AllCorrect *= CheckValue(imageLoad(g_RWTextures[nonuniformEXT(RWTexIdx)], ivec2(coord * 10)), RWTexRefValues[RWTexIdx]);
94101 AllCorrect *= CheckValue(g_RWStructBuffersInst[nonuniformEXT(RWStructBuffIdx)].Data, RWStructBuffRefValues[RWStructBuffIdx]);
102 AllCorrect *= CheckValue(imageLoad(g_RWFormattedBuffers[nonuniformEXT(RWFmtBuffIdx)], 0), RWFmtBuffRefValues[RWFmtBuffIdx]);
95103
96104 return AllCorrect;
97105 }
2424 };
2525 RWStructuredBuffer<RWStructBuffData> g_RWStructBuffers[] : register(u10, space6);
2626 #endif
27
28 RWBuffer<float4> g_RWFormattedBuffers[] : register(u10, space41);
2729
2830
2931 float4 CheckValue(float4 Val, float4 Expected)
7981 RWStructBuffRefValues[2] = RWStructBuff_Ref2;
8082 RWStructBuffRefValues[3] = RWStructBuff_Ref3;
8183
84 float4 RWFmtBuffRefValues[NUM_RWFMT_BUFFERS];
85 RWFmtBuffRefValues[0] = RWFmtBuff_Ref0;
86 RWFmtBuffRefValues[1] = RWFmtBuff_Ref1;
87
8288 uint TexIdx = index % NUM_TEXTURES;
8389 uint SamIdx = index % NUM_SAMPLERS;
8490 uint ConstBuffIdx = index % NUM_CONST_BUFFERS;
8692 uint StructBuffIdx = index % NUM_STRUCT_BUFFERS;
8793 uint RWTexIdx = index % NUM_RWTEXTURES;
8894 uint RWStructBuffIdx = index % NUM_RWSTRUCT_BUFFERS;
95 uint RWFmtBuffIdx = index % NUM_RWFMT_BUFFERS;
8996
9097 float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0);
9198 AllCorrect *= CheckValue(g_Textures[NonUniformResourceIndex(TexIdx)].SampleLevel(g_Samplers[NonUniformResourceIndex(SamIdx)], coord, 0.0), TexRefValues[TexIdx]);
96103 #ifndef VULKAN
97104 AllCorrect *= CheckValue(g_RWStructBuffers[NonUniformResourceIndex(RWStructBuffIdx)][0].Data, RWStructBuffRefValues[RWStructBuffIdx]);
98105 #endif
106 AllCorrect *= CheckValue(g_RWFormattedBuffers[NonUniformResourceIndex(RWFmtBuffIdx)][0], RWFmtBuffRefValues[RWFmtBuffIdx]);
99107
100108 return AllCorrect;
101109 }
16241624 BUFFER_MODE_STRUCTURED //
16251625 };
16261626
1627 constexpr Uint32 RWFormattedBuffArraySize = 2;
1628 ReferenceBuffers RefRWFormattedBuffers{
1629 RWFormattedBuffArraySize,
1630 USAGE_DEFAULT,
1631 BIND_UNORDERED_ACCESS,
1632 BUFFER_VIEW_UNORDERED_ACCESS,
1633 BUFFER_MODE_FORMATTED //
1634 };
1635
16271636 RefCntAutoPtr<IPipelineResourceSignature> pSignature;
16281637
16291638 {
16361645 {SHADER_TYPE_COMPUTE, "g_StructuredBuffers", StructBuffArraySize, SHADER_RESOURCE_TYPE_BUFFER_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16371646 {SHADER_TYPE_COMPUTE, "g_RWTextures", RWTexArraySize, SHADER_RESOURCE_TYPE_TEXTURE_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16381647 {SHADER_TYPE_COMPUTE, "g_RWStructBuffers", RWStructBuffArraySize, SHADER_RESOURCE_TYPE_BUFFER_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
1648 {SHADER_TYPE_COMPUTE, "g_RWFormattedBuffers", RWFormattedBuffArraySize, SHADER_RESOURCE_TYPE_BUFFER_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER | PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
16391649 {SHADER_TYPE_COMPUTE, "g_OutImage", 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} //
16401650 };
16411651
16731683 Macros.AddShaderMacro("NUM_STRUCT_BUFFERS", StructBuffArraySize);
16741684 Macros.AddShaderMacro("NUM_RWTEXTURES", RWTexArraySize);
16751685 Macros.AddShaderMacro("NUM_RWSTRUCT_BUFFERS", RWStructBuffArraySize);
1686 Macros.AddShaderMacro("NUM_RWFMT_BUFFERS", RWFormattedBuffArraySize);
16761687 if (IsGLSL)
16771688 Macros.AddShaderMacro("float4", "vec4");
16781689 for (Uint32 i = 0; i < TexArraySize; ++i)
16871698 Macros.AddShaderMacro((String{"RWTex2D_Ref"} + std::to_string(i)).c_str(), RefRWTextures.GetColor(i));
16881699 for (Uint32 i = 0; i < RWStructBuffArraySize; ++i)
16891700 Macros.AddShaderMacro((String{"RWStructBuff_Ref"} + std::to_string(i)).c_str(), RefRWStructBuffers.GetValue(i));
1701 for (Uint32 i = 0; i < RWFormattedBuffArraySize; ++i)
1702 Macros.AddShaderMacro((String{"RWFmtBuff_Ref"} + std::to_string(i)).c_str(), RefRWFormattedBuffers.GetValue(i));
16901703
16911704 RefCntAutoPtr<IShader> pCS;
16921705 {
17401753 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_StructuredBuffers")->SetArray(RefStructBuffers.GetViewObjects(0), 0, StructBuffArraySize);
17411754 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_RWTextures")->SetArray(RefRWTextures.GetViewObjects(0), 0, RWTexArraySize);
17421755 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_RWStructBuffers")->SetArray(RefRWStructBuffers.GetViewObjects(0), 0, RWStructBuffArraySize);
1756 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_RWFormattedBuffers")->SetArray(RefRWFormattedBuffers.GetViewObjects(0), 0, RWFormattedBuffArraySize);
17431757 pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
17441758
17451759 pContext->SetPipelineState(pPSO);