From 1fcd5dc0af61914ff08cdab7e05050bf47c948b5 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Mon, 8 Aug 2022 14:56:03 +0200 Subject: [PATCH] [d3d9] Unmap stored shader bytecode --- src/d3d9/d3d9_device.cpp | 13 ++++++++-- src/d3d9/d3d9_device.h | 5 ++++ src/d3d9/d3d9_shader.h | 52 ++++++++++++++++++++++++---------------- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 50741571..99fb0e1b 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -47,6 +47,7 @@ namespace dxvk { , m_adapter ( pAdapter ) , m_dxvkDevice ( dxvkDevice ) , m_memoryAllocator ( ) + , m_shaderAllocator ( ) , m_shaderModules ( new D3D9ShaderModuleSet ) , m_stagingBuffer ( dxvkDevice, StagingBufferSize ) , m_d3d9Options ( dxvkDevice, pParent->GetInstance()->config() ) @@ -2829,7 +2830,11 @@ namespace dxvk { &moduleInfo))) return D3DERR_INVALIDCALL; - *ppShader = ref(new D3D9VertexShader(this, module, pFunction, bytecodeLength)); + *ppShader = ref(new D3D9VertexShader(this, + &m_shaderAllocator, + module, + pFunction, + bytecodeLength)); return D3D_OK; } @@ -3160,7 +3165,11 @@ namespace dxvk { &moduleInfo))) return D3DERR_INVALIDCALL; - *ppShader = ref(new D3D9PixelShader(this, module, pFunction, bytecodeLength)); + *ppShader = ref(new D3D9PixelShader(this, + &m_shaderAllocator, + module, + pFunction, + bytecodeLength)); return D3D_OK; } diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 40dcc955..0df0496f 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -1158,6 +1158,11 @@ namespace dxvk { D3D9MemoryAllocator m_memoryAllocator; + // Second memory allocator used for D3D9 shader bytecode. + // Most games never access the stored bytecode, so putting that + // into the same chunks as texture memory would waste address space. + D3D9MemoryAllocator m_shaderAllocator; + uint32_t m_frameLatency = DefaultFrameLatency; D3D9Initializer* m_initializer = nullptr; diff --git a/src/d3d9/d3d9_shader.h b/src/d3d9/d3d9_shader.h index c8705711..997d1525 100644 --- a/src/d3d9/d3d9_shader.h +++ b/src/d3d9/d3d9_shader.h @@ -3,6 +3,7 @@ #include "d3d9_resource.h" #include "../dxso/dxso_module.h" #include "d3d9_util.h" +#include "d3d9_mem.h" #include @@ -81,15 +82,19 @@ namespace dxvk { public: D3D9Shader( - D3D9DeviceEx* pDevice, - const D3D9CommonShader& CommonShader, - const void* pShaderBytecode, - uint32_t BytecodeLength) + D3D9DeviceEx* pDevice, + D3D9MemoryAllocator* pAllocator, + const D3D9CommonShader& CommonShader, + const void* pShaderBytecode, + uint32_t BytecodeLength) : D3D9DeviceChild( pDevice ) - , m_shader ( CommonShader ) { + , m_shader ( CommonShader ) + , m_bytecodeLength ( BytecodeLength ) { - m_bytecode.resize(BytecodeLength); - std::memcpy(m_bytecode.data(), pShaderBytecode, BytecodeLength); + m_bytecode = pAllocator->Alloc(BytecodeLength); + m_bytecode.Map(); + std::memcpy(m_bytecode.Ptr(), pShaderBytecode, BytecodeLength); + m_bytecode.Unmap(); } HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) { @@ -114,12 +119,14 @@ namespace dxvk { return D3DERR_INVALIDCALL; if (pOut == nullptr) { - *pSizeOfData = m_bytecode.size(); + *pSizeOfData = m_bytecodeLength; return D3D_OK; } - size_t copyAmount = std::min(size_t(*pSizeOfData), m_bytecode.size()); - std::memcpy(pOut, m_bytecode.data(), copyAmount); + m_bytecode.Map(); + uint32_t copyAmount = std::min(*pSizeOfData, m_bytecodeLength); + std::memcpy(pOut, m_bytecode.Ptr(), copyAmount); + m_bytecode.Unmap(); return D3D_OK; } @@ -132,7 +139,8 @@ namespace dxvk { D3D9CommonShader m_shader; - std::vector m_bytecode; + D3D9Memory m_bytecode; + uint32_t m_bytecodeLength; }; @@ -143,11 +151,12 @@ namespace dxvk { public: D3D9VertexShader( - D3D9DeviceEx* pDevice, - const D3D9CommonShader& CommonShader, - const void* pShaderBytecode, - uint32_t BytecodeLength) - : D3D9Shader( pDevice, CommonShader, pShaderBytecode, BytecodeLength ) { } + D3D9DeviceEx* pDevice, + D3D9MemoryAllocator* pAllocator, + const D3D9CommonShader& CommonShader, + const void* pShaderBytecode, + uint32_t BytecodeLength) + : D3D9Shader( pDevice, pAllocator, CommonShader, pShaderBytecode, BytecodeLength ) { } }; @@ -156,11 +165,12 @@ namespace dxvk { public: D3D9PixelShader( - D3D9DeviceEx* pDevice, - const D3D9CommonShader& CommonShader, - const void* pShaderBytecode, - uint32_t BytecodeLength) - : D3D9Shader( pDevice, CommonShader, pShaderBytecode, BytecodeLength ) { } + D3D9DeviceEx* pDevice, + D3D9MemoryAllocator* pAllocator, + const D3D9CommonShader& CommonShader, + const void* pShaderBytecode, + uint32_t BytecodeLength) + : D3D9Shader( pDevice, pAllocator, CommonShader, pShaderBytecode, BytecodeLength ) { } };