@@ -165,6 +165,125 @@ InlineConstants::Resources InlineConstants::sm_Res;
165165FastRandFloat InlineConstants::sm_Rnd{0 , 0 .f , 1 .f };
166166
167167
168+ TEST_F (InlineConstants, ResourceLayout)
169+ {
170+ GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance ();
171+ IRenderDevice* pDevice = pEnv->GetDevice ();
172+ IDeviceContext* pContext = pEnv->GetDeviceContext ();
173+ ISwapChain* pSwapChain = pEnv->GetSwapChain ();
174+ if (pDevice->GetDeviceInfo ().Type != RENDER_DEVICE_TYPE_D3D12)
175+ {
176+ GTEST_SKIP ();
177+ }
178+
179+ for (Uint32 pos_type = 0 ; pos_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++pos_type)
180+ {
181+ for (Uint32 col_type = 0 ; col_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++col_type)
182+ {
183+ const float ClearColor[] = {sm_Rnd (), sm_Rnd (), sm_Rnd (), sm_Rnd ()};
184+ RenderDrawCommandReference (pSwapChain, ClearColor);
185+
186+ SHADER_RESOURCE_VARIABLE_TYPE PosType = static_cast <SHADER_RESOURCE_VARIABLE_TYPE>(pos_type);
187+ SHADER_RESOURCE_VARIABLE_TYPE ColType = static_cast <SHADER_RESOURCE_VARIABLE_TYPE>(col_type);
188+
189+ GraphicsPipelineStateCreateInfoX PsoCI{" Inline constants test" };
190+
191+ PipelineResourceLayoutDescX ResLayoutDesc;
192+ ResLayoutDesc
193+ .AddVariable (SHADER_TYPE_VERTEX, " cbInlinePositions" , PosType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS)
194+ .AddVariable (SHADER_TYPE_VERTEX, " cbInlineColors" , ColType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS);
195+
196+ PsoCI
197+ .AddRenderTarget (pSwapChain->GetDesc ().ColorBufferFormat )
198+ .SetPrimitiveTopology (PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
199+ .AddShader (sm_Res.pVS )
200+ .AddShader (sm_Res.pPS )
201+ .SetResourceLayout (ResLayoutDesc);
202+ PsoCI.GraphicsPipeline .DepthStencilDesc .DepthEnable = False;
203+
204+ RefCntAutoPtr<IPipelineState> pPSO;
205+ pDevice->CreateGraphicsPipelineState (PsoCI, &pPSO);
206+ ASSERT_TRUE (pPSO);
207+
208+ if (PosType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
209+ {
210+ IShaderResourceVariable* pVar = pPSO->GetStaticVariableByName (SHADER_TYPE_VERTEX, " cbInlinePositions" );
211+ ASSERT_TRUE (pVar);
212+ pVar->SetInlineConstants (g_Positions, 0 , kNumPosConstants );
213+ }
214+
215+ if (ColType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
216+ {
217+ IShaderResourceVariable* pVar = pPSO->GetStaticVariableByName (SHADER_TYPE_VERTEX, " cbInlineColors" );
218+ ASSERT_TRUE (pVar);
219+ pVar->SetInlineConstants (g_Colors, 0 , kNumColConstants );
220+ }
221+
222+ RefCntAutoPtr<IShaderResourceBinding> pSRB;
223+ pPSO->CreateShaderResourceBinding (&pSRB, true );
224+ ASSERT_TRUE (pSRB);
225+
226+ IShaderResourceVariable* pPosVar = nullptr ;
227+ if (PosType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
228+ {
229+ pPosVar = pSRB->GetVariableByName (SHADER_TYPE_VERTEX, " cbInlinePositions" );
230+ ASSERT_TRUE (pPosVar);
231+ }
232+
233+ IShaderResourceVariable* pColVar = nullptr ;
234+ if (ColType != SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
235+ {
236+ pColVar = pSRB->GetVariableByName (SHADER_TYPE_VERTEX, " cbInlineColors" );
237+ ASSERT_TRUE (pColVar);
238+ }
239+
240+ ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV ()};
241+ pContext->SetRenderTargets (1 , pRTVs, nullptr , RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
242+ pContext->ClearRenderTarget (pRTVs[0 ], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
243+
244+
245+ if (pColVar != nullptr )
246+ {
247+ // Set first half of color constants before committing SRB
248+ pColVar->SetInlineConstants (g_Colors, 0 , kNumColConstants / 2 );
249+ }
250+
251+ pContext->CommitShaderResources (pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
252+
253+ if (pColVar != nullptr )
254+ {
255+ // Set second half of color constants after committing SRB
256+ pColVar->SetInlineConstants (g_Colors[0 ].Data () + kNumColConstants / 2 , kNumColConstants / 2 , kNumColConstants / 2 );
257+ }
258+
259+ pContext->SetPipelineState (pPSO);
260+
261+ if (pPosVar == nullptr )
262+ {
263+ // Draw both triangles as positions are static
264+ pContext->Draw ({6 , DRAW_FLAG_VERIFY_ALL});
265+ }
266+ else
267+ {
268+ // Draw first triangle
269+ pPosVar->SetInlineConstants (g_Positions, 0 , kNumPosConstants / 2 );
270+ pContext->Draw ({3 , DRAW_FLAG_VERIFY_ALL});
271+
272+ // Draw second triangle
273+ pPosVar->SetInlineConstants (g_Positions[0 ].Data () + kNumPosConstants / 2 , 0 , kNumPosConstants / 2 );
274+ pContext->Draw ({3 , DRAW_FLAG_VERIFY_ALL});
275+ }
276+
277+ Present ();
278+
279+ std::cout << TestingEnvironment::GetCurrentTestStatusString () << ' '
280+ << " Pos " << GetShaderVariableTypeLiteralName (PosType) << ' ,'
281+ << " Col " << GetShaderVariableTypeLiteralName (ColType) << std::endl;
282+ }
283+ }
284+ }
285+
286+
168287void InlineConstants::TestSignatures (Uint32 NumSignatures)
169288{
170289 GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance ();
0 commit comments