Remove SPIRV-Cross usage from Metal backend.
Change-Id: I456b6cc660779175afc73bbef5134fbcf4988ad3 Bug: dawn:1036 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/60900 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
parent
f00c68a216
commit
6ab06f8881
|
@ -134,6 +134,14 @@ namespace dawn_native {
|
||||||
|
|
||||||
mFormatTable = BuildFormatTable(this);
|
mFormatTable = BuildFormatTable(this);
|
||||||
SetDefaultToggles();
|
SetDefaultToggles();
|
||||||
|
#if defined(DAWN_PLATFORM_MACOS)
|
||||||
|
if (!IsToggleEnabled(Toggle::UseTintGenerator)) {
|
||||||
|
EmitLog(
|
||||||
|
WGPULoggingType_Warning,
|
||||||
|
"Non-tint generator is not available on this platform; toggle disable ignored.\n");
|
||||||
|
ForceSetToggle(Toggle::UseTintGenerator, true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceBase::~DeviceBase() = default;
|
DeviceBase::~DeviceBase() = default;
|
||||||
|
|
|
@ -23,10 +23,6 @@
|
||||||
|
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
namespace spirv_cross {
|
|
||||||
class CompilerMSL;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
|
@ -22,10 +22,6 @@
|
||||||
|
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
namespace spirv_cross {
|
|
||||||
class CompilerMSL;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
@ -60,16 +56,6 @@ namespace dawn_native { namespace metal {
|
||||||
std::string* remappedEntryPointName,
|
std::string* remappedEntryPointName,
|
||||||
bool* needsStorageBufferLength,
|
bool* needsStorageBufferLength,
|
||||||
bool* hasInvariantAttribute);
|
bool* hasInvariantAttribute);
|
||||||
ResultOrError<std::string> TranslateToMSLWithSPIRVCross(
|
|
||||||
const char* entryPointName,
|
|
||||||
SingleShaderStage stage,
|
|
||||||
const PipelineLayout* layout,
|
|
||||||
uint32_t sampleMask,
|
|
||||||
const RenderPipeline* renderPipeline,
|
|
||||||
const VertexState* vertexState,
|
|
||||||
std::string* remappedEntryPointName,
|
|
||||||
bool* needsStorageBufferLength);
|
|
||||||
|
|
||||||
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
|
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
|
||||||
~ShaderModule() override = default;
|
~ShaderModule() override = default;
|
||||||
MaybeError Initialize(ShaderModuleParseResult* parseResult);
|
MaybeError Initialize(ShaderModuleParseResult* parseResult);
|
||||||
|
|
|
@ -15,18 +15,11 @@
|
||||||
#include "dawn_native/metal/ShaderModuleMTL.h"
|
#include "dawn_native/metal/ShaderModuleMTL.h"
|
||||||
|
|
||||||
#include "dawn_native/BindGroupLayout.h"
|
#include "dawn_native/BindGroupLayout.h"
|
||||||
#include "dawn_native/SpirvUtils.h"
|
|
||||||
#include "dawn_native/TintUtils.h"
|
#include "dawn_native/TintUtils.h"
|
||||||
#include "dawn_native/metal/DeviceMTL.h"
|
#include "dawn_native/metal/DeviceMTL.h"
|
||||||
#include "dawn_native/metal/PipelineLayoutMTL.h"
|
#include "dawn_native/metal/PipelineLayoutMTL.h"
|
||||||
#include "dawn_native/metal/RenderPipelineMTL.h"
|
#include "dawn_native/metal/RenderPipelineMTL.h"
|
||||||
|
|
||||||
#include <spirv_msl.hpp>
|
|
||||||
|
|
||||||
// Tint include must be after spirv_msl.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 <tint/tint.h>
|
#include <tint/tint.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -172,116 +165,6 @@ namespace dawn_native { namespace metal {
|
||||||
return std::move(result.msl);
|
return std::move(result.msl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::string> ShaderModule::TranslateToMSLWithSPIRVCross(
|
|
||||||
const char* entryPointName,
|
|
||||||
SingleShaderStage stage,
|
|
||||||
const PipelineLayout* layout,
|
|
||||||
uint32_t sampleMask,
|
|
||||||
const RenderPipeline* renderPipeline,
|
|
||||||
const VertexState* vertexState,
|
|
||||||
std::string* remappedEntryPointName,
|
|
||||||
bool* needsStorageBufferLength) {
|
|
||||||
const std::vector<uint32_t>* spirv = &GetSpirv();
|
|
||||||
spv::ExecutionModel executionModel = ShaderStageToExecutionModel(stage);
|
|
||||||
|
|
||||||
std::vector<uint32_t> pullingSpirv;
|
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
|
|
||||||
stage == SingleShaderStage::Vertex) {
|
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
|
||||||
DAWN_TRY_ASSIGN(pullingSpirv,
|
|
||||||
GeneratePullingSpirv(GetTintProgram(), *vertexState, entryPointName,
|
|
||||||
kPullingBufferBindingSet));
|
|
||||||
} else {
|
|
||||||
DAWN_TRY_ASSIGN(pullingSpirv,
|
|
||||||
GeneratePullingSpirv(GetSpirv(), *vertexState, entryPointName,
|
|
||||||
kPullingBufferBindingSet));
|
|
||||||
}
|
|
||||||
spirv = &pullingSpirv;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If these options are changed, the values in DawnSPIRVCrossMSLFastFuzzer.cpp need to
|
|
||||||
// be updated.
|
|
||||||
spirv_cross::CompilerMSL::Options options_msl;
|
|
||||||
|
|
||||||
// Disable PointSize builtin for https://bugs.chromium.org/p/dawn/issues/detail?id=146
|
|
||||||
// Because Metal will reject PointSize builtin if the shader is compiled into a render
|
|
||||||
// pipeline that uses a non-point topology.
|
|
||||||
// TODO (hao.x.li@intel.com): Remove this once WebGPU requires there is no
|
|
||||||
// gl_PointSize builtin (https://github.com/gpuweb/gpuweb/issues/332).
|
|
||||||
options_msl.enable_point_size_builtin = false;
|
|
||||||
|
|
||||||
// Always use vertex buffer 30 (the last one in the vertex buffer table) to contain
|
|
||||||
// the shader storage buffer lengths.
|
|
||||||
options_msl.buffer_size_buffer_index = kBufferLengthBufferSlot;
|
|
||||||
|
|
||||||
options_msl.additional_fixed_sample_mask = sampleMask;
|
|
||||||
|
|
||||||
spirv_cross::CompilerMSL compiler(*spirv);
|
|
||||||
compiler.set_msl_options(options_msl);
|
|
||||||
compiler.set_entry_point(entryPointName, executionModel);
|
|
||||||
|
|
||||||
// By default SPIRV-Cross will give MSL resources indices in increasing order.
|
|
||||||
// To make the MSL indices match the indices chosen in the PipelineLayout, we build
|
|
||||||
// a table of MSLResourceBinding to give to SPIRV-Cross.
|
|
||||||
|
|
||||||
// Create one resource binding entry per stage per binding.
|
|
||||||
for (BindGroupIndex group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
|
|
||||||
const BindGroupLayoutBase::BindingMap& bindingMap =
|
|
||||||
layout->GetBindGroupLayout(group)->GetBindingMap();
|
|
||||||
|
|
||||||
for (const auto& it : bindingMap) {
|
|
||||||
BindingNumber bindingNumber = it.first;
|
|
||||||
BindingIndex bindingIndex = it.second;
|
|
||||||
|
|
||||||
const BindingInfo& bindingInfo =
|
|
||||||
layout->GetBindGroupLayout(group)->GetBindingInfo(bindingIndex);
|
|
||||||
|
|
||||||
if (!(bindingInfo.visibility & StageBit(stage))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t shaderIndex = layout->GetBindingIndexInfo(stage)[group][bindingIndex];
|
|
||||||
|
|
||||||
spirv_cross::MSLResourceBinding mslBinding;
|
|
||||||
mslBinding.stage = executionModel;
|
|
||||||
mslBinding.desc_set = static_cast<uint32_t>(group);
|
|
||||||
mslBinding.binding = static_cast<uint32_t>(bindingNumber);
|
|
||||||
mslBinding.msl_buffer = mslBinding.msl_texture = mslBinding.msl_sampler =
|
|
||||||
shaderIndex;
|
|
||||||
|
|
||||||
compiler.add_msl_resource_binding(mslBinding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add vertex buffers bound as storage buffers
|
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
|
|
||||||
stage == SingleShaderStage::Vertex) {
|
|
||||||
for (VertexBufferSlot slot :
|
|
||||||
IterateBitSet(renderPipeline->GetVertexBufferSlotsUsed())) {
|
|
||||||
uint32_t metalIndex = renderPipeline->GetMtlVertexBufferIndex(slot);
|
|
||||||
|
|
||||||
spirv_cross::MSLResourceBinding mslBinding;
|
|
||||||
|
|
||||||
mslBinding.stage = spv::ExecutionModelVertex;
|
|
||||||
mslBinding.desc_set = static_cast<uint32_t>(kPullingBufferBindingSet);
|
|
||||||
mslBinding.binding = static_cast<uint8_t>(slot);
|
|
||||||
mslBinding.msl_buffer = metalIndex;
|
|
||||||
compiler.add_msl_resource_binding(mslBinding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SPIRV-Cross also supports re-ordering attributes but it seems to do the correct thing
|
|
||||||
// by default.
|
|
||||||
std::string msl = compiler.compile();
|
|
||||||
|
|
||||||
// Some entry point names are forbidden in MSL so SPIRV-Cross modifies them. Query the
|
|
||||||
// modified entryPointName from it.
|
|
||||||
*remappedEntryPointName = compiler.get_entry_point(entryPointName, executionModel).name;
|
|
||||||
*needsStorageBufferLength = compiler.needs_buffer_size_buffer();
|
|
||||||
|
|
||||||
return std::move(msl);
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeError ShaderModule::CreateFunction(const char* entryPointName,
|
MaybeError ShaderModule::CreateFunction(const char* entryPointName,
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
const PipelineLayout* layout,
|
const PipelineLayout* layout,
|
||||||
|
@ -301,17 +184,10 @@ namespace dawn_native { namespace metal {
|
||||||
std::string remappedEntryPointName;
|
std::string remappedEntryPointName;
|
||||||
std::string msl;
|
std::string msl;
|
||||||
bool hasInvariantAttribute = false;
|
bool hasInvariantAttribute = false;
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
DAWN_TRY_ASSIGN(
|
||||||
DAWN_TRY_ASSIGN(msl, TranslateToMSLWithTint(
|
msl, TranslateToMSLWithTint(entryPointName, stage, layout, sampleMask, renderPipeline,
|
||||||
entryPointName, stage, layout, sampleMask, renderPipeline,
|
vertexState, &remappedEntryPointName,
|
||||||
vertexState, &remappedEntryPointName,
|
&out->needsStorageBufferLength, &hasInvariantAttribute));
|
||||||
&out->needsStorageBufferLength, &hasInvariantAttribute));
|
|
||||||
} else {
|
|
||||||
DAWN_TRY_ASSIGN(msl, TranslateToMSLWithSPIRVCross(entryPointName, stage, layout,
|
|
||||||
sampleMask, renderPipeline,
|
|
||||||
vertexState, &remappedEntryPointName,
|
|
||||||
&out->needsStorageBufferLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metal uses Clang to compile the shader as C++14. Disable everything in the -Wall
|
// Metal uses Clang to compile the shader as C++14. Disable everything in the -Wall
|
||||||
// category. -Wunused-variable in particular comes up a lot in generated code, and some
|
// category. -Wunused-variable in particular comes up a lot in generated code, and some
|
||||||
|
|
Loading…
Reference in New Issue