1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-12 13:08:50 +01:00

[d3d9] Unmap stored shader bytecode

This commit is contained in:
Robin Kertels 2022-08-08 14:56:03 +02:00 committed by Joshie
parent 49e9ba2ca7
commit 1fcd5dc0af
3 changed files with 47 additions and 23 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -3,6 +3,7 @@
#include "d3d9_resource.h"
#include "../dxso/dxso_module.h"
#include "d3d9_util.h"
#include "d3d9_mem.h"
#include <array>
@ -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<Base>( 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<uint8_t> 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<IDirect3DVertexShader9>( pDevice, CommonShader, pShaderBytecode, BytecodeLength ) { }
D3D9DeviceEx* pDevice,
D3D9MemoryAllocator* pAllocator,
const D3D9CommonShader& CommonShader,
const void* pShaderBytecode,
uint32_t BytecodeLength)
: D3D9Shader<IDirect3DVertexShader9>( 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<IDirect3DPixelShader9>( pDevice, CommonShader, pShaderBytecode, BytecodeLength ) { }
D3D9DeviceEx* pDevice,
D3D9MemoryAllocator* pAllocator,
const D3D9CommonShader& CommonShader,
const void* pShaderBytecode,
uint32_t BytecodeLength)
: D3D9Shader<IDirect3DPixelShader9>( pDevice, pAllocator, CommonShader, pShaderBytecode, BytecodeLength ) { }
};