forked from DiligentGraphics/DiligentCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInlineConstantsTest.cpp
More file actions
1315 lines (1076 loc) · 51.1 KB
/
InlineConstantsTest.cpp
File metadata and controls
1315 lines (1076 loc) · 51.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2025-2026 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
#include "GPUTestingEnvironment.hpp"
#include "TestingSwapChainBase.hpp"
#include "gtest/gtest.h"
#include "RenderStateCache.hpp"
#include "GraphicsTypesX.hpp"
#include "FastRand.hpp"
#include "MapHelper.hpp"
namespace Diligent
{
namespace Testing
{
void RenderDrawCommandReference(ISwapChain* pSwapChain, const float* pClearColor = nullptr);
void ComputeShaderReference(ISwapChain* pSwapChain);
} // namespace Testing
} // namespace Diligent
using namespace Diligent;
using namespace Diligent::Testing;
namespace
{
namespace HLSL
{
const std::string InlineConstantsTest_VS{
R"(
cbuffer cbInlinePositions
{
float4 g_Positions[6];
}
cbuffer cbInlineColors
{
float4 g_Colors[3];
}
struct PSInput
{
float4 Pos : SV_POSITION;
float3 Color : COLOR;
};
void main(uint VertexId : SV_VertexId,
out PSInput PSIn)
{
PSIn.Pos = g_Positions[VertexId];
PSIn.Color = g_Colors[VertexId % 3].rgb;
}
)"};
const std::string InlineConstantsTest_PS{
R"(
struct PSInput
{
float4 Pos : SV_POSITION;
float3 Color : COLOR;
};
cbuffer cbInlineColors
{
float4 g_Colors[3];
}
float4 main(in PSInput PSIn) : SV_Target
{
float3 Color = PSIn.Color.rgb;
Color.r *= g_Colors[0].a;
Color.g *= g_Colors[1].a;
Color.b *= g_Colors[2].a;
return float4(Color, 1.0);
}
)"};
const std::string VulkanPushConstants_VS{
R"(
struct PushConstants_t
{
float4 g_Positions[6];
float4 g_Colors[3];
};
[[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants;
struct PSInput
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};
void main(uint VertexId : SV_VertexId, out PSInput PSIn)
{
PSIn.Pos = PushConstants.g_Positions[VertexId];
PSIn.Color = PushConstants.g_Colors[VertexId % 3];
}
)"};
const std::string VulkanPushConstants_PS{
R"(
struct PushConstants_t
{
float4 g_Positions[6];
float4 g_Colors[3];
};
[[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants;
struct PSInput
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};
float4 main(in PSInput PSIn) : SV_Target
{
// Use push constants from PS to apply color modulation
// This ensures both VS and PS access the same PushConstants
return float4(
PSIn.Color.r * PushConstants.g_Colors[0].r,
PSIn.Color.g * PushConstants.g_Colors[1].g,
PSIn.Color.b * PushConstants.g_Colors[2].b,
PSIn.Color.a);
}
)"};
const std::string InlineConstantsTest_CS{
R"(
cbuffer cbInlineData
{
float4 g_Data[4];
}
#ifndef VK_IMAGE_FORMAT
# define VK_IMAGE_FORMAT(x)
#endif
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_Output;
[numthreads(16, 16, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
float4 Color = float4(float2(DTid.xy % 256u) / 256.0, 0.0, 1.0);
Color *= (g_Data[0] + g_Data[1] + g_Data[2]) * g_Data[3];
g_Output[DTid.xy] = Color;
}
)"};
} // namespace HLSL
float4 g_Positions[] = {
float4{-1.0f, -0.5f, 0.f, 1.f},
float4{-0.5f, +0.5f, 0.f, 1.f},
float4{0.0f, -0.5f, 0.f, 1.f},
float4{+0.0f, -0.5f, 0.f, 1.f},
float4{+0.5f, +0.5f, 0.f, 1.f},
float4{+1.0f, -0.5f, 0.f, 1.f},
};
float4 g_Colors[] = {
float4{1.f, 0.f, 0.f, 1.f},
float4{0.f, 1.f, 0.f, 1.f},
float4{0.f, 0.f, 1.f, 1.f},
};
float4 g_ComputeData[] = {
float4{1.f, 0.f, 0.f, 0.f},
float4{0.f, 1.f, 0.f, 0.f},
float4{0.f, 0.f, 1.f, 1.f},
float4{1.f, 1.f, 1.f, 1.f},
};
constexpr Uint32 kNumPosConstants = sizeof(g_Positions) / 4;
constexpr Uint32 kNumColConstants = sizeof(g_Colors) / 4;
constexpr Uint32 kNumComputeConstants = sizeof(g_ComputeData) / 4;
class InlineConstants : public ::testing::Test
{
protected:
static void SetUpTestSuite()
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
if (!pDevice->GetDeviceInfo().IsD3DDevice() && !pDevice->GetDeviceInfo().IsVulkanDevice() && !pDevice->GetDeviceInfo().IsGLDevice())
{
GTEST_SKIP();
}
ShaderCreateInfo ShaderCI;
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
{
ShaderCI.Desc = {"Inline constants test", SHADER_TYPE_VERTEX, true};
ShaderCI.EntryPoint = "main";
ShaderCI.Source = HLSL::InlineConstantsTest_VS.c_str();
pDevice->CreateShader(ShaderCI, &sm_Res.pVS);
ASSERT_NE(sm_Res.pVS, nullptr);
}
{
ShaderCI.Desc = {"Inline constants test", SHADER_TYPE_PIXEL, true};
ShaderCI.EntryPoint = "main";
ShaderCI.Source = HLSL::InlineConstantsTest_PS.c_str();
pDevice->CreateShader(ShaderCI, &sm_Res.pPS);
ASSERT_NE(sm_Res.pPS, nullptr);
}
}
static void TearDownTestSuite()
{
sm_Res = {};
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
pEnv->Reset();
}
static void TestSignatures(Uint32 NumSignatures);
static void Present()
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
IDeviceContext* pContext = pEnv->GetDeviceContext();
pSwapChain->Present();
pContext->Flush();
pContext->InvalidateState();
}
static void VerifyPSOFromCache(IPipelineState* pPSO,
IShaderResourceBinding* pSRB);
struct Resources
{
RefCntAutoPtr<IShader> pVS;
RefCntAutoPtr<IShader> pPS;
};
static Resources sm_Res;
static FastRandFloat sm_Rnd;
};
InlineConstants::Resources InlineConstants::sm_Res;
FastRandFloat InlineConstants::sm_Rnd{0, 0.f, 1.f};
TEST_F(InlineConstants, ResourceLayout1)
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
IDeviceContext* pContext = pEnv->GetDeviceContext();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
RefCntAutoPtr<IBuffer> pColBuffer = pEnv->CreateBuffer(
BufferDesc{
"Color buffer",
sizeof(g_Colors),
BIND_UNIFORM_BUFFER,
USAGE_DEFAULT,
},
g_Colors);
ASSERT_TRUE(pColBuffer);
for (Uint32 pos_type = 0; pos_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++pos_type)
{
const float ClearColor[] = {sm_Rnd(), sm_Rnd(), sm_Rnd(), sm_Rnd()};
RenderDrawCommandReference(pSwapChain, ClearColor);
SHADER_RESOURCE_VARIABLE_TYPE PosType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(pos_type);
GraphicsPipelineStateCreateInfoX PsoCI{"Inline constants test"};
PipelineResourceLayoutDescX ResLayoutDesc;
ResLayoutDesc
.AddVariable(SHADER_TYPE_VERTEX, "cbInlinePositions", PosType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS)
.AddVariable(SHADER_TYPE_VS_PS, "cbInlineColors", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE);
PsoCI
.AddRenderTarget(pSwapChain->GetDesc().ColorBufferFormat)
.SetPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.AddShader(sm_Res.pVS)
.AddShader(sm_Res.pPS)
.SetResourceLayout(ResLayoutDesc)
.SetSRBAllocationGranularity(4);
PsoCI.GraphicsPipeline.DepthStencilDesc.DepthEnable = False;
RefCntAutoPtr<IPipelineState> pPSO;
pDevice->CreateGraphicsPipelineState(PsoCI, &pPSO);
ASSERT_TRUE(pPSO);
if (PosType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
IShaderResourceVariable* pVar = pPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pVar);
pVar->SetInlineConstants(g_Positions, 0, kNumPosConstants);
}
RefCntAutoPtr<IShaderResourceBinding> pSRB;
pPSO->CreateShaderResourceBinding(&pSRB, true);
ASSERT_TRUE(pSRB);
IShaderResourceVariable* pPosVar = nullptr;
if (PosType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
pPosVar = pSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pPosVar);
}
{
IShaderResourceVariable* pColVar = pSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlineColors");
ASSERT_TRUE(pColVar);
pColVar->Set(pColBuffer);
}
ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()};
pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->SetPipelineState(pPSO);
if (pPosVar == nullptr)
{
// Draw both triangles as positions are static
pContext->Draw({6, DRAW_FLAG_VERIFY_ALL});
}
else
{
// Draw first triangle
pPosVar->SetInlineConstants(g_Positions, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
// Draw second triangle
pPosVar->SetInlineConstants(g_Positions[0].Data() + kNumPosConstants / 2, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL | DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT});
}
Present();
std::cout << TestingEnvironment::GetCurrentTestStatusString() << ' '
<< " Pos " << GetShaderVariableTypeLiteralName(PosType) << std::endl;
}
}
TEST_F(InlineConstants, ResourceLayout2)
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
IDeviceContext* pContext = pEnv->GetDeviceContext();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
for (Uint32 pos_type = 0; pos_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++pos_type)
{
for (Uint32 col_type = 0; col_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++col_type)
{
const float ClearColor[] = {sm_Rnd(), sm_Rnd(), sm_Rnd(), sm_Rnd()};
RenderDrawCommandReference(pSwapChain, ClearColor);
SHADER_RESOURCE_VARIABLE_TYPE PosType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(pos_type);
SHADER_RESOURCE_VARIABLE_TYPE ColType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(col_type);
GraphicsPipelineStateCreateInfoX PsoCI{"Inline constants test"};
PipelineResourceLayoutDescX ResLayoutDesc;
ResLayoutDesc
.AddVariable(SHADER_TYPE_VERTEX, "cbInlinePositions", PosType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS)
.AddVariable(SHADER_TYPE_VS_PS, "cbInlineColors", ColType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS);
PsoCI
.AddRenderTarget(pSwapChain->GetDesc().ColorBufferFormat)
.SetPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.AddShader(sm_Res.pVS)
.AddShader(sm_Res.pPS)
.SetResourceLayout(ResLayoutDesc)
.SetSRBAllocationGranularity(4);
PsoCI.GraphicsPipeline.DepthStencilDesc.DepthEnable = False;
RefCntAutoPtr<IPipelineState> pPSO;
pDevice->CreateGraphicsPipelineState(PsoCI, &pPSO);
ASSERT_TRUE(pPSO);
if (PosType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
IShaderResourceVariable* pVar = pPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pVar);
pVar->SetInlineConstants(g_Positions, 0, kNumPosConstants);
}
if (ColType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
IShaderResourceVariable* pVar = pPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cbInlineColors");
ASSERT_TRUE(pVar);
pVar->SetInlineConstants(g_Colors, 0, kNumColConstants);
}
RefCntAutoPtr<IShaderResourceBinding> pSRB;
pPSO->CreateShaderResourceBinding(&pSRB, true);
ASSERT_TRUE(pSRB);
IShaderResourceVariable* pPosVar = nullptr;
if (PosType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
pPosVar = pSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pPosVar);
}
IShaderResourceVariable* pColVarVS = nullptr;
IShaderResourceVariable* pColVarPS = nullptr;
if (ColType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
pColVarVS = pSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlineColors");
ASSERT_TRUE(pColVarVS);
pColVarPS = pSRB->GetVariableByName(SHADER_TYPE_PIXEL, "cbInlineColors");
ASSERT_TRUE(pColVarPS);
}
ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()};
pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
if (pColVarVS != nullptr)
{
// Set first half of color constants before committing SRB
pColVarVS->SetInlineConstants(g_Colors, 0, kNumColConstants / 2);
}
pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
if (pColVarPS != nullptr)
{
// Set second half of color constants after committing SRB
pColVarPS->SetInlineConstants(g_Colors[0].Data() + kNumColConstants / 2, kNumColConstants / 2, kNumColConstants / 2);
}
pContext->SetPipelineState(pPSO);
if (pPosVar == nullptr)
{
// Draw both triangles as positions are static
pContext->Draw({6, DRAW_FLAG_VERIFY_ALL});
}
else
{
// Draw first triangle
pPosVar->SetInlineConstants(g_Positions, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
// Draw second triangle
pPosVar->SetInlineConstants(g_Positions[0].Data() + kNumPosConstants / 2, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL | DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT});
}
Present();
std::cout << TestingEnvironment::GetCurrentTestStatusString() << ' '
<< " Pos " << GetShaderVariableTypeLiteralName(PosType) << ','
<< " Col " << GetShaderVariableTypeLiteralName(ColType) << std::endl;
}
}
}
TEST_F(InlineConstants, ComputeResourceLayout)
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
IDeviceContext* pContext = pEnv->GetDeviceContext();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
// Check compute shader support
if (!pDevice->GetDeviceInfo().Features.ComputeShaders)
{
GTEST_SKIP() << "Compute shaders are not supported by this device";
}
RefCntAutoPtr<ITestingSwapChain> pTestingSwapChain{pSwapChain, IID_TestingSwapChain};
if (!pTestingSwapChain)
{
GTEST_SKIP() << "Compute shader test requires testing swap chain";
}
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();
// Create compute shader
RefCntAutoPtr<IShader> pCS;
{
ShaderCreateInfo ShaderCI;
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
ShaderCI.Desc = {"Inline constants compute test", SHADER_TYPE_COMPUTE, true};
ShaderCI.EntryPoint = "main";
ShaderCI.Source = HLSL::InlineConstantsTest_CS.c_str();
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
pDevice->CreateShader(ShaderCI, &pCS);
ASSERT_NE(pCS, nullptr);
}
ITextureView* pOutputUAV = pTestingSwapChain->GetCurrentBackBufferUAV();
ASSERT_NE(pOutputUAV, nullptr);
for (Uint32 resType = 0; resType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++resType)
{
ComputeShaderReference(pSwapChain);
SHADER_RESOURCE_VARIABLE_TYPE ResType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(resType);
// Create PSO with inline constants
ComputePipelineStateCreateInfoX PsoCI{"Inline constants compute test"};
PipelineResourceLayoutDescX ResLayoutDesc;
ResLayoutDesc.AddVariable(SHADER_TYPE_COMPUTE, "cbInlineData", ResType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS);
PsoCI
.AddShader(pCS)
.SetResourceLayout(ResLayoutDesc)
.SetSRBAllocationGranularity(4);
RefCntAutoPtr<IPipelineState> pPSO;
pDevice->CreateComputePipelineState(PsoCI, &pPSO);
ASSERT_TRUE(pPSO);
// Set static inline constants on PSO before creating SRB
if (ResType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
IShaderResourceVariable* pInlineDataVar = pPSO->GetStaticVariableByName(SHADER_TYPE_COMPUTE, "cbInlineData");
ASSERT_NE(pInlineDataVar, nullptr);
pInlineDataVar->SetInlineConstants(g_ComputeData, 0, kNumComputeConstants);
}
{
IShaderResourceVariable* pOutputVar = pPSO->GetStaticVariableByName(SHADER_TYPE_COMPUTE, "g_Output");
ASSERT_NE(pOutputVar, nullptr);
pOutputVar->Set(pOutputUAV);
}
// Create SRB
RefCntAutoPtr<IShaderResourceBinding> pSRB;
pPSO->CreateShaderResourceBinding(&pSRB, true);
ASSERT_TRUE(pSRB);
// Set mutable/dynamic inline constants on SRB
IShaderResourceVariable* pDataVar = nullptr;
if (ResType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
pDataVar = pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "cbInlineData");
ASSERT_NE(pDataVar, nullptr);
}
pContext->SetPipelineState(pPSO);
if (pDataVar != nullptr)
{
// Set first half of constants before committing SRB
pDataVar->SetInlineConstants(g_ComputeData, 0, kNumComputeConstants / 2);
}
pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
if (pDataVar != nullptr)
{
// Set second half of constants after committing SRB
pDataVar->SetInlineConstants(g_ComputeData[0].Data() + kNumComputeConstants / 2, kNumComputeConstants / 2, kNumComputeConstants / 2);
}
// Dispatch
DispatchComputeAttribs DispatchAttribs;
DispatchAttribs.ThreadGroupCountX = (SCDesc.Width + 15) / 16;
DispatchAttribs.ThreadGroupCountY = (SCDesc.Height + 15) / 16;
pContext->DispatchCompute(DispatchAttribs);
Present();
std::cout << TestingEnvironment::GetCurrentTestStatusString() << ' '
<< " ResType " << GetShaderVariableTypeLiteralName(ResType) << std::endl;
}
}
void InlineConstants::TestSignatures(Uint32 NumSignatures)
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
IDeviceContext* pContext = pEnv->GetDeviceContext();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
RefCntAutoPtr<IBuffer> pConstBuffer = pEnv->CreateBuffer({"InlineConstants - dummy const buffer", 256, BIND_UNIFORM_BUFFER});
ASSERT_TRUE(pConstBuffer);
RefCntAutoPtr<ITexture> pTexture = pEnv->CreateTexture("InlineConstants - dummy texture", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, 64, 64);
ASSERT_TRUE(pTexture);
ITextureView* pTexSRV = pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
ASSERT_TRUE(pTexSRV);
for (Uint32 pos_type = 0; pos_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++pos_type)
{
for (Uint32 col_type = 0; col_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++col_type)
{
const float ClearColor[] = {sm_Rnd(), sm_Rnd(), sm_Rnd(), sm_Rnd()};
RenderDrawCommandReference(pSwapChain, ClearColor);
SHADER_RESOURCE_VARIABLE_TYPE PosType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(pos_type);
SHADER_RESOURCE_VARIABLE_TYPE ColType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(col_type);
RefCntAutoPtr<IPipelineResourceSignature> pPosSign;
RefCntAutoPtr<IPipelineResourceSignature> pColSign;
PipelineResourceSignatureDescX SignDesc{"Inline constants test"};
SignDesc
.AddResource(SHADER_TYPE_VERTEX, "cb0_stat", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_STATIC, PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS)
.AddResource(SHADER_TYPE_VERTEX, "cb0_mut", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
.AddResource(SHADER_TYPE_VERTEX, "cb0_dyn", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
.AddResource(SHADER_TYPE_VERTEX, "tex0_stat", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
.AddResource(SHADER_TYPE_VERTEX, "tex0_mut", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
.AddResource(SHADER_TYPE_VERTEX, "tex0_dyn", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
.AddResource(SHADER_TYPE_VERTEX, "cbInlinePositions", kNumPosConstants, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, PosType, PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS);
SignDesc.SetSRBAllocationGranularity(4);
if (NumSignatures == 2)
{
pDevice->CreatePipelineResourceSignature(SignDesc, &pPosSign);
ASSERT_TRUE(pPosSign);
SignDesc.Clear();
SignDesc.Name = "Inline constants test 2";
SignDesc.BindingIndex = 1;
}
SignDesc.AddResource(SHADER_TYPE_VERTEX, "cb1_stat", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_STATIC, PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS)
.AddResource(SHADER_TYPE_VERTEX, "cb1_mut", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
.AddResource(SHADER_TYPE_VERTEX, "cb1_dyn", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
.AddResource(SHADER_TYPE_VERTEX, "tex1_stat", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
.AddResource(SHADER_TYPE_VERTEX, "tex1_mut", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
.AddResource(SHADER_TYPE_VERTEX, "tex1_dyn", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
.AddResource(SHADER_TYPE_VS_PS, "cbInlineColors", kNumColConstants, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, ColType, PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
.AddResource(SHADER_TYPE_VERTEX, "cb2_stat", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_STATIC, PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS)
.AddResource(SHADER_TYPE_VERTEX, "cb2_mut", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
.AddResource(SHADER_TYPE_VERTEX, "cb2_dyn", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
.AddResource(SHADER_TYPE_VERTEX, "tex2_stat", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
.AddResource(SHADER_TYPE_VERTEX, "tex2_mut", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
.AddResource(SHADER_TYPE_VERTEX, "tex2_dyn", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC);
if (NumSignatures == 1)
{
pDevice->CreatePipelineResourceSignature(SignDesc, &pPosSign);
ASSERT_TRUE(pPosSign);
pColSign = pPosSign;
}
else if (NumSignatures == 2)
{
pDevice->CreatePipelineResourceSignature(SignDesc, &pColSign);
ASSERT_TRUE(pColSign);
}
else
{
GTEST_FAIL() << "Invalid number of signatures: " << NumSignatures;
}
pPosSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cb0_stat")->Set(pConstBuffer);
pPosSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "tex0_stat")->Set(pTexSRV);
pColSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cb1_stat")->Set(pConstBuffer);
pColSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "tex1_stat")->Set(pTexSRV);
pColSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cb2_stat")->Set(pConstBuffer);
pColSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "tex2_stat")->Set(pTexSRV);
GraphicsPipelineStateCreateInfoX PsoCI{"Inline constants test"};
PsoCI
.AddRenderTarget(pSwapChain->GetDesc().ColorBufferFormat)
.SetPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.AddShader(sm_Res.pVS)
.AddShader(sm_Res.pPS)
.AddSignature(pPosSign);
if (NumSignatures == 2)
{
PsoCI.AddSignature(pColSign);
}
PsoCI.GraphicsPipeline.DepthStencilDesc.DepthEnable = False;
RefCntAutoPtr<IPipelineState> pPSO;
pDevice->CreateGraphicsPipelineState(PsoCI, &pPSO);
ASSERT_TRUE(pPSO);
if (PosType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
IShaderResourceVariable* pVar = pPosSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pVar);
pVar->SetInlineConstants(g_Positions, 0, kNumPosConstants);
}
if (ColType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
IShaderResourceVariable* pVar = pColSign->GetStaticVariableByName(SHADER_TYPE_VERTEX, "cbInlineColors");
ASSERT_TRUE(pVar);
pVar->SetInlineConstants(g_Colors, 0, kNumColConstants);
}
RefCntAutoPtr<IShaderResourceBinding> pPosSRB;
pPosSign->CreateShaderResourceBinding(&pPosSRB, true);
ASSERT_TRUE(pPosSRB);
RefCntAutoPtr<IShaderResourceBinding> pColSRB;
if (NumSignatures == 1)
{
pColSRB = pPosSRB;
}
else if (NumSignatures == 2)
{
pColSign->CreateShaderResourceBinding(&pColSRB, true);
ASSERT_TRUE(pColSRB);
}
pPosSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cb0_mut")->Set(pConstBuffer);
pPosSRB->GetVariableByName(SHADER_TYPE_VERTEX, "tex0_mut")->Set(pTexSRV);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cb1_mut")->Set(pConstBuffer);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "tex1_mut")->Set(pTexSRV);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cb2_mut")->Set(pConstBuffer);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "tex2_mut")->Set(pTexSRV);
pPosSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cb0_dyn")->Set(pConstBuffer);
pPosSRB->GetVariableByName(SHADER_TYPE_VERTEX, "tex0_dyn")->Set(pTexSRV);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cb1_dyn")->Set(pConstBuffer);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "tex1_dyn")->Set(pTexSRV);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cb2_dyn")->Set(pConstBuffer);
pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "tex2_dyn")->Set(pTexSRV);
IShaderResourceVariable* pPosVar = nullptr;
if (PosType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
pPosVar = pPosSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pPosVar);
}
IShaderResourceVariable* pColVarVS = nullptr;
IShaderResourceVariable* pColVarPS = nullptr;
if (ColType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
{
pColVarVS = pColSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlineColors");
ASSERT_TRUE(pColVarVS);
pColVarPS = pColSRB->GetVariableByName(SHADER_TYPE_PIXEL, "cbInlineColors");
ASSERT_TRUE(pColVarPS);
}
ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()};
pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
if (pColVarVS != nullptr)
{
// Set first half of color constants before committing SRB
pColVarVS->SetInlineConstants(g_Colors, 0, kNumColConstants / 2);
}
pContext->CommitShaderResources(pPosSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
if (NumSignatures == 2)
{
pContext->TransitionShaderResources(pColSRB);
pContext->CommitShaderResources(pColSRB, RESOURCE_STATE_TRANSITION_MODE_VERIFY);
}
if (pColVarPS != nullptr)
{
// Set second half of color constants after committing SRB
pColVarPS->SetInlineConstants(g_Colors[0].Data() + kNumColConstants / 2, kNumColConstants / 2, kNumColConstants / 2);
}
pContext->SetPipelineState(pPSO);
if (pPosVar == nullptr)
{
// Draw both triangles as positions are static
pContext->Draw({6, DRAW_FLAG_VERIFY_ALL});
}
else
{
// Draw first triangle
pPosVar->SetInlineConstants(g_Positions, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
// Draw second triangle
pPosVar->SetInlineConstants(g_Positions[0].Data() + kNumPosConstants / 2, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
}
Present();
std::cout << TestingEnvironment::GetCurrentTestStatusString() << ' '
<< " Pos " << GetShaderVariableTypeLiteralName(PosType) << ','
<< " Col " << GetShaderVariableTypeLiteralName(ColType) << std::endl;
}
}
}
TEST_F(InlineConstants, ResourceSignature)
{
TestSignatures(1);
}
TEST_F(InlineConstants, TwoResourceSignatures)
{
TestSignatures(2);
}
// Test for "Inline Constants Cross-Signature Commit Inconsistency" fix.
//
// This test verifies that inline constants work correctly when an SRB created
// from one signature is used with a PSO created from a different but compatible
// signature instance.
//
// Bug scenario:
// 1. PSO is created with Signature A
// 2. SRB is created from Signature B (compatible but different instance)
// 3. Inline constants are set through SRB
// 4. BindResources() binds buffers from SRB cache (pointing to Signature B's buffers)
// 5. BUG (fixed): UpdateInlineConstantBuffers() was updating Signature A's buffers
// instead of the buffers from SRB cache
//
// The fix ensures that UpdateInlineConstantBuffers() updates the buffer from
// SRB cache - the same buffer that was bound during BindResources().
//
// In Vulkan, only the first inline constant uses push constants (always works).
// The second inline constant uses buffer-emulated path where this bug manifested.
// Therefore, this test uses TWO inline constant buffers to ensure we test both paths.
TEST_F(InlineConstants, CrossSignatureSRB)
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
IDeviceContext* pContext = pEnv->GetDeviceContext();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
const float ClearColor[] = {sm_Rnd(), sm_Rnd(), sm_Rnd(), sm_Rnd()};
RenderDrawCommandReference(pSwapChain, ClearColor);
// Create TWO IDENTICAL but SEPARATE signature instances.
// This is the key to reproducing the cross-signature issue:
// - pSign1 and pSign2 are compatible (same resources)
// - But they are different instances with separate internal buffers
RefCntAutoPtr<IPipelineResourceSignature> pSign1, pSign2;
PipelineResourceSignatureDescX SignDesc{"Cross-Signature Test 1"};
SignDesc
// First inline constant (Vulkan: push constants path)
.AddResource(SHADER_TYPE_VS_PS, "cbInlineColors", kNumColConstants,
SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE,
PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
// Second inline constant (Vulkan: buffer-emulated path - where the bug was)
.AddResource(SHADER_TYPE_VERTEX, "cbInlinePositions", kNumPosConstants,
SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE,
PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS);
// Create first signature instance
pDevice->CreatePipelineResourceSignature(SignDesc, &pSign1);
ASSERT_TRUE(pSign1);
// Create second signature instance with identical descriptor.
// This creates a separate instance with its own internal buffers.
SignDesc.SetName("Cross-Signature Test 2");
pDevice->CreatePipelineResourceSignature(SignDesc, &pSign2);
ASSERT_TRUE(pSign2);
EXPECT_NE(pSign1, pSign2);
// IMPORTANT: pSign1 and pSign2 are compatible but have separate buffer allocations.
// Using an SRB from pSign2 with a PSO from pSign1 tests the cross-signature path.
EXPECT_TRUE(pSign1->IsCompatibleWith(pSign2));
// Create PSO using signature 1
GraphicsPipelineStateCreateInfoX PsoCI{"Cross-Signature Test"};
PsoCI
.AddRenderTarget(pSwapChain->GetDesc().ColorBufferFormat)
.SetPrimitiveTopology(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.AddShader(sm_Res.pVS)
.AddShader(sm_Res.pPS)
.AddSignature(pSign1); // PSO uses signature 1
PsoCI.GraphicsPipeline.DepthStencilDesc.DepthEnable = False;
RefCntAutoPtr<IPipelineState> pPSO;
pDevice->CreateGraphicsPipelineState(PsoCI, &pPSO);
ASSERT_TRUE(pPSO);
// Create SRB from signature 2 (DIFFERENT from PSO's signature!).
// This is the critical part: SRB is from pSign2, PSO is from pSign1.
RefCntAutoPtr<IShaderResourceBinding> pSRB;
pSign2->CreateShaderResourceBinding(&pSRB, true);
ASSERT_TRUE(pSRB);
IShaderResourceVariable* pPosVar = pSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlinePositions");
ASSERT_TRUE(pPosVar);
IShaderResourceVariable* pColVar = pSRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbInlineColors");
ASSERT_TRUE(pColVar);
// Create a dummy dynamic buffer and map it to allocate dynamic space and make sure
// that dynamic offset is non-zero in Vulkan backend.
RefCntAutoPtr<IBuffer> pDummyCB = pEnv->CreateBuffer({"InlineConstants - dummy const buffer", 256, BIND_UNIFORM_BUFFER, USAGE_DYNAMIC, CPU_ACCESS_WRITE});
{
MapHelper<Uint8> pData{pContext, pDummyCB, MAP_WRITE, MAP_FLAG_DISCARD};
}
ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()};
pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pContext->SetPipelineState(pPSO);
pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
// Set inline constants and draw
pColVar->SetInlineConstants(g_Colors, 0, kNumColConstants);
pPosVar->SetInlineConstants(g_Positions, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
pPosVar->SetInlineConstants(g_Positions[0].Data() + kNumPosConstants / 2, 0, kNumPosConstants / 2);
pContext->Draw({3, DRAW_FLAG_VERIFY_ALL});
Present();
}
constexpr Uint32 kCacheContentVersion = 7;
RefCntAutoPtr<IRenderStateCache> CreateCache(IRenderDevice* pDevice,
bool HotReload,
bool OptimizeGLShaders,
IDataBlob* pCacheData = nullptr,
IShaderSourceInputStreamFactory* pShaderReloadFactory = nullptr)
{
RenderStateCacheCreateInfo CacheCI{
pDevice,
GPUTestingEnvironment::GetInstance()->GetArchiverFactory(),
RENDER_STATE_CACHE_LOG_LEVEL_VERBOSE,
RENDER_STATE_CACHE_FILE_HASH_MODE_BY_CONTENT,
HotReload,
};
RefCntAutoPtr<IRenderStateCache> pCache;
CreateRenderStateCache(CacheCI, &pCache);
if (pCacheData != nullptr)
pCache->Load(pCacheData, kCacheContentVersion);
return pCache;
}
void CreateShadersFromCache(IRenderStateCache* pCache, bool PresentInCache, IShader** ppVS, IShader** ppPS)
{
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
ShaderCreateInfo ShaderCI;
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
{
ShaderCI.Desc = {"Inline constants test", SHADER_TYPE_VERTEX, true};
ShaderCI.EntryPoint = "main";
ShaderCI.Source = HLSL::InlineConstantsTest_VS.c_str();
if (pCache != nullptr)
{
EXPECT_EQ(pCache->CreateShader(ShaderCI, ppVS), PresentInCache);
}
else
{