diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 78ed326847..8d800950d8 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -278,7 +278,7 @@ D3D12GSRender::D3D12GSRender() m_constantsData.Init(m_device.Get(), 1024 * 1024 * 64, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE); m_vertexIndexData.Init(m_device.Get(), 1024 * 1024 * 384, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE); - m_textureUploadData.Init(m_device.Get(), 1024 * 1024 * 256, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS); + m_textureUploadData.Init(m_device.Get(), 1024 * 1024 * 256, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE); if (Ini.GSOverlay.GetValue()) InitD2DStructures(); @@ -705,7 +705,7 @@ void D3D12GSRender::Flip() size_t w = 0, h = 0, rowPitch = 0; - ID3D12Resource *stagingTexture; + size_t offset = 0; if (m_read_buffer) { CellGcmDisplayInfo* buffers = vm::get_ptr(m_gcm_buffers_addr); @@ -719,21 +719,13 @@ void D3D12GSRender::Flip() assert(m_textureUploadData.canAlloc(textureSize)); size_t heapOffset = m_textureUploadData.alloc(textureSize); - ThrowIfFailed(m_device->CreatePlacedResource( - m_textureUploadData.m_heap, - heapOffset, - &CD3DX12_RESOURCE_DESC::Buffer(textureSize), - D3D12_RESOURCE_STATE_GENERIC_READ, - nullptr, - IID_PPV_ARGS(&stagingTexture) - )); - getCurrentResourceStorage().m_singleFrameLifetimeResources.push_back(stagingTexture); - - void *dstBuffer; - ThrowIfFailed(stagingTexture->Map(0, nullptr, &dstBuffer)); + void *buffer; + ThrowIfFailed(m_textureUploadData.m_heap->Map(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize), &buffer)); + void *dstBuffer = (char*)buffer + heapOffset; for (unsigned row = 0; row < h; row++) memcpy((char*)dstBuffer + row * rowPitch, (char*)src_buffer + row * w * 4, w * 4); - stagingTexture->Unmap(0, nullptr); + m_textureUploadData.m_heap->Unmap(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize)); + offset = heapOffset; } ThrowIfFailed( @@ -747,7 +739,7 @@ void D3D12GSRender::Flip() ) ); getCurrentResourceStorage().m_commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(storage.m_RAMFramebuffer.Get(), 0), 0, 0, 0, - &CD3DX12_TEXTURE_COPY_LOCATION(stagingTexture, { 0, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)rowPitch} }), nullptr); + &CD3DX12_TEXTURE_COPY_LOCATION(m_textureUploadData.m_heap, { offset, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)rowPitch} }), nullptr); getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(storage.m_RAMFramebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ)); resourceToFlip = storage.m_RAMFramebuffer.Get(); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index ca12d0618b..b7c926ab6a 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -334,7 +334,7 @@ private: // Vertex storage DataHeap m_vertexIndexData; // Texture storage - DataHeap m_textureUploadData; + DataHeap m_textureUploadData; DataHeap m_UAVHeap; DataHeap m_readbackResources; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp index 219b9b2248..f17b53f240 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp @@ -394,8 +394,7 @@ ID3D12Resource *uploadSingleTexture( const RSXTexture &texture, ID3D12Device *device, ID3D12GraphicsCommandList *commandList, - DataHeap &textureBuffersHeap, - std::vector > &stagingRamTexture) + DataHeap &textureBuffersHeap) { ID3D12Resource *vramTexture; size_t w = texture.GetWidth(), h = texture.GetHeight(); @@ -550,24 +549,14 @@ ID3D12Resource *uploadSingleTexture( // Multiple of 256 size_t rowPitch = align(blockSizeInByte * widthInBlocks, 256); - ComPtr Texture; size_t textureSize = rowPitch * heightInBlocks * 2; // * 4 for mipmap levels assert(textureBuffersHeap.canAlloc(textureSize)); size_t heapOffset = textureBuffersHeap.alloc(textureSize); - ThrowIfFailed(device->CreatePlacedResource( - textureBuffersHeap.m_heap, - heapOffset, - &CD3DX12_RESOURCE_DESC::Buffer(textureSize), - D3D12_RESOURCE_STATE_GENERIC_READ, - nullptr, - IID_PPV_ARGS(Texture.GetAddressOf()) - )); - stagingRamTexture.push_back(Texture); - auto pixels = vm::get_ptr(texaddr); - void *textureData; - ThrowIfFailed(Texture->Map(0, nullptr, (void**)&textureData)); + void *buffer; + ThrowIfFailed(textureBuffersHeap.m_heap->Map(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize), &buffer)); + void *textureData = (char*)buffer + heapOffset; std::vector mipInfos; switch (format) @@ -608,7 +597,7 @@ ID3D12Resource *uploadSingleTexture( break; } } - Texture->Unmap(0, nullptr); + textureBuffersHeap.m_heap->Unmap(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize)); D3D12_RESOURCE_DESC texturedesc = CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)w, (UINT)h, 1, texture.GetMipmap()); textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes; @@ -626,7 +615,7 @@ ID3D12Resource *uploadSingleTexture( for (const MipmapLevelInfo mli : mipInfos) { commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(vramTexture, (UINT)miplevel), 0, 0, 0, - &CD3DX12_TEXTURE_COPY_LOCATION(Texture.Get(), { mli.offset, { dxgiFormat, (UINT)mli.width, (UINT)mli.height, 1, (UINT)mli.rowPitch } }), nullptr); + &CD3DX12_TEXTURE_COPY_LOCATION(textureBuffersHeap.m_heap, { heapOffset + mli.offset, { dxgiFormat, (UINT)mli.width, (UINT)mli.height, 1, (UINT)mli.rowPitch } }), nullptr); miplevel++; } @@ -738,7 +727,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) } else { - vramTexture = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData, getCurrentResourceStorage().m_singleFrameLifetimeResources); + vramTexture = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData); m_texturesCache[texaddr] = vramTexture; u32 s = (u32)align(getTextureSize(m_textures[i]), 4096);