Metal API validation fixes

This commit is contained in:
Jack Andersen 2018-01-24 20:55:42 -10:00
parent 1d70723c98
commit 5b62fcd826
3 changed files with 16 additions and 7 deletions

View File

@ -48,7 +48,7 @@ public:
const ObjToken<IVertexFormat>& vtxFmt, const ObjToken<IVertexFormat>& vtxFmt,
BlendFactor srcFac, BlendFactor dstFac, Primitive prim, BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
ZTest depthTest, bool depthWrite, bool colorWrite, ZTest depthTest, bool depthWrite, bool colorWrite,
bool alphaWrite, CullMode culling); bool alphaWrite, CullMode culling, bool depthAttachment = true);
ObjToken<IShaderDataBinding> ObjToken<IShaderDataBinding>
newShaderDataBinding(const ObjToken<IShaderPipeline>& pipeline, newShaderDataBinding(const ObjToken<IShaderPipeline>& pipeline,

View File

@ -99,7 +99,7 @@ class MetalDataFactoryImpl : public MetalDataFactory, public GraphicsDataFactory
m_gammaVFMT = ctx.newVertexFormat(2, vfmt); m_gammaVFMT = ctx.newVertexFormat(2, vfmt);
m_gammaShader = static_cast<Context&>(ctx).newShaderPipeline(GammaVS, GammaFS, m_gammaShader = static_cast<Context&>(ctx).newShaderPipeline(GammaVS, GammaFS,
nullptr, nullptr, m_gammaVFMT, BlendFactor::One, BlendFactor::Zero, nullptr, nullptr, m_gammaVFMT, BlendFactor::One, BlendFactor::Zero,
Primitive::TriStrips, ZTest::None, false, true, false, CullMode::None); Primitive::TriStrips, ZTest::None, false, true, false, CullMode::None, false);
m_gammaLUT = ctx.newDynamicTexture(256, 256, TextureFormat::I16, TextureClampMode::ClampToEdge); m_gammaLUT = ctx.newDynamicTexture(256, 256, TextureFormat::I16, TextureClampMode::ClampToEdge);
setDisplayGamma(1.f); setDisplayGamma(1.f);
const struct Vert { const struct Vert {
@ -879,7 +879,7 @@ class MetalShaderPipeline : public GraphicsDataNode<IShaderPipeline>
const ObjToken<IVertexFormat>& vtxFmt, NSUInteger targetSamples, const ObjToken<IVertexFormat>& vtxFmt, NSUInteger targetSamples,
BlendFactor srcFac, BlendFactor dstFac, Primitive prim, BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
ZTest depthTest, bool depthWrite, bool colorWrite, ZTest depthTest, bool depthWrite, bool colorWrite,
bool alphaWrite, CullMode culling) bool alphaWrite, CullMode culling, bool depthAttachment = true)
: GraphicsDataNode<IShaderPipeline>(parent), : GraphicsDataNode<IShaderPipeline>(parent),
m_drawPrim(PRIMITIVE_TABLE[int(prim)]), m_drawPrim(PRIMITIVE_TABLE[int(prim)]),
m_vert(std::move(vert)), m_frag(std::move(frag)) m_vert(std::move(vert)), m_frag(std::move(frag))
@ -921,7 +921,7 @@ class MetalShaderPipeline : public GraphicsDataNode<IShaderPipeline>
} }
desc.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorOne; desc.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorOne;
desc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorZero; desc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorZero;
desc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float; desc.depthAttachmentPixelFormat = depthAttachment ? MTLPixelFormatDepth32Float : MTLPixelFormatInvalid;
desc.inputPrimitiveTopology = MTLPrimitiveTopologyClassTriangle; desc.inputPrimitiveTopology = MTLPrimitiveTopologyClassTriangle;
NSError* err = nullptr; NSError* err = nullptr;
m_state = [ctx->m_dev newRenderPipelineStateWithDescriptor:desc error:&err]; m_state = [ctx->m_dev newRenderPipelineStateWithDescriptor:desc error:&err];
@ -1493,6 +1493,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue
MetalShaderDataBinding* gammaBinding = gfxF->m_gammaBinding.cast<MetalShaderDataBinding>(); MetalShaderDataBinding* gammaBinding = gfxF->m_gammaBinding.cast<MetalShaderDataBinding>();
gammaBinding->m_texs[0].tex = m_needsDisplay.get(); gammaBinding->m_texs[0].tex = m_needsDisplay.get();
gammaBinding->bind(enc, m_drawBuf); gammaBinding->bind(enc, m_drawBuf);
[enc setFragmentSamplerStates:m_samplers withRange:NSMakeRange(0, 3)];
[enc drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; [enc drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
gammaBinding->m_texs[0].tex.reset(); gammaBinding->m_texs[0].tex.reset();
[enc endEncoding]; [enc endEncoding];
@ -1632,7 +1633,7 @@ MetalDataFactory::Context::newShaderPipeline(const char* vertSource, const char*
const ObjToken<IVertexFormat>& vtxFmt, const ObjToken<IVertexFormat>& vtxFmt,
BlendFactor srcFac, BlendFactor dstFac, Primitive prim, BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
ZTest depthTest, bool depthWrite, bool colorWrite, ZTest depthTest, bool depthWrite, bool colorWrite,
bool alphaWrite, CullMode culling) bool alphaWrite, CullMode culling, bool depthAttachment)
{ {
@autoreleasepool @autoreleasepool
{ {
@ -1759,8 +1760,9 @@ MetalDataFactory::Context::newShaderPipeline(const char* vertSource, const char*
} }
return {new MetalShaderPipeline(m_data, factory.m_ctx, std::move(vertShader), std::move(fragShader), return {new MetalShaderPipeline(m_data, factory.m_ctx, std::move(vertShader), std::move(fragShader),
vtxFmt, factory.m_ctx->m_sampleCount, srcFac, dstFac, prim, depthTest, depthWrite, vtxFmt, depthAttachment ? factory.m_ctx->m_sampleCount : 1,
colorWrite, alphaWrite, culling)}; srcFac, dstFac, prim, depthTest, depthWrite,
colorWrite, alphaWrite, culling, depthAttachment)};
} }
} }

View File

@ -110,11 +110,18 @@ public:
if (!gfxApi.compare("OpenGL")) if (!gfxApi.compare("OpenGL"))
useGL = true; useGL = true;
for (const SystemString& arg : args) for (const SystemString& arg : args)
{
if (!arg.compare("--gl")) if (!arg.compare("--gl"))
{ {
useGL = true; useGL = true;
break; break;
} }
else if (!arg.compare("--metal"))
{
useGL = false;
break;
}
}
if (!useGL) if (!useGL)
m_metalCtx.m_dev = MTLCreateSystemDefaultDevice(); m_metalCtx.m_dev = MTLCreateSystemDefaultDevice();
if (m_metalCtx.m_dev) if (m_metalCtx.m_dev)