From 00f6262ff3ee75a2999d1241c8b0579223744012 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 26 Feb 2018 14:23:41 +0100 Subject: [PATCH] [dxbc] Properly implement Input/Output coverage masks --- src/d3d11/d3d11_device.cpp | 3 ++- src/dxbc/dxbc_compiler.cpp | 53 +++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index b07a0509..c43b7b49 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -912,6 +912,7 @@ namespace dxvk { ID3D11ClassLinkage* pClassLinkage, ID3D11HullShader** ppHullShader) { D3D11ShaderModule module; + *ppHullShader = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage))) @@ -932,7 +933,7 @@ namespace dxvk { ID3D11ClassLinkage* pClassLinkage, ID3D11DomainShader** ppDomainShader) { D3D11ShaderModule module; - + *ppDomainShader = nullptr; if (FAILED(this->CreateShaderModule(&module, pShaderBytecode, BytecodeLength, pClassLinkage))) return E_INVALIDARG; diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index fc0115bd..af0cbc94 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -425,13 +425,22 @@ namespace dxvk { "vThreadIndexInGroup"); } break; + case DxbcOperandType::InputCoverageMask: { + m_module.enableCapability(spv::CapabilitySampleRateShading); + m_ps.builtinSampleMaskIn = emitNewBuiltinVariable({ + { DxbcScalarType::Uint32, 1, 1 }, + spv::StorageClassInput }, + spv::BuiltInSampleMask, + "vCoverage"); + } break; + case DxbcOperandType::OutputCoverageMask: { m_module.enableCapability(spv::CapabilitySampleRateShading); m_ps.builtinSampleMaskOut = emitNewBuiltinVariable({ - { DxbcScalarType::Uint32, 1, 0 }, + { DxbcScalarType::Uint32, 1, 1 }, spv::StorageClassOutput }, spv::BuiltInSampleMask, - "oCoverage"); + "oMask"); } break; case DxbcOperandType::OutputDepth: { @@ -3723,9 +3732,8 @@ namespace dxvk { const uint32_t ptrTypeId = getPointerTypeId(info); - const std::array indices = { - m_module.consti32(0), constId.id - }; + const std::array indices = + {{ m_module.consti32(0), constId.id }}; DxbcRegisterPointer result; result.type.ctype = info.type.ctype; @@ -3802,10 +3810,37 @@ namespace dxvk { { DxbcScalarType::Uint32, 1 }, m_cs.builtinLocalInvocationIndex }; - case DxbcOperandType::OutputCoverageMask: - return DxbcRegisterPointer { - { DxbcScalarType::Uint32, 1 }, - m_ps.builtinSampleMaskOut }; + case DxbcOperandType::InputCoverageMask: { + const std::array indices + = {{ m_module.constu32(0) }}; + + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(result.type), + spv::StorageClassInput), + m_ps.builtinSampleMaskIn, + indices.size(), indices.data()); + return result; + } + + case DxbcOperandType::OutputCoverageMask: { + const std::array indices + = {{ m_module.constu32(0) }}; + + DxbcRegisterPointer result; + result.type.ctype = DxbcScalarType::Uint32; + result.type.ccount = 1; + result.id = m_module.opAccessChain( + m_module.defPointerType( + getVectorTypeId(result.type), + spv::StorageClassOutput), + m_ps.builtinSampleMaskOut, + indices.size(), indices.data()); + return result; + } case DxbcOperandType::OutputDepth: case DxbcOperandType::OutputDepthGe: