Skip to content

Commit f9d2ac8

Browse files
Inline Constants test: use constants in PS (#672)
1 parent aeeac03 commit f9d2ac8

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

Tests/DiligentCoreAPITest/src/InlineConstantsTest.cpp

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ void RenderDrawCommandReference(ISwapChain* pSwapChain, const float* pClearColor
4545
using namespace Diligent;
4646
using namespace Diligent::Testing;
4747

48-
#include "InlineShaders/DrawCommandTestHLSL.h"
49-
50-
5148
namespace
5249
{
5350

@@ -80,8 +77,31 @@ void main(uint VertexId : SV_VertexId,
8077
}
8178
)"};
8279

80+
const std::string InlineConstantsTest_PS{
81+
R"(
82+
struct PSInput
83+
{
84+
float4 Pos : SV_POSITION;
85+
float3 Color : COLOR;
86+
};
87+
88+
cbuffer cbInlineColors
89+
{
90+
float4 g_Colors[3];
8391
}
8492
93+
float4 main(in PSInput PSIn) : SV_Target
94+
{
95+
float3 Color = PSIn.Color.rgb;
96+
Color.r *= g_Colors[0].a;
97+
Color.g *= g_Colors[1].a;
98+
Color.b *= g_Colors[2].a;
99+
return float4(Color, 1.0);
100+
}
101+
)"};
102+
103+
} // namespace HLSL
104+
85105
float4 g_Positions[] = {
86106
float4{-1.0f, -0.5f, 0.f, 1.f},
87107
float4{-0.5f, +0.5f, 0.f, 1.f},
@@ -109,6 +129,11 @@ class InlineConstants : public ::testing::Test
109129
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
110130
IRenderDevice* pDevice = pEnv->GetDevice();
111131

132+
if (pDevice->GetDeviceInfo().Type != RENDER_DEVICE_TYPE_D3D12)
133+
{
134+
GTEST_SKIP();
135+
}
136+
112137
ShaderCreateInfo ShaderCI;
113138
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
114139
ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
@@ -124,7 +149,7 @@ class InlineConstants : public ::testing::Test
124149
{
125150
ShaderCI.Desc = {"Inline constants test", SHADER_TYPE_PIXEL, true};
126151
ShaderCI.EntryPoint = "main";
127-
ShaderCI.Source = HLSL::DrawTest_PS.c_str();
152+
ShaderCI.Source = HLSL::InlineConstantsTest_PS.c_str();
128153
pDevice->CreateShader(ShaderCI, &sm_Res.pPS);
129154
ASSERT_NE(sm_Res.pPS, nullptr);
130155
}
@@ -175,10 +200,6 @@ TEST_F(InlineConstants, ResourceLayout)
175200
IRenderDevice* pDevice = pEnv->GetDevice();
176201
IDeviceContext* pContext = pEnv->GetDeviceContext();
177202
ISwapChain* pSwapChain = pEnv->GetSwapChain();
178-
if (pDevice->GetDeviceInfo().Type != RENDER_DEVICE_TYPE_D3D12)
179-
{
180-
GTEST_SKIP();
181-
}
182203

183204
for (Uint32 pos_type = 0; pos_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++pos_type)
184205
{
@@ -195,7 +216,7 @@ TEST_F(InlineConstants, ResourceLayout)
195216
PipelineResourceLayoutDescX ResLayoutDesc;
196217
ResLayoutDesc
197218
.AddVariable(SHADER_TYPE_VERTEX, "cbInlinePositions", PosType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS)
198-
.AddVariable(SHADER_TYPE_VERTEX, "cbInlineColors", ColType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS);
219+
.AddVariable(SHADER_TYPE_VS_PS, "cbInlineColors", ColType, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS);
199220

200221
PsoCI
201222
.AddRenderTarget(pSwapChain->GetDesc().ColorBufferFormat)
@@ -294,10 +315,6 @@ void InlineConstants::TestSignatures(Uint32 NumSignatures)
294315
IRenderDevice* pDevice = pEnv->GetDevice();
295316
IDeviceContext* pContext = pEnv->GetDeviceContext();
296317
ISwapChain* pSwapChain = pEnv->GetSwapChain();
297-
if (pDevice->GetDeviceInfo().Type != RENDER_DEVICE_TYPE_D3D12)
298-
{
299-
GTEST_SKIP();
300-
}
301318

302319
RefCntAutoPtr<IBuffer> pConstBuffer = pEnv->CreateBuffer({"InlineConstants - dummy const buffer", 256, BIND_UNIFORM_BUFFER});
303320
ASSERT_TRUE(pConstBuffer);
@@ -347,7 +364,7 @@ void InlineConstants::TestSignatures(Uint32 NumSignatures)
347364
.AddResource(SHADER_TYPE_VERTEX, "tex1_mut", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
348365
.AddResource(SHADER_TYPE_VERTEX, "tex1_dyn", SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
349366

350-
.AddResource(SHADER_TYPE_VERTEX, "cbInlineColors", kNumColConstants, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, ColType, PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
367+
.AddResource(SHADER_TYPE_VS_PS, "cbInlineColors", kNumColConstants, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, ColType, PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
351368

352369
.AddResource(SHADER_TYPE_VERTEX, "cb2_stat", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
353370
.AddResource(SHADER_TYPE_VERTEX, "cb2_mut", 1u, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE)
@@ -567,7 +584,7 @@ void CreateShadersFromCache(IRenderStateCache* pCache, bool PresentInCache, ISha
567584
{
568585
ShaderCI.Desc = {"Inline constants test", SHADER_TYPE_PIXEL, true};
569586
ShaderCI.EntryPoint = "main";
570-
ShaderCI.Source = HLSL::DrawTest_PS.c_str();
587+
ShaderCI.Source = HLSL::InlineConstantsTest_PS.c_str();
571588
if (pCache != nullptr)
572589
{
573590
EXPECT_EQ(pCache->CreateShader(ShaderCI, ppPS), PresentInCache);
@@ -599,7 +616,7 @@ void CreatePSOFromCache(IRenderStateCache* pCache, bool PresentInCache, IShader*
599616
static ShaderResourceVariableDesc Vars[] =
600617
{
601618
{SHADER_TYPE_VERTEX, "cbInlinePositions", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS},
602-
{SHADER_TYPE_VERTEX, "cbInlineColors", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS},
619+
{SHADER_TYPE_VS_PS, "cbInlineColors", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_FLAG_INLINE_CONSTANTS},
603620
};
604621
PsoCI.PSODesc.ResourceLayout.Variables = Vars;
605622
PsoCI.PSODesc.ResourceLayout.NumVariables = _countof(Vars);
@@ -667,11 +684,6 @@ TEST_F(InlineConstants, RenderStateCache)
667684
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
668685
IRenderDevice* pDevice = pEnv->GetDevice();
669686

670-
if (pDevice->GetDeviceInfo().Type != RENDER_DEVICE_TYPE_D3D12)
671-
{
672-
GTEST_SKIP();
673-
}
674-
675687
GPUTestingEnvironment::ScopedReset AutoReset;
676688

677689
RefCntAutoPtr<IShaderSourceInputStreamFactory> pShaderSourceFactory;

0 commit comments

Comments
 (0)