From 5b62fcd82613ab3ca8fddc50a41303ec7196b268 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 24 Jan 2018 20:55:42 -1000 Subject: [PATCH] Metal API validation fixes --- include/boo/graphicsdev/Metal.hpp | 2 +- lib/graphicsdev/Metal.mm | 14 ++++++++------ lib/mac/ApplicationCocoa.mm | 7 +++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/boo/graphicsdev/Metal.hpp b/include/boo/graphicsdev/Metal.hpp index 5a8e8ee..5768264 100644 --- a/include/boo/graphicsdev/Metal.hpp +++ b/include/boo/graphicsdev/Metal.hpp @@ -48,7 +48,7 @@ public: const ObjToken& vtxFmt, BlendFactor srcFac, BlendFactor dstFac, Primitive prim, ZTest depthTest, bool depthWrite, bool colorWrite, - bool alphaWrite, CullMode culling); + bool alphaWrite, CullMode culling, bool depthAttachment = true); ObjToken newShaderDataBinding(const ObjToken& pipeline, diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index 1040d78..682bd41 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -99,7 +99,7 @@ class MetalDataFactoryImpl : public MetalDataFactory, public GraphicsDataFactory m_gammaVFMT = ctx.newVertexFormat(2, vfmt); m_gammaShader = static_cast(ctx).newShaderPipeline(GammaVS, GammaFS, 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); setDisplayGamma(1.f); const struct Vert { @@ -879,7 +879,7 @@ class MetalShaderPipeline : public GraphicsDataNode const ObjToken& vtxFmt, NSUInteger targetSamples, BlendFactor srcFac, BlendFactor dstFac, Primitive prim, ZTest depthTest, bool depthWrite, bool colorWrite, - bool alphaWrite, CullMode culling) + bool alphaWrite, CullMode culling, bool depthAttachment = true) : GraphicsDataNode(parent), m_drawPrim(PRIMITIVE_TABLE[int(prim)]), m_vert(std::move(vert)), m_frag(std::move(frag)) @@ -921,7 +921,7 @@ class MetalShaderPipeline : public GraphicsDataNode } desc.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorOne; desc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorZero; - desc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float; + desc.depthAttachmentPixelFormat = depthAttachment ? MTLPixelFormatDepth32Float : MTLPixelFormatInvalid; desc.inputPrimitiveTopology = MTLPrimitiveTopologyClassTriangle; NSError* err = nullptr; m_state = [ctx->m_dev newRenderPipelineStateWithDescriptor:desc error:&err]; @@ -1493,6 +1493,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue MetalShaderDataBinding* gammaBinding = gfxF->m_gammaBinding.cast(); gammaBinding->m_texs[0].tex = m_needsDisplay.get(); gammaBinding->bind(enc, m_drawBuf); + [enc setFragmentSamplerStates:m_samplers withRange:NSMakeRange(0, 3)]; [enc drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; gammaBinding->m_texs[0].tex.reset(); [enc endEncoding]; @@ -1632,7 +1633,7 @@ MetalDataFactory::Context::newShaderPipeline(const char* vertSource, const char* const ObjToken& vtxFmt, BlendFactor srcFac, BlendFactor dstFac, Primitive prim, ZTest depthTest, bool depthWrite, bool colorWrite, - bool alphaWrite, CullMode culling) + bool alphaWrite, CullMode culling, bool depthAttachment) { @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), - vtxFmt, factory.m_ctx->m_sampleCount, srcFac, dstFac, prim, depthTest, depthWrite, - colorWrite, alphaWrite, culling)}; + vtxFmt, depthAttachment ? factory.m_ctx->m_sampleCount : 1, + srcFac, dstFac, prim, depthTest, depthWrite, + colorWrite, alphaWrite, culling, depthAttachment)}; } } diff --git a/lib/mac/ApplicationCocoa.mm b/lib/mac/ApplicationCocoa.mm index 3cba24e..cbb84dc 100644 --- a/lib/mac/ApplicationCocoa.mm +++ b/lib/mac/ApplicationCocoa.mm @@ -110,11 +110,18 @@ public: if (!gfxApi.compare("OpenGL")) useGL = true; for (const SystemString& arg : args) + { if (!arg.compare("--gl")) { useGL = true; break; } + else if (!arg.compare("--metal")) + { + useGL = false; + break; + } + } if (!useGL) m_metalCtx.m_dev = MTLCreateSystemDefaultDevice(); if (m_metalCtx.m_dev)