Metal: Recreate the compiler everytime we use it.
This commit is contained in:
parent
2f96e129ef
commit
9a72ea09a9
|
@ -31,7 +31,6 @@ namespace metal {
|
|||
class ShaderModule : public ShaderModuleBase {
|
||||
public:
|
||||
ShaderModule(ShaderModuleBuilder* builder);
|
||||
~ShaderModule();
|
||||
|
||||
struct MetalFunctionData {
|
||||
id<MTLFunction> function;
|
||||
|
@ -40,7 +39,10 @@ namespace metal {
|
|||
MetalFunctionData GetFunction(const char* functionName, const PipelineLayout* layout) const;
|
||||
|
||||
private:
|
||||
spirv_cross::CompilerMSL* compiler = nullptr;
|
||||
// Calling compile on CompilerMSL somehow changes internal state that makes subsequent
|
||||
// compiles return invalid MSL. We keep the spirv around and recreate the compiler everytime
|
||||
// we need to use it.
|
||||
std::vector<uint32_t> spirv;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -42,17 +42,15 @@ namespace metal {
|
|||
}
|
||||
|
||||
ShaderModule::ShaderModule(ShaderModuleBuilder* builder)
|
||||
: ShaderModuleBase(builder) {
|
||||
compiler = new spirv_cross::CompilerMSL(builder->AcquireSpirv());
|
||||
ExtractSpirvInfo(*compiler);
|
||||
}
|
||||
|
||||
ShaderModule::~ShaderModule() {
|
||||
delete compiler;
|
||||
: ShaderModuleBase(builder), spirv(builder->AcquireSpirv()) {
|
||||
spirv_cross::CompilerMSL compiler(spirv);
|
||||
ExtractSpirvInfo(compiler);
|
||||
}
|
||||
|
||||
ShaderModule::MetalFunctionData ShaderModule::GetFunction(const char* functionName,
|
||||
const PipelineLayout* layout) const {
|
||||
spirv_cross::CompilerMSL compiler(spirv);
|
||||
|
||||
// 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
|
||||
|
@ -92,14 +90,14 @@ namespace metal {
|
|||
MetalFunctionData result;
|
||||
|
||||
{
|
||||
auto size = compiler->get_entry_point(functionName).workgroup_size;
|
||||
auto size = compiler.get_entry_point(functionName).workgroup_size;
|
||||
result.localWorkgroupSize = MTLSizeMake(size.x, size.y, size.z);
|
||||
}
|
||||
|
||||
{
|
||||
// SPIRV-Cross also supports re-ordering attributes but it seems to do the correct thing
|
||||
// by default.
|
||||
std::string msl = compiler->compile(nullptr, &mslBindings);
|
||||
std::string msl = compiler.compile(nullptr, &mslBindings);
|
||||
NSString* mslSource = [NSString stringWithFormat:@"%s", msl.c_str()];
|
||||
|
||||
auto mtlDevice = ToBackend(GetDevice())->GetMTLDevice();
|
||||
|
|
Loading…
Reference in New Issue