d3d12: Use another sampler heap when using more than 2048 samplers

This commit is contained in:
vlj 2015-07-01 22:52:32 +02:00 committed by Vincent Lejeune
parent d2edeafffe
commit 38a809b483
3 changed files with 22 additions and 9 deletions

View file

@ -78,6 +78,8 @@ void D3D12GSRender::ResourceStorage::Reset()
m_currentTextureIndex = 0; m_currentTextureIndex = 0;
m_frameFinishedFence = nullptr; m_frameFinishedFence = nullptr;
m_frameFinishedHandle = 0; m_frameFinishedHandle = 0;
m_currentSamplerIndex = 0;
m_samplerDescriptorHeapIndex = 0;
m_commandAllocator->Reset(); m_commandAllocator->Reset();
m_textureUploadCommandAllocator->Reset(); m_textureUploadCommandAllocator->Reset();
@ -117,7 +119,8 @@ void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device)
textureDescriptorDesc.NumDescriptors = 2048; // For safety textureDescriptorDesc.NumDescriptors = 2048; // For safety
textureDescriptorDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; 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() void D3D12GSRender::ResourceStorage::Release()
@ -126,7 +129,8 @@ void D3D12GSRender::ResourceStorage::Release()
m_constantsBufferDescriptorsHeap->Release(); m_constantsBufferDescriptorsHeap->Release();
m_scaleOffsetDescriptorHeap->Release(); m_scaleOffsetDescriptorHeap->Release();
m_textureDescriptorsHeap->Release(); m_textureDescriptorsHeap->Release();
m_samplerDescriptorHeap->Release(); m_samplerDescriptorHeap[0]->Release();
m_samplerDescriptorHeap[1]->Release();
for (auto &tmp : m_inflightCommandList) for (auto &tmp : m_inflightCommandList)
tmp->Release(); tmp->Release();
m_commandAllocator->Release(); m_commandAllocator->Release();
@ -578,8 +582,8 @@ void D3D12GSRender::ExecCMD()
samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
m_device->CreateSampler(&samplerDesc, m_device->CreateSampler(&samplerDesc,
getCPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap, getCPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex],
(getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * g_descriptorStrideSamplers) (getCurrentResourceStorage().m_currentSamplerIndex + usedTexture) * g_descriptorStrideSamplers)
); );
} }
@ -589,13 +593,14 @@ void D3D12GSRender::ExecCMD()
getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSRVCBVUAV) getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSRVCBVUAV)
); );
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_samplerDescriptorHeap); commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]);
commandList->SetGraphicsRootDescriptorTable(3, commandList->SetGraphicsRootDescriptorTable(3,
getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap, getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex],
getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSamplers) getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSamplers)
); );
getCurrentResourceStorage().m_currentTextureIndex += usedTexture; getCurrentResourceStorage().m_currentTextureIndex += usedTexture;
getCurrentResourceStorage().m_currentSamplerIndex += usedTexture;
std::chrono::time_point<std::chrono::system_clock> endTextureTime = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> endTextureTime = std::chrono::system_clock::now();
m_timers.m_textureUploadDuration += std::chrono::duration_cast<std::chrono::microseconds>(endTextureTime - startTextureTime).count(); m_timers.m_textureUploadDuration += std::chrono::duration_cast<std::chrono::microseconds>(endTextureTime - startTextureTime).count();
} }

View file

@ -310,7 +310,9 @@ private:
// Texture storage // Texture storage
ID3D12CommandAllocator *m_textureUploadCommandAllocator; ID3D12CommandAllocator *m_textureUploadCommandAllocator;
ID3D12DescriptorHeap *m_textureDescriptorsHeap; ID3D12DescriptorHeap *m_textureDescriptorsHeap;
ID3D12DescriptorHeap *m_samplerDescriptorHeap; ID3D12DescriptorHeap *m_samplerDescriptorHeap[2];
size_t m_samplerDescriptorHeapIndex;
size_t m_currentSamplerIndex;
size_t m_currentTextureIndex; size_t m_currentTextureIndex;
ID3D12Resource *m_RAMFramebuffer; ID3D12Resource *m_RAMFramebuffer;

View file

@ -876,13 +876,19 @@ size_t D3D12GSRender::UploadTextures()
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
break; break;
} }
D3D12_CPU_DESCRIPTOR_HANDLE Handle = getCurrentResourceStorage().m_textureDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(); 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); Handle.ptr += (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
m_device->CreateShaderResourceView(vramTexture, &srvDesc, Handle); 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 = getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex]->GetCPUDescriptorHandleForHeapStart();
Handle.ptr += (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); Handle.ptr += (getCurrentResourceStorage().m_currentSamplerIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
m_device->CreateSampler(&getSamplerDesc(m_textures[i]), Handle); m_device->CreateSampler(&getSamplerDesc(m_textures[i]), Handle);
usedTexture++; usedTexture++;