Validate if depth attachment is present when frag_depth is written

Bug: dawn:1636
Change-Id: I47aa4e5734b8e70e8c5a9171872a44a577d168d7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116859
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shrek Shao <shrekshao@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
shrekshao 2023-01-17 20:53:55 +00:00 committed by Dawn LUCI CQ
parent cdec06a2aa
commit e597e04e13
2 changed files with 64 additions and 0 deletions

View File

@ -335,6 +335,7 @@ MaybeError ValidateColorTargetState(
MaybeError ValidateFragmentState(DeviceBase* device, MaybeError ValidateFragmentState(DeviceBase* device,
const FragmentState* descriptor, const FragmentState* descriptor,
const PipelineLayoutBase* layout, const PipelineLayoutBase* layout,
const DepthStencilState* depthStencil,
bool alphaToCoverageEnabled) { bool alphaToCoverageEnabled) {
DAWN_INVALID_IF(descriptor->nextInChain != nullptr, "nextInChain must be nullptr."); DAWN_INVALID_IF(descriptor->nextInChain != nullptr, "nextInChain must be nullptr.");
@ -351,6 +352,22 @@ MaybeError ValidateFragmentState(DeviceBase* device,
const EntryPointMetadata& fragmentMetadata = const EntryPointMetadata& fragmentMetadata =
descriptor->module->GetEntryPoint(descriptor->entryPoint); descriptor->module->GetEntryPoint(descriptor->entryPoint);
if (fragmentMetadata.usesFragDepth) {
DAWN_INVALID_IF(
depthStencil == nullptr,
"Depth stencil state is not present when fragment stage (%s, entryPoint: %s) is "
"writing to frag_depth.",
descriptor->module, descriptor->entryPoint);
const Format* depthStencilFormat;
DAWN_TRY_ASSIGN(depthStencilFormat, device->GetInternalFormat(depthStencil->format));
DAWN_INVALID_IF(!depthStencilFormat->HasDepth(),
"Depth stencil state format (%s) has no depth aspect when fragment stage "
"(%s, entryPoint: %s) is "
"writing to frag_depth.",
depthStencil->format, descriptor->module, descriptor->entryPoint);
}
ColorAttachmentFormats colorAttachmentFormats; ColorAttachmentFormats colorAttachmentFormats;
for (ColorAttachmentIndex i(uint8_t(0)); for (ColorAttachmentIndex i(uint8_t(0));
i < ColorAttachmentIndex(static_cast<uint8_t>(descriptor->targetCount)); ++i) { i < ColorAttachmentIndex(static_cast<uint8_t>(descriptor->targetCount)); ++i) {
@ -477,6 +494,7 @@ MaybeError ValidateRenderPipelineDescriptor(DeviceBase* device,
if (descriptor->fragment != nullptr) { if (descriptor->fragment != nullptr) {
DAWN_TRY_CONTEXT(ValidateFragmentState(device, descriptor->fragment, descriptor->layout, DAWN_TRY_CONTEXT(ValidateFragmentState(device, descriptor->fragment, descriptor->layout,
descriptor->depthStencil,
descriptor->multisample.alphaToCoverageEnabled), descriptor->multisample.alphaToCoverageEnabled),
"validating fragment state."); "validating fragment state.");

View File

@ -193,6 +193,52 @@ TEST_F(RenderPipelineValidationTest, DepthStencilAspectRequirement) {
// enabled when Stencil8 format is implemented // enabled when Stencil8 format is implemented
} }
// Tests that depth attachment is required when frag_depth is written in fragment stage.
TEST_F(RenderPipelineValidationTest, DepthAttachmentRequiredWhenFragDepthIsWritten) {
wgpu::ShaderModule fsModuleFragDepthOutput = utils::CreateShaderModule(device, R"(
struct Output {
@builtin(frag_depth) depth_out: f32,
@location(0) color : vec4<f32>,
}
@fragment fn main() -> Output {
var o: Output;
// We need to make sure this frag_depth isn't optimized out even its value equals "no op".
o.depth_out = 0.5;
o.color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
return o;
}
)");
{
// Succeeds because there is depth stencil state.
utils::ComboRenderPipelineDescriptor descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModuleFragDepthOutput;
descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
device.CreateRenderPipeline(&descriptor);
}
{
// Fails because there is no depth stencil state.
utils::ComboRenderPipelineDescriptor descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModuleFragDepthOutput;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
{
// Fails because there is depth stencil state but no depth aspect.
utils::ComboRenderPipelineDescriptor descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModuleFragDepthOutput;
descriptor.EnableDepthStencil(wgpu::TextureFormat::Stencil8);
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
}
// Tests that at least one color target state is required. // Tests that at least one color target state is required.
TEST_F(RenderPipelineValidationTest, ColorTargetStateRequired) { TEST_F(RenderPipelineValidationTest, ColorTargetStateRequired) {
{ {