Handle pipelines with no fragment shaders on Metal
This commit is contained in:
parent
fcf6277032
commit
d97e88741b
1 changed files with 61 additions and 62 deletions
|
@ -441,7 +441,12 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
||||||
|
|
||||||
NSError* error = nil;
|
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;
|
id<MTLLibrary> vertexLibrary;
|
||||||
{
|
{
|
||||||
std::string vertex_src;
|
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];
|
vertexLibrary = [device newLibraryWithSource:[NSString stringWithFormat:@"%s", vertex_src.c_str()] options:nil error:&error];
|
||||||
if(!vertexLibrary)
|
if(!vertexLibrary)
|
||||||
NSLog(@"%@", error.debugDescription);
|
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;
|
id<MTLLibrary> fragmentLibrary;
|
||||||
{
|
{
|
||||||
std::string fragment_src;
|
std::string fragment_src;
|
||||||
|
@ -485,17 +500,14 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
||||||
NSLog(@"%@", error.debugDescription);
|
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);
|
auto fragment_constants = get_constant_values(info.shaders.fragment_constants);
|
||||||
|
|
||||||
id<MTLFunction> fragmentFunc = [fragmentLibrary newFunctionWithName:@"main0" constantValues:fragment_constants error:nil];
|
id<MTLFunction> fragmentFunc = [fragmentLibrary newFunctionWithName:@"main0" constantValues:fragment_constants error:nil];
|
||||||
|
|
||||||
if(debug_enabled) {
|
if(debug_enabled)
|
||||||
vertexFunc.label = [NSString stringWithFormat:@"%s", info.shaders.vertex_path.data()];
|
|
||||||
fragmentFunc.label = [NSString stringWithFormat:@"%s", info.shaders.fragment_path.data()];
|
fragmentFunc.label = [NSString stringWithFormat:@"%s", info.shaders.fragment_path.data()];
|
||||||
|
|
||||||
|
pipelineDescriptor.fragmentFunction = fragmentFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLVertexDescriptor* descriptor = [MTLVertexDescriptor new];
|
MTLVertexDescriptor* descriptor = [MTLVertexDescriptor new];
|
||||||
|
@ -539,10 +551,6 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
||||||
descriptor.attributes[attribute.location].offset = (NSUInteger)attribute.offset;
|
descriptor.attributes[attribute.location].offset = (NSUInteger)attribute.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLRenderPipelineDescriptor *pipelineDescriptor = [MTLRenderPipelineDescriptor new];
|
|
||||||
pipelineDescriptor.vertexFunction = vertexFunc;
|
|
||||||
pipelineDescriptor.fragmentFunction = fragmentFunc;
|
|
||||||
|
|
||||||
if(info.render_pass != nullptr) {
|
if(info.render_pass != nullptr) {
|
||||||
GFXMetalRenderPass* metalRenderPass = (GFXMetalRenderPass*)info.render_pass;
|
GFXMetalRenderPass* metalRenderPass = (GFXMetalRenderPass*)info.render_pass;
|
||||||
|
|
||||||
|
@ -635,15 +643,6 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
|
||||||
if(info.rasterization.polygon_type == GFXPolygonType::Line)
|
if(info.rasterization.polygon_type == GFXPolygonType::Line)
|
||||||
pipeline->renderWire = true;
|
pipeline->renderWire = true;
|
||||||
|
|
||||||
[vertexFunc release];
|
|
||||||
[fragmentFunc release];
|
|
||||||
|
|
||||||
[vertexLibrary release];
|
|
||||||
[fragmentLibrary release];
|
|
||||||
|
|
||||||
[vertex_constants release];
|
|
||||||
[fragment_constants release];
|
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue