Archived
1
Fork 0

Handle pipelines with no fragment shaders on Metal

This commit is contained in:
redstrate 2021-02-05 19:50:19 -05:00
parent fcf6277032
commit d97e88741b

View file

@ -441,7 +441,12 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
NSError* error = nil;
// vertex
MTLRenderPipelineDescriptor *pipelineDescriptor = [MTLRenderPipelineDescriptor new];
const bool has_vertex_stage = !info.shaders.vertex_path.empty() || !info.shaders.vertex_src.empty();
const bool has_fragment_stage = !info.shaders.fragment_path.empty() || !info.shaders.fragment_src.empty();
if(has_vertex_stage) {
id<MTLLibrary> vertexLibrary;
{
std::string vertex_src;
@ -461,9 +466,19 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
vertexLibrary = [device newLibraryWithSource:[NSString stringWithFormat:@"%s", vertex_src.c_str()] options:nil error:&error];
if(!vertexLibrary)
NSLog(@"%@", error.debugDescription);
auto vertex_constants = get_constant_values(info.shaders.vertex_constants);
id<MTLFunction> vertexFunc = [vertexLibrary newFunctionWithName:@"main0" constantValues:vertex_constants error:nil];
if(debug_enabled)
vertexFunc.label = [NSString stringWithFormat:@"%s", info.shaders.vertex_path.data()];
pipelineDescriptor.vertexFunction = vertexFunc;
}
}
// fragment
if(has_fragment_stage) {
id<MTLLibrary> fragmentLibrary;
{
std::string fragment_src;
@ -485,17 +500,14 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
NSLog(@"%@", error.debugDescription);
}
auto vertex_constants = get_constant_values(info.shaders.vertex_constants);
id<MTLFunction> vertexFunc = [vertexLibrary newFunctionWithName:@"main0" constantValues:vertex_constants error:nil];
auto fragment_constants = get_constant_values(info.shaders.fragment_constants);
id<MTLFunction> fragmentFunc = [fragmentLibrary newFunctionWithName:@"main0" constantValues:fragment_constants error:nil];
if(debug_enabled) {
vertexFunc.label = [NSString stringWithFormat:@"%s", info.shaders.vertex_path.data()];
if(debug_enabled)
fragmentFunc.label = [NSString stringWithFormat:@"%s", info.shaders.fragment_path.data()];
pipelineDescriptor.fragmentFunction = fragmentFunc;
}
MTLVertexDescriptor* descriptor = [MTLVertexDescriptor new];
@ -539,10 +551,6 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
descriptor.attributes[attribute.location].offset = (NSUInteger)attribute.offset;
}
MTLRenderPipelineDescriptor *pipelineDescriptor = [MTLRenderPipelineDescriptor new];
pipelineDescriptor.vertexFunction = vertexFunc;
pipelineDescriptor.fragmentFunction = fragmentFunc;
if(info.render_pass != nullptr) {
GFXMetalRenderPass* metalRenderPass = (GFXMetalRenderPass*)info.render_pass;
@ -635,15 +643,6 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
if(info.rasterization.polygon_type == GFXPolygonType::Line)
pipeline->renderWire = true;
[vertexFunc release];
[fragmentFunc release];
[vertexLibrary release];
[fragmentLibrary release];
[vertex_constants release];
[fragment_constants release];
return pipeline;
}