diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 609ede0dc1..c7edb9f529 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -134,14 +134,14 @@ namespace dawn_native { mFormatTable = BuildFormatTable(this); SetDefaultToggles(); -#if defined(DAWN_PLATFORM_MACOS) - if (!IsToggleEnabled(Toggle::UseTintGenerator)) { + if ((adapter->GetBackendType() == wgpu::BackendType::Metal || + adapter->GetBackendType() == wgpu::BackendType::Vulkan) && + !IsToggleEnabled(Toggle::UseTintGenerator)) { EmitLog( WGPULoggingType_Warning, - "Non-tint generator is not available on this platform; toggle disable ignored.\n"); + "Non-tint generator is not available on this backend; toggle disable ignored.\n"); ForceSetToggle(Toggle::UseTintGenerator, true); } -#endif } DeviceBase::~DeviceBase() = default; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 359dfda4d1..ad9ed48ead 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -192,7 +192,7 @@ namespace dawn_native { namespace metal { // Vertex buffer robustness is implemented by using programmable vertex pulling. Enable // that code path if it isn't explicitly disabled. - if (IsToggleEnabled(Toggle::UseTintGenerator) && IsRobustnessEnabled()) { + if (IsRobustnessEnabled()) { SetToggle(Toggle::MetalEnableVertexPulling, true); } diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp index 3b9bec6ad6..c56d95027d 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.cpp +++ b/src/dawn_native/opengl/ShaderModuleGL.cpp @@ -83,21 +83,17 @@ namespace dawn_native { namespace opengl { DAWN_TRY(InitializeBase(parseResult)); // Tint currently does not support emitting GLSL, so when provided a Tint program need to // generate SPIRV and SPIRV-Cross reflection data to be used in this backend. - if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { - tint::writer::spirv::Options options; - options.disable_workgroup_init = - GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); - auto result = tint::writer::spirv::Generate(GetTintProgram(), options); - if (!result.success) { - std::ostringstream errorStream; - errorStream << "Generator: " << result.error << std::endl; - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - - DAWN_TRY_ASSIGN(mGLEntryPoints, - ReflectShaderUsingSPIRVCross(GetDevice(), result.spirv)); + tint::writer::spirv::Options options; + options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); + auto result = tint::writer::spirv::Generate(GetTintProgram(), options); + if (!result.success) { + std::ostringstream errorStream; + errorStream << "Generator: " << result.error << std::endl; + return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); } + DAWN_TRY_ASSIGN(mGLEntryPoints, ReflectShaderUsingSPIRVCross(GetDevice(), result.spirv)); + return {}; } @@ -126,31 +122,27 @@ namespace dawn_native { namespace opengl { options.version = version.GetMajor() * 100 + version.GetMinor() * 10; std::vector spirv; - if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { - tint::transform::SingleEntryPoint singleEntryPointTransform; + tint::transform::SingleEntryPoint singleEntryPointTransform; - tint::transform::DataMap transformInputs; - transformInputs.Add(entryPointName); + tint::transform::DataMap transformInputs; + transformInputs.Add(entryPointName); - tint::Program program; - DAWN_TRY_ASSIGN(program, RunTransforms(&singleEntryPointTransform, GetTintProgram(), - transformInputs, nullptr, nullptr)); + tint::Program program; + DAWN_TRY_ASSIGN(program, RunTransforms(&singleEntryPointTransform, GetTintProgram(), + transformInputs, nullptr, nullptr)); - tint::writer::spirv::Options options; - options.disable_workgroup_init = - GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); - auto result = tint::writer::spirv::Generate(&program, options); - if (!result.success) { - std::ostringstream errorStream; - errorStream << "Generator: " << result.error << std::endl; - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - - spirv = std::move(result.spirv); - } else { - spirv = GetSpirv(); + tint::writer::spirv::Options tintOptions; + tintOptions.disable_workgroup_init = + GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); + auto result = tint::writer::spirv::Generate(&program, tintOptions); + if (!result.success) { + std::ostringstream errorStream; + errorStream << "Generator: " << result.error << std::endl; + return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); } + spirv = std::move(result.spirv); + if (GetDevice()->IsToggleEnabled(Toggle::DumpShaders)) { spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1); std::ostringstream dumpedMsg; @@ -204,9 +196,7 @@ namespace dawn_native { namespace opengl { } const EntryPointMetadata::BindingInfoArray& bindingInfo = - GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator) - ? (*mGLEntryPoints.at(entryPointName)).bindings - : GetEntryPoint(entryPointName).bindings; + (*mGLEntryPoints.at(entryPointName)).bindings; // Change binding names to be "dawn_binding__". // Also unsets the SPIRV "Binding" decoration as it outputs "layout(binding=)" which diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp index 1f8514d692..1e1b673c0d 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp @@ -91,16 +91,12 @@ namespace dawn_native { namespace vulkan { ityp::vector bindings; bindings.reserve(GetBindingCount()); - bool useBindingIndex = GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator); - for (const auto& it : GetBindingMap()) { - BindingNumber bindingNumber = it.first; BindingIndex bindingIndex = it.second; const BindingInfo& bindingInfo = GetBindingInfo(bindingIndex); VkDescriptorSetLayoutBinding vkBinding; - vkBinding.binding = useBindingIndex ? static_cast(bindingIndex) - : static_cast(bindingNumber); + vkBinding.binding = static_cast(bindingIndex); // TODO(dawn:728) In the future, special handling will be needed for external textures // here because they encompass multiple views. vkBinding.descriptorType = VulkanDescriptorType(bindingInfo); diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.h b/src/dawn_native/vulkan/BindGroupLayoutVk.h index cc502c94d9..72f8b698d7 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.h +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.h @@ -43,10 +43,6 @@ namespace dawn_native { namespace vulkan { // the pools are reused when no longer used. Minimizing the number of descriptor pool allocation // is important because creating them can incur GPU memory allocation which is usually an // expensive syscall. - // - // The Vulkan BindGroupLayout is dependent on UseTintGenerator or not. - // When UseTintGenerator is on, VkDescriptorSetLayoutBinding::binding is set to BindingIndex, - // otherwise it is set to BindingNumber. class BindGroupLayout final : public BindGroupLayoutBase { public: static ResultOrError> Create( diff --git a/src/dawn_native/vulkan/BindGroupVk.cpp b/src/dawn_native/vulkan/BindGroupVk.cpp index e06ad293a4..54db30d070 100644 --- a/src/dawn_native/vulkan/BindGroupVk.cpp +++ b/src/dawn_native/vulkan/BindGroupVk.cpp @@ -48,11 +48,8 @@ namespace dawn_native { namespace vulkan { ityp::stack_vec writeImageInfo(bindingCount); - bool useBindingIndex = device->IsToggleEnabled(Toggle::UseTintGenerator); - uint32_t numWrites = 0; for (const auto& it : GetLayout()->GetBindingMap()) { - BindingNumber bindingNumber = it.first; BindingIndex bindingIndex = it.second; const BindingInfo& bindingInfo = GetLayout()->GetBindingInfo(bindingIndex); @@ -60,8 +57,7 @@ namespace dawn_native { namespace vulkan { write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; write.pNext = nullptr; write.dstSet = GetHandle(); - write.dstBinding = useBindingIndex ? static_cast(bindingIndex) - : static_cast(bindingNumber); + write.dstBinding = static_cast(bindingIndex); write.dstArrayElement = 0; write.descriptorCount = 1; write.descriptorType = VulkanDescriptorType(bindingInfo); diff --git a/src/dawn_native/vulkan/BindGroupVk.h b/src/dawn_native/vulkan/BindGroupVk.h index 14b6940eb9..dac780bf0b 100644 --- a/src/dawn_native/vulkan/BindGroupVk.h +++ b/src/dawn_native/vulkan/BindGroupVk.h @@ -26,9 +26,6 @@ namespace dawn_native { namespace vulkan { class Device; - // The Vulkan BindGroup is dependent on UseTintGenerator or not. - // When UseTintGenerator is on, VkWriteDescriptorSet::dstBinding is set to BindingIndex, - // otherwise it is set to BindingNumber. class BindGroup final : public BindGroupBase, public PlacementAllocated { public: static ResultOrError> Create(Device* device, diff --git a/src/dawn_native/vulkan/ComputePipelineVk.cpp b/src/dawn_native/vulkan/ComputePipelineVk.cpp index 941e48f945..d6a471f6b3 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.cpp +++ b/src/dawn_native/vulkan/ComputePipelineVk.cpp @@ -46,15 +46,11 @@ namespace dawn_native { namespace vulkan { createInfo.stage.pNext = nullptr; createInfo.stage.flags = 0; createInfo.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; - if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { - // Generate a new VkShaderModule with BindingRemapper tint transform for each pipeline - DAWN_TRY_ASSIGN(createInfo.stage.module, - ToBackend(descriptor->compute.module) - ->GetTransformedModuleHandle(descriptor->compute.entryPoint, - ToBackend(GetLayout()))); - } else { - createInfo.stage.module = ToBackend(descriptor->compute.module)->GetHandle(); - } + // Generate a new VkShaderModule with BindingRemapper tint transform for each pipeline + DAWN_TRY_ASSIGN(createInfo.stage.module, + ToBackend(descriptor->compute.module) + ->GetTransformedModuleHandle(descriptor->compute.entryPoint, + ToBackend(GetLayout()))); createInfo.stage.pName = descriptor->compute.entryPoint; createInfo.stage.pSpecializationInfo = nullptr; diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp index 3eb2e126c5..79dbb40627 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp @@ -341,22 +341,16 @@ namespace dawn_native { namespace vulkan { VkPipelineShaderStageCreateInfo shaderStages[2]; { - if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { - // Generate a new VkShaderModule with BindingRemapper tint transform for each - // pipeline - DAWN_TRY_ASSIGN(shaderStages[0].module, - ToBackend(descriptor->vertex.module) - ->GetTransformedModuleHandle(descriptor->vertex.entryPoint, - ToBackend(GetLayout()))); - DAWN_TRY_ASSIGN(shaderStages[1].module, - ToBackend(descriptor->fragment->module) - ->GetTransformedModuleHandle(descriptor->fragment->entryPoint, - ToBackend(GetLayout()))); - } else { - shaderStages[0].module = ToBackend(descriptor->vertex.module)->GetHandle(); - shaderStages[1].module = ToBackend(descriptor->fragment->module)->GetHandle(); - } - + // Generate a new VkShaderModule with BindingRemapper tint transform for each + // pipeline + DAWN_TRY_ASSIGN(shaderStages[0].module, + ToBackend(descriptor->vertex.module) + ->GetTransformedModuleHandle(descriptor->vertex.entryPoint, + ToBackend(GetLayout()))); + DAWN_TRY_ASSIGN(shaderStages[1].module, + ToBackend(descriptor->fragment->module) + ->GetTransformedModuleHandle(descriptor->fragment->entryPoint, + ToBackend(GetLayout()))); shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStages[0].pNext = nullptr; shaderStages[0].flags = 0; diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 98df4411c8..5fb97b531f 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -21,12 +21,6 @@ #include "dawn_native/vulkan/PipelineLayoutVk.h" #include "dawn_native/vulkan/VulkanError.h" -#include - -// Tint include must be after spirv_hlsl.hpp, because spirv-cross has its own -// version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross -// is at 3 while spirv-headers is at 4. -#undef SPV_REVISION #include namespace dawn_native { namespace vulkan { @@ -89,45 +83,37 @@ namespace dawn_native { namespace vulkan { ScopedTintICEHandler scopedICEHandler(GetDevice()); - if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { - std::ostringstream errorStream; - errorStream << "Tint SPIR-V writer failure:" << std::endl; + std::ostringstream errorStream; + errorStream << "Tint SPIR-V writer failure:" << std::endl; - tint::transform::Manager transformManager; - if (GetDevice()->IsRobustnessEnabled()) { - transformManager.Add(); - } - - tint::transform::DataMap transformInputs; - - tint::Program program; - DAWN_TRY_ASSIGN(program, - RunTransforms(&transformManager, parseResult->tintProgram.get(), - transformInputs, nullptr, nullptr)); - - tint::writer::spirv::Options options; - options.emit_vertex_point_size = true; - options.disable_workgroup_init = - GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); - auto result = tint::writer::spirv::Generate(&program, options); - if (!result.success) { - errorStream << "Generator: " << result.error << std::endl; - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - - spirv = std::move(result.spirv); - spirvPtr = &spirv; - - // Rather than use a new ParseResult object, we just reuse the original parseResult - parseResult->tintProgram = std::make_unique(std::move(program)); - parseResult->spirv = spirv; - - DAWN_TRY(InitializeBase(parseResult)); - } else { - DAWN_TRY(InitializeBase(parseResult)); - spirvPtr = &GetSpirv(); + tint::transform::Manager transformManager; + if (GetDevice()->IsRobustnessEnabled()) { + transformManager.Add(); } + tint::transform::DataMap transformInputs; + + tint::Program program; + DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, parseResult->tintProgram.get(), + transformInputs, nullptr, nullptr)); + + tint::writer::spirv::Options options; + options.emit_vertex_point_size = true; + options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); + auto result = tint::writer::spirv::Generate(&program, options); + if (!result.success) { + errorStream << "Generator: " << result.error << std::endl; + return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); + } + + spirv = std::move(result.spirv); + spirvPtr = &spirv; + + // Rather than use a new ParseResult object, we just reuse the original parseResult + parseResult->tintProgram = std::make_unique(std::move(program)); + + DAWN_TRY(InitializeBase(parseResult)); + VkShaderModuleCreateInfo createInfo; createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; createInfo.pNext = nullptr; @@ -151,18 +137,11 @@ namespace dawn_native { namespace vulkan { } } - VkShaderModule ShaderModule::GetHandle() const { - ASSERT(!GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)); - return mHandle; - } - ResultOrError ShaderModule::GetTransformedModuleHandle( const char* entryPointName, PipelineLayout* layout) { ScopedTintICEHandler scopedICEHandler(GetDevice()); - ASSERT(GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)); - auto cacheKey = std::make_pair(layout, entryPointName); VkShaderModule cachedShaderModule = mTransformedShaderModuleCache.FindShaderModule(cacheKey); diff --git a/src/dawn_native/vulkan/ShaderModuleVk.h b/src/dawn_native/vulkan/ShaderModuleVk.h index 7bd0c2f185..bbb73007ff 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.h +++ b/src/dawn_native/vulkan/ShaderModuleVk.h @@ -33,9 +33,6 @@ namespace dawn_native { namespace vulkan { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult); - VkShaderModule GetHandle() const; - - // This is only called when UseTintGenerator is on ResultOrError GetTransformedModuleHandle(const char* entryPointName, PipelineLayout* layout);