From 58ce2745cd7077c8f38839f4c2f5beeebf631648 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 22 Dec 2020 18:10:58 +0000 Subject: [PATCH] dawn_native/vulkan: Use EmitVertexPointSize transform Fixes validation errors when drawing with point topologies, and without explicitly writing to the PointSize builtin. Fixed: tint:321 Change-Id: I3c00c5ee56966a82d9e3024cb277eae8921a9af2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/35800 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Austin Eng --- src/dawn_native/ShaderModule.cpp | 17 +++++++++++++++++ src/dawn_native/metal/ShaderModuleMTL.mm | 2 +- src/dawn_native/opengl/ShaderModuleGL.cpp | 1 + src/dawn_native/vulkan/ShaderModuleVk.cpp | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index df68e3c643..909ecbb737 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -837,12 +837,28 @@ namespace dawn_native { } else { tint::ast::Module module; DAWN_TRY_ASSIGN(module, ParseWGSL(wgslDesc->source)); + + { + tint::transform::Manager transformManager; + transformManager.append( + std::make_unique()); + DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, &module)); + } + if (device->IsValidationEnabled()) { DAWN_TRY(ValidateModule(&module)); } + + // Keep the Tint module around. The Metal backend will use it for vertex + // pulling since we can't go WGSL->point size transform->spirv->Tint. + // Tint's spirv reader doesn't understand point size. crbug.com/tint/412. + auto tintModule = std::make_unique(module.Clone()); + std::vector spirv; DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(std::move(module))); DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size())); + + parseResult.tintModule = std::move(tintModule); parseResult.spirv = std::move(spirv); } break; @@ -1026,6 +1042,7 @@ namespace dawn_native { tint::transform::Manager transformManager; transformManager.append( MakeVertexPullingTransform(vertexState, entryPoint, pullingBufferBindingSet)); + transformManager.append(std::make_unique()); if (GetDevice()->IsRobustnessEnabled()) { // TODO(enga): Run the Tint BoundArrayAccessors transform instead of the SPIRV Tools // one, but it appears to crash after running VertexPulling. diff --git a/src/dawn_native/metal/ShaderModuleMTL.mm b/src/dawn_native/metal/ShaderModuleMTL.mm index 74787fce49..b0958ecad4 100644 --- a/src/dawn_native/metal/ShaderModuleMTL.mm +++ b/src/dawn_native/metal/ShaderModuleMTL.mm @@ -123,7 +123,7 @@ namespace dawn_native { namespace metal { std::vector pullingSpirv; if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) && stage == SingleShaderStage::Vertex) { - if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { + if (mTintModule) { DAWN_TRY_ASSIGN(pullingSpirv, GeneratePullingSpirv(mTintModule.get(), *renderPipeline->GetVertexStateDescriptor(), diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp index b3bcfb22ab..ab8ae71fc0 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.cpp +++ b/src/dawn_native/opengl/ShaderModuleGL.cpp @@ -89,6 +89,7 @@ namespace dawn_native { namespace opengl { tint::transform::Manager transformManager; transformManager.append(std::make_unique()); + transformManager.append(std::make_unique()); DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, &module)); diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 28aa11568f..b0edeb64b0 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -60,6 +60,7 @@ namespace dawn_native { namespace vulkan { tint::transform::Manager transformManager; transformManager.append(std::make_unique()); + transformManager.append(std::make_unique()); DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, &module));