Lot more Metal changes

This commit is contained in:
Dynamitos
2024-08-28 17:54:14 +02:00
parent e3b06dfb22
commit 6eb114e892
40 changed files with 1634 additions and 1737 deletions
+23 -30
View File
@@ -14,40 +14,33 @@
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();
library->release();
}
if (function) {
function->release();
library->release();
}
}
void Shader::create(const ShaderCreateInfo &createInfo) {
Map<std::string, uint32> paramMapping;
auto [kernelBlob, entryPoint] =
generateShader(createInfo);
std::cout << (char *)kernelBlob->getBufferPointer() << std::endl;
hash = CRC::Calculate(kernelBlob->getBufferPointer(),
kernelBlob->getBufferSize(), CRC::CRC_32());
NS::Error *error;
MTL::CompileOptions *options = MTL::CompileOptions::alloc()->init();
library = graphics->getDevice()->newLibrary(
NS::String::string((char *)kernelBlob->getBufferPointer(),
NS::ASCIIStringEncoding),
options, &error);
options->release();
if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding)
<< std::endl;
}
function = library->newFunction(NS::String::string(
entryPoint.c_str(), NS::ASCIIStringEncoding));
if (!function) {
assert(false);
}
void Shader::create(const ShaderCreateInfo& createInfo) {
auto [kernelBlob, entryPoint] = generateShader(createInfo);
std::ofstream test("test.metal");
test.write((char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
test.close();
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
NS::Error* error;
MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init();
library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options,
&error);
options->release();
if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
}
function = library->newFunction(NS::String::string(entryPoint.c_str(), NS::ASCIIStringEncoding));
if (!function) {
assert(false);
}
}
uint32 Shader::getShaderHash() const { return hash; }