From 65f4437417b2570395adcfe872fcfbe50fd11473 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 26 Jan 2020 18:40:32 +0000 Subject: [PATCH] [dxso] Initialize vPos value at the start of the shader Otherwise we can end up initializing it in a branch and that's no good. Closes https://github.com/doitsujin/dxvk/issues/1294 --- src/dxso/dxso_compiler.cpp | 53 +++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/dxso/dxso_compiler.cpp b/src/dxso/dxso_compiler.cpp index 9af7806a9..4acc3b637 100644 --- a/src/dxso/dxso_compiler.cpp +++ b/src/dxso/dxso_compiler.cpp @@ -1188,39 +1188,15 @@ namespace dxvk { case DxsoRegisterType::MiscType: if (reg.id.num == MiscTypePosition) { if (m_ps.vPos.id == 0) { - DxsoRegisterPointer fragCoord = this->emitRegisterPtr( - "ps_frag_coord", DxsoScalarType::Float32, 4, 0, - spv::StorageClassInput, spv::BuiltInFragCoord); - - DxsoRegisterValue val = this->emitValueLoad(fragCoord); - val.id = m_module.opFSub( - getVectorTypeId(val.type), val.id, - m_module.constvec4f32(0.5f, 0.5f, 0.0f, 0.0f)); - m_ps.vPos = this->emitRegisterPtr( "vPos", DxsoScalarType::Float32, 4, 0); - - m_module.opStore(m_ps.vPos.id, val.id); } return m_ps.vPos; } else { // MiscTypeFace if (m_ps.vFace.id == 0) { - DxsoRegisterPointer faceBool = this->emitRegisterPtr( - "ps_is_front_face", DxsoScalarType::Bool, 1, 0, - spv::StorageClassInput, spv::BuiltInFrontFacing); - - DxsoRegisterValue frontFace = emitValueLoad(faceBool); - DxsoRegisterValue selectOp = emitRegisterExtend(frontFace, 4); - m_ps.vFace = this->emitRegisterPtr( "vFace", DxsoScalarType::Float32, 4, 0); - - m_module.opStore( - m_ps.vFace.id, - m_module.opSelect(getVectorTypeId(m_ps.vFace.type), selectOp.id, - m_module.constvec4f32( 1.0f, 1.0f, 1.0f, 1.0f), - m_module.constvec4f32(-1.0f, -1.0f, -1.0f, -1.0f))); } return m_ps.vFace; } @@ -3533,6 +3509,35 @@ void DxsoCompiler::emitControlFlowGenericLoop( this->emitMainFunctionBegin(); this->emitInputSetup(); + + if (m_ps.vPos.id != 0) { + DxsoRegisterPointer fragCoord = this->emitRegisterPtr( + "ps_frag_coord", DxsoScalarType::Float32, 4, 0, + spv::StorageClassInput, spv::BuiltInFragCoord); + + DxsoRegisterValue val = this->emitValueLoad(fragCoord); + val.id = m_module.opFSub( + getVectorTypeId(val.type), val.id, + m_module.constvec4f32(0.5f, 0.5f, 0.0f, 0.0f)); + + m_module.opStore(m_ps.vPos.id, val.id); + } + + if (m_ps.vFace.id != 0) { + DxsoRegisterPointer faceBool = this->emitRegisterPtr( + "ps_is_front_face", DxsoScalarType::Bool, 1, 0, + spv::StorageClassInput, spv::BuiltInFrontFacing); + + DxsoRegisterValue frontFace = emitValueLoad(faceBool); + DxsoRegisterValue selectOp = emitRegisterExtend(frontFace, 4); + + m_module.opStore( + m_ps.vFace.id, + m_module.opSelect(getVectorTypeId(m_ps.vFace.type), selectOp.id, + m_module.constvec4f32( 1.0f, 1.0f, 1.0f, 1.0f), + m_module.constvec4f32(-1.0f, -1.0f, -1.0f, -1.0f))); + } + m_module.opFunctionCall( m_module.defVoidType(), m_ps.functionId, 0, nullptr);