Extend Overlay tests to include shader exported depth scenario

This commit is contained in:
Jake Turner
2023-12-05 15:26:57 +00:00
parent 00c352748c
commit dd0c888d11
5 changed files with 168 additions and 8 deletions
+37 -1
View File
@@ -36,6 +36,39 @@ float4 main() : SV_Target0
return float4(1, 1, 1, 1);
}
)EOSHADER";
std::string depthWritePixel = R"EOSHADER(
struct v2f
{
float4 pos : SV_POSITION;
float4 col : COLOR0;
float2 uv : TEXCOORD0;
};
struct PixOut
{
float4 colour : SV_Target0;
float depth : SV_Depth;
};
PixOut main(v2f IN)
{
PixOut OUT;
OUT.colour = IN.col;
if ((IN.pos.x > 180.0) && (IN.pos.x < 185.0) &&
(IN.pos.y > 155.0) && (IN.pos.y < 165.0))
{
OUT.depth = 0.0;
}
else
{
OUT.depth = IN.pos.z;
}
return OUT;
}
)EOSHADER";
int main()
@@ -52,6 +85,7 @@ float4 main() : SV_Target0
ID3D11VertexShaderPtr vs = CreateVS(vsblob);
ID3D11PixelShaderPtr ps = CreatePS(psblob);
ID3D11PixelShaderPtr whiteps = CreatePS(Compile(whitePixel, "main", "ps_4_0"));
ID3D11PixelShaderPtr depthwriteps = CreatePS(Compile(depthWritePixel, "main", "ps_4_0"));
const DefaultA2V VBData[] = {
// this triangle occludes in depth
@@ -171,7 +205,6 @@ float4 main() : SV_Target0
ctx->IASetInputLayout(defaultLayout);
ctx->VSSetShader(vs, NULL, 0);
ctx->PSSetShader(ps, NULL, 0);
for(size_t f = 0; f < countFmts; f++)
{
@@ -182,6 +215,7 @@ float4 main() : SV_Target0
hasStencil = true;
for(ID3D11RenderTargetViewPtr rtv : {bbRTV, msaartv})
{
ctx->PSSetShader(ps, NULL, 0);
D3D11_DEPTH_STENCIL_DESC depth = GetDepthState();
depth.StencilEnable = FALSE;
@@ -237,7 +271,9 @@ float4 main() : SV_Target0
depth.StencilEnable = TRUE;
depth.FrontFace.StencilFunc = D3D11_COMPARISON_GREATER;
SetDepthState(depth);
ctx->PSSetShader(depthwriteps, NULL, 0);
ctx->Draw(24, 9);
ctx->PSSetShader(ps, NULL, 0);
depth.StencilEnable = FALSE;
depth.DepthFunc = D3D11_COMPARISON_ALWAYS;
+45 -1
View File
@@ -81,6 +81,39 @@ float4 main() : SV_Target0
return float4(1, 1, 1, 1);
}
)EOSHADER";
std::string depthWritePixel = R"EOSHADER(
struct v2f
{
float4 col : COLOR0;
float2 uv : TEXCOORD0;
float4 pos : SV_POSITION;
};
struct PixOut
{
float4 colour : SV_Target0;
float depth : SV_Depth;
};
PixOut main(v2f IN)
{
PixOut OUT;
OUT.colour = IN.col;
if ((IN.pos.x > 180.0) && (IN.pos.x < 185.0) &&
(IN.pos.y > 155.0) && (IN.pos.y < 165.0))
{
OUT.depth = 0.0;
}
else
{
OUT.depth = IN.pos.z;
}
return OUT;
}
)EOSHADER";
int main()
@@ -92,6 +125,7 @@ float4 main() : SV_Target0
ID3DBlobPtr vsblob[3] = {};
ID3DBlobPtr psblob[3] = {};
ID3DBlobPtr whitepsblob[3] = {};
ID3DBlobPtr depthwritepsblob[3] = {};
{
int i = 0;
@@ -103,6 +137,7 @@ float4 main() : SV_Target0
vsblob[i] = Compile(vertexEndPosVert, "main", "vs" + profile);
psblob[i] = Compile(vertexEndPosPixel, "main", "ps" + profile);
whitepsblob[i] = Compile(whitePixel, "main", "ps" + profile);
depthwritepsblob[i] = Compile(depthWritePixel, "main", "ps" + profile);
i++;
}
}
@@ -192,6 +227,7 @@ float4 main() : SV_Target0
ID3D12PipelineStatePtr stencilWritePipe[3][countFmts][2];
ID3D12PipelineStatePtr backgroundPipe[3][countFmts][2];
ID3D12PipelineStatePtr pipe[3][countFmts][2];
ID3D12PipelineStatePtr depthWritePixelShaderPipe[3][countFmts][2];
ID3D12PipelineStatePtr whitepipe[3];
ID3D12PipelineStatePtr sampleMaskPipe[3][countFmts];
@@ -265,6 +301,13 @@ float4 main() : SV_Target0
creator.GraphicsDesc.SampleDesc = yesMSAA;
pipe[i][f][1] = creator;
creator.PS(depthwritepsblob[i]);
creator.GraphicsDesc.SampleDesc = noMSAA;
depthWritePixelShaderPipe[i][f][0] = creator;
creator.GraphicsDesc.SampleDesc = yesMSAA;
depthWritePixelShaderPipe[i][f][1] = creator;
creator.PS(psblob[i]);
creator.GraphicsDesc.SampleDesc = yesMSAA;
sampleMaskPipe[i][f] = creator;
}
@@ -393,8 +436,9 @@ float4 main() : SV_Target0
markerName += fmtName;
setMarker(cmd, markerName);
cmd->SetPipelineState(pipe[pass][f][is_msaa ? 1 : 0]);
cmd->SetPipelineState(depthWritePixelShaderPipe[pass][f][is_msaa ? 1 : 0]);
cmd->DrawInstanced(24, 1, 9, 0);
cmd->SetPipelineState(pipe[pass][f][is_msaa ? 1 : 0]);
if(!is_msaa)
{
+26
View File
@@ -83,6 +83,29 @@ void main()
Color = vec4(1,1,1,1);
}
)EOSHADER";
std::string fragdepthpixel = R"EOSHADER(
in v2f vertIn;
layout(location = 0, index = 0) out vec4 Color;
void main()
{
Color = vertIn.col;
if ((gl_FragCoord.x > 180.0) && (gl_FragCoord.x < 185.0) &&
(gl_FragCoord.y > 135.0) && (gl_FragCoord.y < 145.0))
{
gl_FragDepth = 0.0;
}
else
{
gl_FragDepth = gl_FragCoord.z;
}
}
)EOSHADER";
int main()
@@ -176,6 +199,7 @@ void main()
GLuint program = MakeProgram(common + vertex, common + pixel);
GLuint whiteprogram = MakeProgram(common + vertex, whitepixel);
GLuint fragdepthprogram = MakeProgram(common + vertex, common + fragdepthpixel);
const char *fmtNames[] = {"D24_S8", "D32F_S8", "D16_S0", "D24_S0", "D32F_S0"};
GLenum fmts[] = {GL_DEPTH24_STENCIL8, GL_DEPTH32F_STENCIL8, GL_DEPTH_COMPONENT16,
@@ -320,7 +344,9 @@ void main()
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_GREATER, 0x55, 0xff);
glUseProgram(fragdepthprogram);
glDrawArrays(GL_TRIANGLES, 9, 24);
glUseProgram(program);
if(!is_msaa)
{
+56 -5
View File
@@ -110,6 +110,40 @@ void main()
Color = vec4(1,1,1,1);
}
)EOSHADER";
std::string depthWritePixel = R"EOSHADER(
layout(location = 0) in v2f vertIn;
layout(location = 0, index = 0) out vec4 Color;
layout(constant_id = 2) const int spec_canary = 0;
layout(binding = 0) uniform texture2D tex[64];
void main()
{
if(vertIn.uv.z > 100.0f)
{
Color += texelFetch(tex[uint(vertIn.uv.z) % 50], ivec2(vertIn.uv.xy * vec2(4,4)), 0) * 0.001f;
}
Color = vertIn.col;
if ((gl_FragCoord.x > 180.0) && (gl_FragCoord.x < 185.0) &&
(gl_FragCoord.y > 155.0) && (gl_FragCoord.y < 165.0))
{
gl_FragDepth = 0.0;
}
else
{
gl_FragDepth = gl_FragCoord.z;
}
if(spec_canary != 1338) { Color = vec4(1.0, 0.0, 0.0, 1.0); return; }
}
)EOSHADER";
int main()
@@ -360,10 +394,9 @@ void main()
vkh::vertexAttr(2, 0, DefaultA2V, uv),
};
pipeCreateInfo.stages = {
CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"),
CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"),
};
pipeCreateInfo.stages.resize(2);
pipeCreateInfo.stages[0] =
CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main");
VkSpecializationMapEntry specmap[2] = {
{1, 0 * sizeof(uint32_t), sizeof(uint32_t)},
@@ -381,11 +414,18 @@ void main()
std::vector<VkPipeline> depthWritePipes;
std::vector<VkPipeline> stencilWritePipes;
std::vector<VkPipeline> backgroundPipes;
std::vector<VkPipeline> depthWritePixelShaderPipes;
std::vector<VkPipeline> sampleMaskPipes;
std::vector<VkPipeline> drawPipes;
VkPipelineShaderStageCreateInfo normalFragShader =
CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main");
VkPipelineShaderStageCreateInfo depthWriteFragShader =
CompileShaderModule(common + depthWritePixel, ShaderLang::glsl, ShaderStage::frag, "main");
for(size_t f = 0; f < supportedFmts.size(); ++f)
{
pipeCreateInfo.stages[1] = normalFragShader;
pipeCreateInfo.stages[0].pSpecializationInfo = &spec;
pipeCreateInfo.stages[1].pSpecializationInfo = &spec;
@@ -440,6 +480,15 @@ void main()
pipeCreateInfo.multisampleState.pSampleMask = &sampleMask;
sampleMaskPipes.push_back(createGraphicsPipeline(pipeCreateInfo));
pipeCreateInfo.multisampleState.pSampleMask = NULL;
pipeCreateInfo.stages[1] = depthWriteFragShader;
pipeCreateInfo.stages[1].pSpecializationInfo = &spec;
pipeCreateInfo.multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
pipeCreateInfo.renderPass = renderPasses[f];
depthWritePixelShaderPipes.push_back(createGraphicsPipeline(pipeCreateInfo));
pipeCreateInfo.multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
pipeCreateInfo.renderPass = msaaRPs[f];
depthWritePixelShaderPipes.push_back(createGraphicsPipeline(pipeCreateInfo));
}
pipeCreateInfo.stages[1] =
@@ -594,8 +643,10 @@ void main()
markerName += supportedFmtNames[f];
setMarker(cmd, markerName);
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, drawPipes[pipeIndex]);
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
depthWritePixelShaderPipes[pipeIndex]);
vkCmdDraw(cmd, 24, 1, 9, 0);
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, drawPipes[pipeIndex]);
if(!is_msaa)
{
+4 -1
View File
@@ -195,6 +195,9 @@ class Overlay_Test(rdtest.TestCase):
self.check_pixel_value(overlay_id, 200, 65, [0.0, 1.0, 0.0, 1.0], eps=eps)
self.check_pixel_value(overlay_id, 200, 79, [0.0, 1.0, 0.0, 1.0], eps=eps)
self.check_pixel_value(overlay_id, 200, 93, [0.0, 1.0, 0.0, 1.0], eps=eps)
# Shader modified depth (pass)
self.check_pixel_value(overlay_id, 180, 160, [0.0, 1.0, 0.0, 1.0], eps=eps)
elif overlay == rd.DebugOverlay.Stencil:
self.check_pixel_value(overlay_id, 150, 90, [0.0, 1.0, 0.0, 1.0], eps=eps)
# Intersection with different stencil - stencil fail
@@ -587,7 +590,7 @@ class Overlay_Test(rdtest.TestCase):
eps = 0.001
if has_stencil:
self.check_pixel_value(depth_tex, 180, 160, [0.0, 0.0/255.0, 0.0, 1.0], eps=eps)
self.check_pixel_value(depth_tex, 170, 160, [0.0, 0.0/255.0, 0.0, 1.0], eps=eps)
self.check_pixel_value(depth_tex, 160, 135, [0.9, 85.0/255.0, 0.0, 1.0], eps=eps)
self.check_pixel_value(depth_tex, 160, 165, [0.0, 0.0/255.0, 0.0, 1.0], eps=eps)
self.check_pixel_value(depth_tex, 250, 150, [0.5, 85.0/255.0, 0.0, 1.0], eps=eps)