git.s-ol.nu ~forks/DiligentCore / 7a23e17
RunTimeResourceArray test: added formatted and structured buffers assiduous 6 months ago
3 changed file(s) with 80 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
88 {
99 vec4 Data;
1010 }g_ConstantBufferInst[];
11
12 uniform samplerBuffer g_FormattedBuffers[];
13
14 layout(std140) readonly buffer g_StructuredBuffers
15 {
16 vec4 Data;
17 }g_StructuredBufferInst[];
1118
1219 vec4 CheckValue(vec4 Val, vec4 Expected)
1320 {
3946 ConstBuffRefValues[5] = ConstBuff_Ref5;
4047 ConstBuffRefValues[6] = ConstBuff_Ref6;
4148
42 uint TexIdx = index % NUM_TEXTURES;
43 uint BuffIdx = index % NUM_CONST_BUFFERS;
49 float4 FmtBuffRefValues[NUM_FMT_BUFFERS];
50 FmtBuffRefValues[0] = FmtBuff_Ref0;
51 FmtBuffRefValues[1] = FmtBuff_Ref1;
52 FmtBuffRefValues[2] = FmtBuff_Ref2;
53 FmtBuffRefValues[3] = FmtBuff_Ref3;
54 FmtBuffRefValues[4] = FmtBuff_Ref4;
55
56 float4 StructBuffRefValues[NUM_STRUCT_BUFFERS];
57 StructBuffRefValues[0] = StructBuff_Ref0;
58 StructBuffRefValues[1] = StructBuff_Ref1;
59 StructBuffRefValues[2] = StructBuff_Ref2;
60
61 uint TexIdx = index % NUM_TEXTURES;
62 uint BuffIdx = index % NUM_CONST_BUFFERS;
63 uint FmtBuffIdx = index % NUM_FMT_BUFFERS;
64 uint StructBuffIdx = index % NUM_STRUCT_BUFFERS;
4465
4566 vec4 AllCorrect = vec4(1.0, 1.0, 1.0, 1.0);
4667 AllCorrect *= CheckValue(textureLod(sampler2D(g_Textures[nonuniformEXT(TexIdx)], g_Sampler), coord, 0.0), TexRefValues[TexIdx]);
4768 AllCorrect *= CheckValue(g_ConstantBufferInst[nonuniformEXT(BuffIdx)].Data, ConstBuffRefValues[BuffIdx]);
69 AllCorrect *= CheckValue(texelFetch(g_FormattedBuffers[nonuniformEXT(FmtBuffIdx)], 0), FmtBuffRefValues[FmtBuffIdx]);
70 AllCorrect *= CheckValue(g_ConstantBufferInst[nonuniformEXT(StructBuffIdx)].Data, StructBuffRefValues[StructBuffIdx]);
4871
4972 return AllCorrect;
5073 }
55 float4 Data;
66 };
77 ConstantBuffer<CBData> g_ConstantBuffers[] : register(b10, space5);
8
9 Buffer g_FormattedBuffers[]: register(t15, space7);
10
11 struct StructBuffData
12 {
13 float4 Data;
14 };
15 StructuredBuffer<StructBuffData> g_StructuredBuffers[];
816
917 float4 CheckValue(float4 Val, float4 Expected)
1018 {
3644 ConstBuffRefValues[5] = ConstBuff_Ref5;
3745 ConstBuffRefValues[6] = ConstBuff_Ref6;
3846
39 uint TexIdx = index % NUM_TEXTURES;
40 uint BuffIdx = index % NUM_CONST_BUFFERS;
47 float4 FmtBuffRefValues[NUM_FMT_BUFFERS];
48 FmtBuffRefValues[0] = FmtBuff_Ref0;
49 FmtBuffRefValues[1] = FmtBuff_Ref1;
50 FmtBuffRefValues[2] = FmtBuff_Ref2;
51 FmtBuffRefValues[3] = FmtBuff_Ref3;
52 FmtBuffRefValues[4] = FmtBuff_Ref4;
53
54 float4 StructBuffRefValues[NUM_STRUCT_BUFFERS];
55 StructBuffRefValues[0] = StructBuff_Ref0;
56 StructBuffRefValues[1] = StructBuff_Ref1;
57 StructBuffRefValues[2] = StructBuff_Ref2;
58
59 uint TexIdx = index % NUM_TEXTURES;
60 uint ConstBuffIdx = index % NUM_CONST_BUFFERS;
61 uint FmtBuffIdx = index % NUM_FMT_BUFFERS;
62 uint StructBuffIdx = index % NUM_STRUCT_BUFFERS;
4163
4264 float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0);
4365 AllCorrect *= CheckValue(g_Textures[NonUniformResourceIndex(TexIdx)].SampleLevel(g_Sampler, coord, 0.0), TexRefValues[TexIdx]);
44 AllCorrect *= CheckValue(g_ConstantBuffers[NonUniformResourceIndex(BuffIdx)].Data, ConstBuffRefValues[BuffIdx]);
66 AllCorrect *= CheckValue(g_ConstantBuffers[NonUniformResourceIndex(ConstBuffIdx)].Data, ConstBuffRefValues[ConstBuffIdx]);
67 AllCorrect *= CheckValue(g_FormattedBuffers[NonUniformResourceIndex(FmtBuffIdx)].Load(0), FmtBuffRefValues[FmtBuffIdx]);
68 AllCorrect *= CheckValue(g_StructuredBuffers[NonUniformResourceIndex(StructBuffIdx)][0].Data, StructBuffRefValues[StructBuffIdx]);
4569
4670 return AllCorrect;
4771 }
15861586 BIND_UNIFORM_BUFFER //
15871587 };
15881588
1589 constexpr Uint32 FmtBuffArraySize = 5;
1590 ReferenceBuffers RefFmtBuffers{
1591 FmtBuffArraySize,
1592 USAGE_DEFAULT,
1593 BIND_SHADER_RESOURCE,
1594 BUFFER_VIEW_SHADER_RESOURCE,
1595 BUFFER_MODE_FORMATTED //
1596 };
1597
1598 constexpr Uint32 StructBuffArraySize = 3;
1599 ReferenceBuffers RefStructBuffers{
1600 StructBuffArraySize,
1601 USAGE_DEFAULT,
1602 BIND_SHADER_RESOURCE,
1603 BUFFER_VIEW_SHADER_RESOURCE,
1604 BUFFER_MODE_STRUCTURED //
1605 };
1606
15891607 RefCntAutoPtr<IPipelineResourceSignature> pSignature;
15901608
15911609 {
15941612 {SHADER_TYPE_COMPUTE, "g_Textures", TexArraySize, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
15951613 {SHADER_TYPE_COMPUTE, "g_Sampler", 1, SHADER_RESOURCE_TYPE_SAMPLER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE},
15961614 {SHADER_TYPE_COMPUTE, "g_ConstantBuffers", ConstBuffArraySize, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
1615 {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},
1616 {SHADER_TYPE_COMPUTE, "g_StructuredBuffers", StructBuffArraySize, SHADER_RESOURCE_TYPE_BUFFER_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
15971617 {SHADER_TYPE_COMPUTE, "g_OutImage", 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} //
15981618 };
15991619
16241644
16251645 Macros.AddShaderMacro("NUM_TEXTURES", TexArraySize);
16261646 Macros.AddShaderMacro("NUM_CONST_BUFFERS", ConstBuffArraySize);
1647 Macros.AddShaderMacro("NUM_FMT_BUFFERS", FmtBuffArraySize);
1648 Macros.AddShaderMacro("NUM_STRUCT_BUFFERS", StructBuffArraySize);
16271649 if (IsGLSL)
16281650 Macros.AddShaderMacro("float4", "vec4");
16291651 for (Uint32 i = 0; i < TexArraySize; ++i)
16301652 Macros.AddShaderMacro((String{"Tex2D_Ref"} + std::to_string(i)).c_str(), RefTextures.GetColor(i));
16311653 for (Uint32 i = 0; i < ConstBuffArraySize; ++i)
16321654 Macros.AddShaderMacro((String{"ConstBuff_Ref"} + std::to_string(i)).c_str(), RefConstBuffers.GetValue(i));
1655 for (Uint32 i = 0; i < FmtBuffArraySize; ++i)
1656 Macros.AddShaderMacro((String{"FmtBuff_Ref"} + std::to_string(i)).c_str(), RefFmtBuffers.GetValue(i));
1657 for (Uint32 i = 0; i < StructBuffArraySize; ++i)
1658 Macros.AddShaderMacro((String{"StructBuff_Ref"} + std::to_string(i)).c_str(), RefStructBuffers.GetValue(i));
16331659
16341660 RefCntAutoPtr<IShader> pCS;
16351661 {
16711697 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_OutImage")->Set(pTestingSwapChain->GetCurrentBackBufferUAV());
16721698 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_Textures")->SetArray(RefTextures.GetViewObjects(0), 0, TexArraySize);
16731699 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_ConstantBuffers")->SetArray(RefConstBuffers.GetBuffObjects(0), 0, ConstBuffArraySize);
1700 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_FormattedBuffers")->SetArray(RefFmtBuffers.GetViewObjects(0), 0, FmtBuffArraySize);
1701 pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_StructuredBuffers")->SetArray(RefStructBuffers.GetViewObjects(0), 0, StructBuffArraySize);
16741702 pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
16751703
16761704 pContext->SetPipelineState(pPSO);