diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 43d4b1436d..4ed9c4135a 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -78,6 +78,8 @@ void D3D12GSRender::ResourceStorage::Reset() m_currentTextureIndex = 0; m_frameFinishedFence = nullptr; m_frameFinishedHandle = 0; + m_currentSamplerIndex = 0; + m_samplerDescriptorHeapIndex = 0; m_commandAllocator->Reset(); m_textureUploadCommandAllocator->Reset(); @@ -117,7 +119,8 @@ void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device) textureDescriptorDesc.NumDescriptors = 2048; // For safety textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; - check(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap))); + check(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[0]))); + check(device->CreateDescriptorHeap(&textureDescriptorDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap[1]))); } void D3D12GSRender::ResourceStorage::Release() @@ -126,7 +129,8 @@ void D3D12GSRender::ResourceStorage::Release() m_constantsBufferDescriptorsHeap->Release(); m_scaleOffsetDescriptorHeap->Release(); m_textureDescriptorsHeap->Release(); - m_samplerDescriptorHeap->Release(); + m_samplerDescriptorHeap[0]->Release(); + m_samplerDescriptorHeap[1]->Release(); for (auto &tmp : m_inflightCommandList) tmp->Release(); m_commandAllocator->Release(); @@ -578,8 +582,8 @@ void D3D12GSRender::ExecCMD() samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; m_device->CreateSampler(&samplerDesc, - getCPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap, - (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * g_descriptorStrideSamplers) + getCPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex], + (getCurrentResourceStorage().m_currentSamplerIndex + usedTexture) * g_descriptorStrideSamplers) ); } @@ -589,13 +593,14 @@ void D3D12GSRender::ExecCMD() getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSRVCBVUAV) ); - commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_samplerDescriptorHeap); + commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]); commandList->SetGraphicsRootDescriptorTable(3, - getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap, + getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex], getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSamplers) ); getCurrentResourceStorage().m_currentTextureIndex += usedTexture; + getCurrentResourceStorage().m_currentSamplerIndex += usedTexture; std::chrono::time_point endTextureTime = std::chrono::system_clock::now(); m_timers.m_textureUploadDuration += std::chrono::duration_cast(endTextureTime - startTextureTime).count(); } diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index d3012c58ab..33615fd472 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -310,7 +310,9 @@ private: // Texture storage ID3D12CommandAllocator *m_textureUploadCommandAllocator; ID3D12DescriptorHeap *m_textureDescriptorsHeap; - ID3D12DescriptorHeap *m_samplerDescriptorHeap; + ID3D12DescriptorHeap *m_samplerDescriptorHeap[2]; + size_t m_samplerDescriptorHeapIndex; + size_t m_currentSamplerIndex; size_t m_currentTextureIndex; ID3D12Resource *m_RAMFramebuffer; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp index 53f2952b79..b52a0d174a 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp @@ -876,13 +876,19 @@ size_t D3D12GSRender::UploadTextures() srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; break; } + D3D12_CPU_DESCRIPTOR_HANDLE Handle = getCurrentResourceStorage().m_textureDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(); Handle.ptr += (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); m_device->CreateShaderResourceView(vramTexture, &srvDesc, Handle); + if (getCurrentResourceStorage().m_currentSamplerIndex + 16 > 2048) + { + getCurrentResourceStorage().m_samplerDescriptorHeapIndex = 1; + getCurrentResourceStorage().m_currentSamplerIndex = 0; + } - Handle = getCurrentResourceStorage().m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); - Handle.ptr += (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + Handle = getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart(); + Handle.ptr += (getCurrentResourceStorage().m_currentSamplerIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); m_device->CreateSampler(&getSamplerDesc(m_textures[i]), Handle); usedTexture++;