From aa70369671c4f35619178dc6c24a844eb40c65be Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 5 Feb 2020 17:07:08 +0100 Subject: [PATCH] [d3d9] Store copy of shader metadata in constant set Reduces pointer chasing when updating shader constants. --- src/d3d9/d3d9_constant_set.h | 2 +- src/d3d9/d3d9_device.cpp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/d3d9/d3d9_constant_set.h b/src/d3d9/d3d9_constant_set.h index c65c1825f..16b4e7e98 100644 --- a/src/d3d9/d3d9_constant_set.h +++ b/src/d3d9/d3d9_constant_set.h @@ -40,7 +40,7 @@ namespace dxvk { struct D3D9ConstantSets { Rc buffer; - const DxsoShaderMetaInfo* meta = nullptr; + DxsoShaderMetaInfo meta = {}; bool dirty = true; }; diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index fa6a66fad..8acb57089 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -2644,7 +2644,7 @@ namespace dxvk { bool newCopies = newShader && newShader->GetMeta().needsConstantCopies; m_consts[DxsoProgramTypes::VertexShader].dirty |= oldCopies || newCopies || !oldShader; - m_consts[DxsoProgramTypes::VertexShader].meta = newShader ? &newShader->GetMeta() : nullptr; + m_consts[DxsoProgramTypes::VertexShader].meta = newShader ? newShader->GetMeta() : DxsoShaderMetaInfo(); if (newShader && oldShader) { m_consts[DxsoProgramTypes::VertexShader].dirty @@ -2970,7 +2970,7 @@ namespace dxvk { bool newCopies = newShader && newShader->GetMeta().needsConstantCopies; m_consts[DxsoProgramTypes::PixelShader].dirty |= oldCopies || newCopies || !oldShader; - m_consts[DxsoProgramTypes::PixelShader].meta = newShader ? &newShader->GetMeta() : nullptr; + m_consts[DxsoProgramTypes::PixelShader].meta = newShader ? newShader->GetMeta() : DxsoShaderMetaInfo(); if (newShader && oldShader) { m_consts[DxsoProgramTypes::PixelShader].dirty @@ -4461,10 +4461,10 @@ namespace dxvk { auto* dst = reinterpret_cast(pData); - if (constSet.meta->maxConstIndexF) - std::memcpy(dst->fConsts, Src.fConsts, constSet.meta->maxConstIndexF * sizeof(Vector4)); - if (constSet.meta->maxConstIndexI) - std::memcpy(dst->iConsts, Src.iConsts, constSet.meta->maxConstIndexI * sizeof(Vector4i)); + if (constSet.meta.maxConstIndexF) + std::memcpy(dst->fConsts, Src.fConsts, constSet.meta.maxConstIndexF * sizeof(Vector4)); + if (constSet.meta.maxConstIndexI) + std::memcpy(dst->iConsts, Src.iConsts, constSet.meta.maxConstIndexI * sizeof(Vector4i)); } @@ -4474,11 +4474,11 @@ namespace dxvk { auto dst = reinterpret_cast(pData); - if (constSet.meta->maxConstIndexF) - std::memcpy(dst + Layout.floatOffset(), Src.fConsts, constSet.meta->maxConstIndexF * sizeof(Vector4)); - if (constSet.meta->maxConstIndexI) - std::memcpy(dst + Layout.intOffset(), Src.iConsts, constSet.meta->maxConstIndexI * sizeof(Vector4i)); - if (constSet.meta->maxConstIndexB) + if (constSet.meta.maxConstIndexF) + std::memcpy(dst + Layout.floatOffset(), Src.fConsts, constSet.meta.maxConstIndexF * sizeof(Vector4)); + if (constSet.meta.maxConstIndexI) + std::memcpy(dst + Layout.intOffset(), Src.iConsts, constSet.meta.maxConstIndexI * sizeof(Vector4i)); + if (constSet.meta.maxConstIndexB) std::memcpy(dst + Layout.bitmaskOffset(), Src.bConsts, Layout.bitmaskSize()); } @@ -4508,7 +4508,7 @@ namespace dxvk { else UploadSoftwareConstantSet(slice.mapPtr, Src, Layout, Shader); - if (constSet.meta->needsConstantCopies) { + if (constSet.meta.needsConstantCopies) { Vector4* data = reinterpret_cast(slice.mapPtr); auto& shaderConsts = GetCommonShader(Shader)->GetConstants(); @@ -5448,7 +5448,7 @@ namespace dxvk { if (likely(!CanSWVP())) { UpdateBoolSpecConstantVertex( m_state.vsConsts.bConsts[0] & - GetCommonShader(m_state.vertexShader)->GetMeta().boolConstantMask); + m_consts[DxsoProgramType::VertexShader].meta.boolConstantMask); } else UpdateBoolSpecConstantVertex(0); } @@ -5478,7 +5478,7 @@ namespace dxvk { UpdateBoolSpecConstantPixel( m_state.psConsts.bConsts[0] & - GetCommonShader(m_state.pixelShader)->GetMeta().boolConstantMask); + m_consts[DxsoProgramType::PixelShader].meta.boolConstantMask); } else { UpdateBoolSpecConstantPixel(0);