implement color write mask

This commit is contained in:
Samuliak 2024-07-08 14:10:25 +02:00
parent 114a5f2f8f
commit 6c153d96fe
2 changed files with 12 additions and 5 deletions

View file

@ -6,14 +6,16 @@ using namespace PICA;
namespace Metal {
struct DrawPipelineHash { // 62 bits
struct DrawPipelineHash { // 56 bits
// Formats
ColorFmt colorFmt; // 3 bits
DepthFmt depthFmt; // 3 bits
// Blending
bool blendEnabled; // 1 bit
u32 blendControl; // 32 bits
// | functions | aeq | ceq |
u32 blendControl; // 22 bits (mask: 1111111111111111 00000111 00000111)
u8 colorWriteMask; // 4 bits
// Specialization constants (23 bits)
bool lightingEnabled; // 1 bit
@ -46,7 +48,7 @@ public:
MTL::RenderPipelineState* get(DrawPipelineHash hash) {
u32 fragmentFunctionHash = ((u32)hash.lightingEnabled << 22) | ((u32)hash.lightingNumLights << 19) | ((u32)hash.lightingConfig1 << 12) | ((((u32)hash.alphaControl & 0b1111111100000000) >> 8) << 4) | ((((u32)hash.alphaControl & 0b01110000) >> 4) << 1) | ((u32)hash.alphaControl & 0b0001);
u64 pipelineHash = ((u64)hash.colorFmt << 59) | ((u64)hash.depthFmt << 56) | ((u64)hash.blendEnabled << 55) | ((u64)hash.blendControl << 23) | fragmentFunctionHash;
u64 pipelineHash = ((u64)hash.colorFmt << 53) | ((u64)hash.depthFmt << 50) | ((u64)hash.blendEnabled << 49) | ((u64)hash.colorWriteMask << 45) | ((((u64)hash.blendControl & 0b11111111111111110000000000000000) >> 16) << 29) | ((((u64)hash.blendControl & 0b0000011100000000) >> 8) << 26) | (((u64)hash.blendControl & 0b00000111) << 23) | fragmentFunctionHash;
auto& pipeline = pipelineCache[pipelineHash];
if (!pipeline) {
auto& fragmentFunction = fragmentFunctionCache[fragmentFunctionHash];
@ -73,6 +75,12 @@ public:
auto colorAttachment = desc->colorAttachments()->object(0);
colorAttachment->setPixelFormat(toMTLPixelFormatColor(hash.colorFmt));
MTL::ColorWriteMask writeMask = 0;
if (hash.colorWriteMask & 0x1) writeMask |= MTL::ColorWriteMaskRed;
if (hash.colorWriteMask & 0x2) writeMask |= MTL::ColorWriteMaskGreen;
if (hash.colorWriteMask & 0x4) writeMask |= MTL::ColorWriteMaskBlue;
if (hash.colorWriteMask & 0x8) writeMask |= MTL::ColorWriteMaskAlpha;
colorAttachment->setWriteMask(writeMask);
if (hash.blendEnabled) {
const u8 rgbEquation = hash.blendControl & 0x7;
const u8 alphaEquation = Helpers::getBits<8, 3>(hash.blendControl);

View file

@ -477,8 +477,6 @@ void RendererMTL::drawVertices(PICA::PrimType primType, std::span<const PICA::Ve
const bool depthWriteEnable = Helpers::getBit<12>(depthControl);
const u8 depthFunc = Helpers::getBits<4, 3>(depthControl);
const u8 colorMask = Helpers::getBits<8, 4>(depthControl);
// TODO: color mask
// gl.setColourMask(colorMask & 0x1, colorMask & 0x2, colorMask & 0x4, colorMask & 0x8);
Metal::DepthStencilHash depthStencilHash{false, 1};
depthStencilHash.stencilConfig = regs[PICA::InternalRegs::StencilTest];
@ -521,6 +519,7 @@ void RendererMTL::drawVertices(PICA::PrimType primType, std::span<const PICA::Ve
// Blending and logic op
pipelineHash.blendEnabled = (regs[PICA::InternalRegs::ColourOperation] & (1 << 8)) != 0;
pipelineHash.colorWriteMask = colorMask;
u8 logicOp = 3; // Copy, which doesn't do anything
if (pipelineHash.blendEnabled) {