d3d12: Avoid copying 8k of constant data per draw call

This commit is contained in:
vlj 2015-06-25 18:19:14 +02:00 committed by Vincent Lejeune
parent d88d078f4a
commit 8f31211557
3 changed files with 14 additions and 7 deletions

View File

@ -473,8 +473,7 @@ void D3D12GSRender::FillVertexShaderConstantsBuffer()
for (const RSXTransformConstant& c : m_transform_constants) for (const RSXTransformConstant& c : m_transform_constants)
{ {
size_t offset = c.id * 4 * sizeof(float); size_t offset = c.id * 4 * sizeof(float);
float vector[] = { c.x, c.y, c.z, c.w }; m_vertexConstants[offset] = c;
memcpy((char*)vertexConstantShadowCopy + offset, vector, 4 * sizeof(float));
} }
size_t bufferSize = 512 * 4 * sizeof(float); size_t bufferSize = 512 * 4 * sizeof(float);
@ -486,7 +485,16 @@ void D3D12GSRender::FillVertexShaderConstantsBuffer()
void *constantsBufferMap; void *constantsBufferMap;
check(m_constantsData.m_heap->Map(0, &range, &constantsBufferMap)); check(m_constantsData.m_heap->Map(0, &range, &constantsBufferMap));
streamBuffer((char*)constantsBufferMap + heapOffset, vertexConstantShadowCopy, bufferSize); for (auto vertexConstants : m_vertexConstants)
{
float data[4] = {
vertexConstants.second.x,
vertexConstants.second.y,
vertexConstants.second.z,
vertexConstants.second.w
};
memcpy((char*)constantsBufferMap + heapOffset + vertexConstants.first, data, 4 * sizeof(float));
}
m_constantsData.m_heap->Unmap(0, &range); m_constantsData.m_heap->Unmap(0, &range);
D3D12_CONSTANT_BUFFER_VIEW_DESC constantBufferViewDesc = {}; D3D12_CONSTANT_BUFFER_VIEW_DESC constantBufferViewDesc = {};

View File

@ -545,8 +545,6 @@ D3D12GSRender::D3D12GSRender()
m_perFrameStorage[1].Init(m_device); m_perFrameStorage[1].Init(m_device);
m_perFrameStorage[1].Reset(); m_perFrameStorage[1].Reset();
vertexConstantShadowCopy = new float[512 * 4];
// Convert shader // Convert shader
auto p = compileF32toU8CS(); auto p = compileF32toU8CS();
check( check(
@ -620,7 +618,6 @@ D3D12GSRender::~D3D12GSRender()
m_swapChain->Release(); m_swapChain->Release();
m_outputScalingPass.Release(); m_outputScalingPass.Release();
m_device->Release(); m_device->Release();
delete[] vertexConstantShadowCopy;
unloadD3D12FunctionPointers(); unloadD3D12FunctionPointers();
} }
@ -1058,6 +1055,7 @@ void D3D12GSRender::Flip()
// Flush // Flush
m_texturesRTTs.clear(); m_texturesRTTs.clear();
m_vertexCache.clear(); m_vertexCache.clear();
m_vertexConstants.clear();
std::vector<std::function<void()> > cleaningFunction = std::vector<std::function<void()> > cleaningFunction =
{ {

View File

@ -333,7 +333,8 @@ public:
GSFrameBase2 *m_frame; GSFrameBase2 *m_frame;
u32 m_draw_frames; u32 m_draw_frames;
u32 m_skip_frames; u32 m_skip_frames;
float *vertexConstantShadowCopy;
std::unordered_map<size_t, RSXTransformConstant> m_vertexConstants;
D3D12GSRender(); D3D12GSRender();
virtual ~D3D12GSRender(); virtual ~D3D12GSRender();