diff --git a/src/dawn/native/ShaderModule.cpp b/src/dawn/native/ShaderModule.cpp index 285e4db3c3..779e6ae499 100644 --- a/src/dawn/native/ShaderModule.cpp +++ b/src/dawn/native/ShaderModule.cpp @@ -703,11 +703,6 @@ namespace dawn::native { if (metadata->stage == SingleShaderStage::Vertex) { for (const auto& inputVar : entryPoint.input_variables) { - DAWN_INVALID_IF( - !inputVar.has_location_decoration, - "Vertex input variable \"%s\" doesn't have a location decoration.", - inputVar.name); - uint32_t unsanitizedLocation = inputVar.location_decoration; if (DelayedInvalidIf(unsanitizedLocation >= kMaxVertexAttributes, "Vertex input variable \"%s\" has a location (%u) that " @@ -742,11 +737,6 @@ namespace dawn::native { outputVar.interpolation_sampling)); totalInterStageShaderComponents += variable.componentCount; - DAWN_INVALID_IF( - !outputVar.has_location_decoration, - "Vertex ouput variable \"%s\" doesn't have a location decoration.", - outputVar.name); - uint32_t location = outputVar.location_decoration; if (DelayedInvalidIf(location > kMaxInterStageShaderLocation, "Vertex output variable \"%s\" has a location (%u) that " @@ -782,11 +772,6 @@ namespace dawn::native { inputVar.interpolation_sampling)); totalInterStageShaderComponents += variable.componentCount; - DAWN_INVALID_IF( - !inputVar.has_location_decoration, - "Fragment input variable \"%s\" doesn't have a location decoration.", - inputVar.name); - uint32_t location = inputVar.location_decoration; if (DelayedInvalidIf(location > kMaxInterStageShaderLocation, "Fragment input variable \"%s\" has a location (%u) that " @@ -826,11 +811,6 @@ namespace dawn::native { TintCompositionTypeToInterStageComponentCount(outputVar.composition_type)); ASSERT(variable.componentCount <= 4); - DAWN_INVALID_IF( - !outputVar.has_location_decoration, - "Fragment input variable \"%s\" doesn't have a location decoration.", - outputVar.name); - uint32_t unsanitizedAttachment = outputVar.location_decoration; if (DelayedInvalidIf(unsanitizedAttachment >= kMaxColorAttachments, "Fragment output variable \"%s\" has a location (%u) that " diff --git a/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp b/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp index ba702fb18a..7f6f7927a6 100644 --- a/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp @@ -575,3 +575,87 @@ TEST_F(ShaderModuleValidationTest, MaxBindingNumber) { )"); ASSERT_DEVICE_ERROR(device.CreateComputePipeline(&desc)); } + +// Test that missing decorations on shader IO or bindings causes a validation error. +TEST_F(ShaderModuleValidationTest, MissingDecorations) { + // Vertex input. + utils::CreateShaderModule(device, R"( + @stage(vertex) fn main(@location(0) a : vec4) -> @builtin(position) vec4 { + return vec4(1.0); + } + )"); + ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( + @stage(vertex) fn main(a : vec4) -> @builtin(position) vec4 { + return vec4(1.0); + } + )")); + + // Vertex output + utils::CreateShaderModule(device, R"( + struct Output { + @builtin(position) pos : vec4, + @location(0) a : f32, + } + @stage(vertex) fn main() -> Output { + var output : Output; + return output; + } + )"); + ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( + struct Output { + @builtin(position) pos : vec4, + a : f32, + } + @stage(vertex) fn main() -> Output { + var output : Output; + return output; + } + )")); + + // Fragment input + utils::CreateShaderModule(device, R"( + @stage(fragment) fn main(@location(0) a : vec4) -> @location(0) f32 { + return 1.0; + } + )"); + ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( + @stage(fragment) fn main(a : vec4) -> @location(0) f32 { + return 1.0; + } + )")); + + // Fragment input + utils::CreateShaderModule(device, R"( + @stage(fragment) fn main() -> @location(0) f32 { + return 1.0; + } + )"); + ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( + @stage(fragment) fn main() -> f32 { + return 1.0; + } + )")); + + // Binding decorations + utils::CreateShaderModule(device, R"( + @group(0) @binding(0) var s : sampler; + @stage(fragment) fn main() -> @location(0) f32 { + _ = s; + return 1.0; + } + )"); + ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( + @binding(0) var s : sampler; + @stage(fragment) fn main() -> @location(0) f32 { + _ = s; + return 1.0; + } + )")); + ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( + @group(0) var s : sampler; + @stage(fragment) fn main() -> @location(0) f32 { + _ = s; + return 1.0; + } + )")); +}