From 538b55921ecea72ef861d2b5da72ac20b109d2be Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 24 Nov 2020 18:39:20 +0100 Subject: [PATCH] [dxbc] Conditionally return zeroes for unbound textures in shader May allow the driver to optimize away texture operations. --- src/dxbc/dxbc_compiler.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp index 6c84ee2dd..8e89dabbd 100644 --- a/src/dxbc/dxbc_compiler.cpp +++ b/src/dxbc/dxbc_compiler.cpp @@ -3543,6 +3543,14 @@ namespace dxvk { result = emitRegisterSwizzle(result, textureReg.swizzle, ins.dst[0].mask); + DxbcRegisterValue bound; + bound.type = { DxbcScalarType::Bool, 1 }; + bound.id = m_textures.at(textureId).specId; + + result.id = m_module.opSelect(getVectorTypeId(result.type), + emitBuildVector(bound, result.type.ccount).id, result.id, + emitBuildZeroVector(result.type).id); + emitRegisterStore(ins.dst[0], result); } @@ -3695,6 +3703,14 @@ namespace dxvk { textureReg.swizzle, ins.dst[0].mask); } + DxbcRegisterValue bound; + bound.type = { DxbcScalarType::Bool, 1 }; + bound.id = m_textures.at(textureId).specId; + + result.id = m_module.opSelect(getVectorTypeId(result.type), + emitBuildVector(bound, result.type.ccount).id, result.id, + emitBuildZeroVector(result.type).id); + emitRegisterStore(ins.dst[0], result); }