wrote c compatible return code structure
This commit is contained in:
@@ -62,7 +62,7 @@ GN_EXPORT gnReturnCode gnRegisterOutputDeviceFn(gnOutputDevice* outputDevice, co
|
||||
MTL::CompileOptions* options = nullptr;
|
||||
MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error);
|
||||
if (!library) {
|
||||
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
|
||||
return gnReturnError(GN_FAILED_CREATE_DEVICE, error->localizedDescription()->utf8String());
|
||||
}
|
||||
MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding));
|
||||
MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding));
|
||||
@@ -74,61 +74,7 @@ GN_EXPORT gnReturnCode gnRegisterOutputDeviceFn(gnOutputDevice* outputDevice, co
|
||||
|
||||
instance.instance->framebufferRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error);
|
||||
if (!instance.instance->framebufferRenderer) {
|
||||
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char* shaderSrc = R"metal(
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexIn {
|
||||
float3 position;
|
||||
float2 uv;
|
||||
};
|
||||
|
||||
struct VertexOut {
|
||||
float4 position [[position]];
|
||||
};
|
||||
|
||||
vertex VertexOut vs_main(uint vertexID [[vertex_id]]) {
|
||||
float2 positions[6] = {
|
||||
{-0.5, -0.5},
|
||||
{ 0.5, -0.5},
|
||||
{-0.5, 0.5},
|
||||
{ 0.5, -0.5},
|
||||
{-0.5, 0.5},
|
||||
{ 0.5, 0.5}
|
||||
};
|
||||
|
||||
VertexOut out;
|
||||
out.position = float4(positions[vertexID], 0.0, 1.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 fs_main(VertexOut in [[stage_in]]) {
|
||||
return float4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
)metal";
|
||||
|
||||
NS::Error* error = nullptr;
|
||||
MTL::CompileOptions* options = nullptr;
|
||||
MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error);
|
||||
if (!library) {
|
||||
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
|
||||
}
|
||||
MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding));
|
||||
MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding));
|
||||
|
||||
MTL::RenderPipelineDescriptor* pipelineDesc = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
pipelineDesc->setVertexFunction(vs);
|
||||
pipelineDesc->setFragmentFunction(fs);
|
||||
pipelineDesc->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm);
|
||||
|
||||
instance.instance->testSquareRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error);
|
||||
if (!instance.instance->framebufferRenderer) {
|
||||
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
|
||||
return gnReturnError(GN_FAILED_CREATE_DEVICE, error->localizedDescription()->utf8String());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ GN_EXPORT gnReturnCode gnCreateFramebufferFn(gnFramebuffer* framebuffer, const g
|
||||
stencilAttachment->setStoreAction(MTL::StoreActionStore);
|
||||
stencilAttachment->release();
|
||||
} else {
|
||||
GN_RETURN_ERROR("fuck you (line 46 in metal_framebuffer.cpp)");
|
||||
return gnReturnError(GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, "GN_DEPTH_ATTACHMENT and GN_STENCIL_ATTACHMENT are unsupported on metal for now");
|
||||
}
|
||||
}
|
||||
return GN_SUCCESS;
|
||||
|
@@ -117,12 +117,12 @@ GN_EXPORT void gnGraphicsPipelineAddPushConstantFn(gnGraphicsPipeline& graphicsP
|
||||
|
||||
}
|
||||
GN_EXPORT gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline* graphicsPipeline, gnOutputDevice& outputDevice) {
|
||||
if (graphicsPipeline->graphicsPipeline == nullptr) GN_RETURN_ERROR("Need to call one gnGraphicsPipeline function to create a graphics pipeline");
|
||||
if (graphicsPipeline->graphicsPipeline == nullptr) graphicsPipeline->graphicsPipeline = new gnPlatformGraphicsPipeline();
|
||||
NS::Error* error = nullptr;
|
||||
graphicsPipeline->graphicsPipeline->renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm);
|
||||
graphicsPipeline->graphicsPipeline->renderPipelineState = outputDevice.outputDevice->device->newRenderPipelineState(graphicsPipeline->graphicsPipeline->renderPipelineDescriptor, &error);
|
||||
if (!graphicsPipeline->graphicsPipeline->renderPipelineState)
|
||||
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
|
||||
return gnReturnError(GN_FAILED_CREATE_GRAPHICS_PIPELINE, error->localizedDescription()->utf8String());
|
||||
|
||||
graphicsPipeline->graphicsPipeline->depthStencilState = outputDevice.outputDevice->device->newDepthStencilState(graphicsPipeline->graphicsPipeline->depthStateDescriptor);
|
||||
graphicsPipeline->graphicsPipeline->outputDevice = &outputDevice;
|
||||
|
@@ -24,7 +24,7 @@ GN_EXPORT gnReturnCode gnCreateRenderPassFn(gnRenderPass* renderPass, const gnOu
|
||||
else if (renderPass->attachments[i].colorMode == GN_DEPTH8_STENCIL24) {}
|
||||
else {
|
||||
std::string return_code = "GN_RENDERPASS_ATTATCHMENT_(" + std::to_string(i) + ")" + "_UNSUPPORTED_COLOR_MODE";
|
||||
GN_RETURN_ERROR(return_code.c_str());
|
||||
return gnReturnError(GN_UNKNOWN_COLOR_FORMAT, return_code.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "metal_shader_module.h"
|
||||
#include "metal_shader.h"
|
||||
#include "spirv_msl.hpp"
|
||||
#include "core/devices/metal_output_devices.h"
|
||||
#include "core/shaders/gryphn_shader.h"
|
||||
|
||||
static uint32_t* chars_to_uint32s(const char* chars, size_t num_chars) {
|
||||
if (chars == NULL || num_chars == 0) {
|
||||
@@ -93,7 +93,7 @@ GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* shaderModule, const
|
||||
shaderModule->shaderModule->uniformBufferOffset = 0;
|
||||
shaderModule->shaderModule->pushConstantOffset = largestBinding + 1;
|
||||
} else {
|
||||
GN_RETURN_ERROR("GN_UNKNOWN_SHADER_MODULE_TYPE_(I prolly lazy)");
|
||||
return gnReturnError(GN_UNKNOWN_SHADER_MODULE, "unknown shader module type (vertex and fragment are the only supported ones for now)");
|
||||
}
|
||||
|
||||
// std::cout << shaderSource << "\n";
|
||||
@@ -103,9 +103,9 @@ GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* shaderModule, const
|
||||
NS::String* sourceCode = NS::String::string(shaderSource.c_str(), NS::StringEncoding::UTF8StringEncoding);
|
||||
MTL::Library* shaderLib = outputDeviec.outputDevice->device->newLibrary(sourceCode, mtloptions, &error);
|
||||
if (!shaderLib)
|
||||
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
|
||||
return gnReturnError(GN_SHADER_FAILED_TO_COMPILE, error->localizedDescription()->utf8String());
|
||||
if (shaderLib->functionNames()->count() > 1)
|
||||
GN_RETURN_ERROR("More than one shader function in shader");
|
||||
return gnReturnError(GN_SHADER_FAILED_TO_COMPILE, "More than one shader function in shader");
|
||||
|
||||
shaderModule->shaderModule->shaderFunction = shaderLib->newFunction(reinterpret_cast<NS::String*>(shaderLib->functionNames()->object(0)));
|
||||
return GN_SUCCESS;
|
||||
|
@@ -49,14 +49,14 @@ GN_EXPORT gnErrorCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevice
|
||||
if (texture->textureColorFormat == GN_RED)
|
||||
textureDescriptor->setPixelFormat(MTL::PixelFormatR8Unorm);
|
||||
else if (texture->textureColorFormat == GN_RGB8)
|
||||
return gnReturnError("GN_RGB8_UNSUPPORTED");
|
||||
return gnReturnError(GN_UNSUPPORTED_COLOR_FORMAT, "GN_RGB8_UNSUPPORTED");
|
||||
else if (texture->textureColorFormat == GN_RGBA8)
|
||||
textureDescriptor->setPixelFormat(MTL::PixelFormatRGBA8Unorm);
|
||||
else if (texture->textureColorFormat == GN_BGRA8)
|
||||
textureDescriptor->setPixelFormat(MTL::PixelFormatBGRA8Unorm);
|
||||
else if (texture->textureColorFormat == GN_DEPTH_STENCIL)
|
||||
textureDescriptor->setPixelFormat(MTL::PixelFormatDepth32Float_Stencil8);
|
||||
else return gnReturnError("GN_UNSUPPORTED_PIXEL_FORMAT");
|
||||
else return gnReturnError(GN_UNKNOWN_COLOR_FORMAT, "unknown pixel format");
|
||||
|
||||
textureDescriptor->setWidth(texture->textureExtent.x);
|
||||
textureDescriptor->setHeight(texture->textureExtent.y);
|
||||
|
Reference in New Issue
Block a user