diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp index 16555d5425..eaf26a827d 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp @@ -264,7 +264,7 @@ ID3D12Resource *createVertexBuffer(const VertexBufferFormat &vbf, const RSXVerte return vertexBuffer; } -std::pair, D3D12_INDEX_BUFFER_VIEW> D3D12GSRender::EnableVertexData(bool indexed_draw) +std::pair, D3D12_INDEX_BUFFER_VIEW> D3D12GSRender::UploadVertexBuffers(bool indexed_draw) { std::pair, D3D12_INDEX_BUFFER_VIEW> result; const std::vector &vertexBufferFormat = FormatVertexData(m_vertex_data); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 731b9f69ab..902b45de94 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -630,7 +630,7 @@ void D3D12GSRender::ExecCMD(u32 cmd) { assert(cmd == NV4097_CLEAR_SURFACE); - InitDrawBuffers(); + PrepareRenderTargets(); ID3D12GraphicsCommandList *commandList; check(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&commandList))); @@ -710,7 +710,7 @@ void D3D12GSRender::ExecCMD(u32 cmd) void D3D12GSRender::ExecCMD() { - InitDrawBuffers(); + PrepareRenderTargets(); // Init vertex count // TODO: Very hackish, clean this @@ -743,7 +743,7 @@ void D3D12GSRender::ExecCMD() if (m_indexed_array.m_count || m_draw_array_count) { - const std::pair, D3D12_INDEX_BUFFER_VIEW> &vertexIndexBufferViews = EnableVertexData(m_indexed_array.m_count ? true : false); + const std::pair, D3D12_INDEX_BUFFER_VIEW> &vertexIndexBufferViews = UploadVertexBuffers(m_indexed_array.m_count ? true : false); commandList->IASetVertexBuffers(0, (UINT)vertexIndexBufferViews.first.size(), vertexIndexBufferViews.first.data()); if (m_forcedIndexBuffer || m_indexed_array.m_count) commandList->IASetIndexBuffer(&vertexIndexBufferViews.second); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index 891aec7355..7c4ac7ee2f 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -81,6 +81,14 @@ struct InitHeap } }; + +/** + * Wrapper around a ID3D12Resource or a ID3D12Heap. + * Acts as a ring buffer : hold a get and put pointers, + * put pointer is used as storage space offset + * and get is used as beginning of in use data space. + * This wrapper checks that put pointer doesn't cross get one. + */ template struct DataHeap { @@ -154,6 +162,12 @@ struct DataHeap } }; + +/** + * Wrapper for a worker thread that executes lambda functions + * in the order they were submitted during its lifetime. + * Used mostly to release data that are not needed anymore. + */ struct GarbageCollectionThread { std::mutex m_mutex; @@ -192,12 +206,25 @@ private: void Init(ID3D12Device *device); void Release(); }; - + + /** + * Stores data related to the scaling pass that turns internal + * render targets into presented buffers. + */ Shader m_outputScalingPass; + /** + * Data used when depth buffer is converted to uchar textures. + */ ID3D12PipelineState *m_convertPSO; ID3D12RootSignature *m_convertRootSignature; + + /** + * Stores data that are "ping ponged" between frame. + * For instance command allocator : maintains 2 command allocators and + * swap between them when frame is flipped. + */ struct ResourceStorage { ID3D12Fence* m_frameFinishedFence; @@ -296,29 +323,19 @@ private: virtual void Close() override; bool LoadProgram(); - std::pair, D3D12_INDEX_BUFFER_VIEW> EnableVertexData(bool indexed_draw = false); + std::pair, D3D12_INDEX_BUFFER_VIEW> UploadVertexBuffers(bool indexed_draw = false); void setScaleOffset(); void FillVertexShaderConstantsBuffer(); void FillPixelShaderConstantsBuffer(); /** + * Upload textures to Data heap if necessary and create necessary descriptor in the per frame storage struct. * returns the number of texture uploaded */ size_t UploadTextures(); size_t GetMaxAniso(size_t aniso); D3D12_TEXTURE_ADDRESS_MODE GetWrap(size_t wrap); - /*void DisableVertexData(); - - void WriteBuffers(); - void WriteColorBuffers(); - void WriteColorBufferA(); - void WriteColorBufferB(); - void WriteColorBufferC(); - void WriteColorBufferD(); - - void DrawObjects();*/ - void InitDrawBuffers(); - void WriteDepthBuffer(); + void PrepareRenderTargets(); protected: virtual void OnInit() override; virtual void OnInitThread() override; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp index 6bcdfbc56f..5a8d776239 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp @@ -12,7 +12,7 @@ #include "D3D12.h" #include "D3D12GSRender.h" -void D3D12GSRender::InitDrawBuffers() +void D3D12GSRender::PrepareRenderTargets() { // FBO location has changed, previous data might be copied u32 address_a = GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000);