Metal is impossible to debug, thanks apple

This commit is contained in:
Dynamitos
2024-04-14 11:35:37 +02:00
parent f5eb12a5de
commit dc2f0eac30
14 changed files with 325 additions and 138 deletions
+15 -17
View File
@@ -14,8 +14,8 @@
using namespace Seele;
using namespace Seele::Metal;
Shader::Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage)
: stage(stage), graphics(graphics) {}
Shader::Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage) : stage(stage), graphics(graphics) {}
Shader::~Shader() {
if (function) {
function->release();
@@ -23,29 +23,27 @@ Shader::~Shader() {
}
}
void Shader::create(const ShaderCreateInfo &createInfo) {
Slang::ComPtr<slang::IBlob> kernelBlob =
generateShader(createInfo, SLANG_SPIRV);
spirv_cross::CompilerMSL comp((const uint32 *)kernelBlob->getBufferPointer(),
kernelBlob->getBufferSize() / 4);
void Shader::create(const ShaderCreateInfo& createInfo) {
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_SPIRV);
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
spirv_cross::CompilerMSL comp((const uint32*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize() / 4);
auto options = comp.get_msl_options();
options.argument_buffers = true;
options.argument_buffers_tier =
spirv_cross::CompilerMSL::Options::ArgumentBuffersTier::Tier2;
options.argument_buffers_tier = spirv_cross::CompilerMSL::Options::ArgumentBuffersTier::Tier2;
options.set_msl_version(3);
comp.set_msl_options(options);
std::string metalCode = comp.compile();
NS::Error *error = nullptr;
MTL::CompileOptions *mtlOptions = MTL::CompileOptions::alloc()->init();
NS::Error* error = nullptr;
MTL::CompileOptions* mtlOptions = MTL::CompileOptions::alloc()->init();
library = graphics->getDevice()->newLibrary(
NS::String::string(metalCode.c_str(), NS::ASCIIStringEncoding),
mtlOptions, &error);
library = graphics->getDevice()->newLibrary(NS::String::string(metalCode.c_str(), NS::ASCIIStringEncoding),
mtlOptions, &error);
if (error) {
std::cout << error->debugDescription() << std::endl;
assert(false);
}
function =
library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding));
function = library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding));
mtlOptions->release();
}
}
uint32 Shader::getShaderHash() const { return hash; }