mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-08-02 22:30:39 +00:00
d3d12: Implement intraframe vertex caching
This commit is contained in:
parent
294d649012
commit
4ee66a2680
3 changed files with 29 additions and 1 deletions
|
@ -264,6 +264,17 @@ ID3D12Resource *createVertexBuffer(const VertexBufferFormat &vbf, const RSXVerte
|
||||||
return vertexBuffer;
|
return vertexBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
isContained(const std::vector<std::pair<u32, u32> > &ranges, const std::pair<u32, u32> &range)
|
||||||
|
{
|
||||||
|
for (auto &r : ranges)
|
||||||
|
{
|
||||||
|
if (r == range)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<std::vector<D3D12_VERTEX_BUFFER_VIEW>, D3D12_INDEX_BUFFER_VIEW> D3D12GSRender::UploadVertexBuffers(bool indexed_draw)
|
std::pair<std::vector<D3D12_VERTEX_BUFFER_VIEW>, D3D12_INDEX_BUFFER_VIEW> D3D12GSRender::UploadVertexBuffers(bool indexed_draw)
|
||||||
{
|
{
|
||||||
std::pair<std::vector<D3D12_VERTEX_BUFFER_VIEW>, D3D12_INDEX_BUFFER_VIEW> result;
|
std::pair<std::vector<D3D12_VERTEX_BUFFER_VIEW>, D3D12_INDEX_BUFFER_VIEW> result;
|
||||||
|
@ -280,7 +291,19 @@ std::pair<std::vector<D3D12_VERTEX_BUFFER_VIEW>, D3D12_INDEX_BUFFER_VIEW> D3D12G
|
||||||
if (vbf.stride)
|
if (vbf.stride)
|
||||||
subBufferSize = ((subBufferSize + vbf.stride - 1) / vbf.stride) * vbf.stride;
|
subBufferSize = ((subBufferSize + vbf.stride - 1) / vbf.stride) * vbf.stride;
|
||||||
|
|
||||||
ID3D12Resource *vertexBuffer = createVertexBuffer(vbf, m_vertex_data, m_device, m_vertexIndexData);
|
u64 key = vbf.range.first;
|
||||||
|
key = key << 32;
|
||||||
|
key = key | vbf.range.second;
|
||||||
|
auto It = m_vertexCache.find(key);
|
||||||
|
|
||||||
|
ID3D12Resource *vertexBuffer;
|
||||||
|
if (It != m_vertexCache.end())
|
||||||
|
vertexBuffer = It->second;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertexBuffer = createVertexBuffer(vbf, m_vertex_data, m_device, m_vertexIndexData);
|
||||||
|
m_vertexCache[key] = vertexBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
D3D12_VERTEX_BUFFER_VIEW vertexBufferView = {};
|
D3D12_VERTEX_BUFFER_VIEW vertexBufferView = {};
|
||||||
vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
|
vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
|
||||||
|
|
|
@ -1057,6 +1057,7 @@ void D3D12GSRender::Flip()
|
||||||
|
|
||||||
// Flush
|
// Flush
|
||||||
m_texturesRTTs.clear();
|
m_texturesRTTs.clear();
|
||||||
|
m_vertexCache.clear();
|
||||||
|
|
||||||
std::vector<std::function<void()> > cleaningFunction =
|
std::vector<std::function<void()> > cleaningFunction =
|
||||||
{
|
{
|
||||||
|
|
|
@ -218,6 +218,10 @@ private:
|
||||||
std::unordered_map<u32, ID3D12Resource*> m_texturesCache;
|
std::unordered_map<u32, ID3D12Resource*> m_texturesCache;
|
||||||
// std::vector<PostDrawObj> m_post_draw_objs;
|
// std::vector<PostDrawObj> m_post_draw_objs;
|
||||||
|
|
||||||
|
// TODO: Use a tree structure to parse more efficiently
|
||||||
|
// Key is begin << 32 | end
|
||||||
|
std::unordered_map<u64, ID3D12Resource *> m_vertexCache;
|
||||||
|
|
||||||
PipelineStateObjectCache m_cachePSO;
|
PipelineStateObjectCache m_cachePSO;
|
||||||
std::pair<ID3D12PipelineState *, size_t> *m_PSO;
|
std::pair<ID3D12PipelineState *, size_t> *m_PSO;
|
||||||
// m_rootSignatures[N] is RS with N texture/sample
|
// m_rootSignatures[N] is RS with N texture/sample
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue