mirror of https://github.com/RPCS3/rpcs3.git
d3d12: Try to factorise CPU/GPU descriptor handle gen
I'm still not satisfied with it but I didn't find another way to make it compact and readable.
This commit is contained in:
parent
1c7bff4d36
commit
d4b83bcf6f
|
@ -288,4 +288,20 @@ inline DXGI_FORMAT getTextureDXGIFormat(int format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE getCPUDescriptorHandle(ID3D12DescriptorHeap *descriptors, size_t offset)
|
||||||
|
{
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE result = descriptors->GetCPUDescriptorHandleForHeapStart();
|
||||||
|
result.ptr += offset;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
D3D12_GPU_DESCRIPTOR_HANDLE getGPUDescriptorHandle(ID3D12DescriptorHeap *descriptors, size_t offset)
|
||||||
|
{
|
||||||
|
D3D12_GPU_DESCRIPTOR_HANDLE result = descriptors->GetGPUDescriptorHandleForHeapStart();
|
||||||
|
result.ptr += offset;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -456,6 +456,11 @@ D3D12GSRender::D3D12GSRender()
|
||||||
check(m_device->CreateCommandQueue(©QueueDesc, IID_PPV_ARGS(&m_commandQueueCopy)));
|
check(m_device->CreateCommandQueue(©QueueDesc, IID_PPV_ARGS(&m_commandQueueCopy)));
|
||||||
check(m_device->CreateCommandQueue(&graphicQueueDesc, IID_PPV_ARGS(&m_commandQueueGraphic)));
|
check(m_device->CreateCommandQueue(&graphicQueueDesc, IID_PPV_ARGS(&m_commandQueueGraphic)));
|
||||||
|
|
||||||
|
g_descriptorStrideSRVCBVUAV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||||
|
size_t g_descriptorStrideDSV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
|
||||||
|
size_t g_descriptorStrideRTV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||||
|
size_t g_descriptorStrideSamplers = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||||
|
|
||||||
m_frame = GetGSFrame();
|
m_frame = GetGSFrame();
|
||||||
DXGI_ADAPTER_DESC adaptaterDesc;
|
DXGI_ADAPTER_DESC adaptaterDesc;
|
||||||
adaptater->GetDesc(&adaptaterDesc);
|
adaptater->GetDesc(&adaptaterDesc);
|
||||||
|
@ -692,28 +697,26 @@ void D3D12GSRender::ExecCMD(u32 cmd)
|
||||||
|
|
||||||
case CELL_GCM_SURFACE_TARGET_0:
|
case CELL_GCM_SURFACE_TARGET_0:
|
||||||
case CELL_GCM_SURFACE_TARGET_1:
|
case CELL_GCM_SURFACE_TARGET_1:
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||||
break;
|
break;
|
||||||
case CELL_GCM_SURFACE_TARGET_MRT1:
|
case CELL_GCM_SURFACE_TARGET_MRT1:
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||||
handle.ptr += g_RTTIncrement;
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
|
||||||
break;
|
break;
|
||||||
case CELL_GCM_SURFACE_TARGET_MRT2:
|
case CELL_GCM_SURFACE_TARGET_MRT2:
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||||
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||||
handle.ptr += g_RTTIncrement;
|
handle.ptr += g_RTTIncrement;
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||||
handle.ptr += g_RTTIncrement;
|
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
|
||||||
break;
|
break;
|
||||||
case CELL_GCM_SURFACE_TARGET_MRT3:
|
case CELL_GCM_SURFACE_TARGET_MRT3:
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr);
|
||||||
handle.ptr += g_RTTIncrement;
|
handle.ptr += g_RTTIncrement;
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||||
handle.ptr += g_RTTIncrement;
|
handle.ptr += g_RTTIncrement;
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||||
handle.ptr += g_RTTIncrement;
|
handle.ptr += g_RTTIncrement;
|
||||||
commandList->ClearRenderTargetView(handle, clearColor, 0, nullptr);
|
commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 3 * g_descriptorStrideRTV), clearColor, 0, nullptr);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target);
|
LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target);
|
||||||
|
@ -782,9 +785,10 @@ void D3D12GSRender::ExecCMD()
|
||||||
// Constants
|
// Constants
|
||||||
setScaleOffset();
|
setScaleOffset();
|
||||||
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_scaleOffsetDescriptorHeap);
|
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_scaleOffsetDescriptorHeap);
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE Handle = getCurrentResourceStorage().m_scaleOffsetDescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
commandList->SetGraphicsRootDescriptorTable(0,
|
||||||
Handle.ptr += getCurrentResourceStorage().m_currentScaleOffsetBufferIndex * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
getGPUDescriptorHandle(getCurrentResourceStorage().m_scaleOffsetDescriptorHeap,
|
||||||
commandList->SetGraphicsRootDescriptorTable(0, Handle);
|
getCurrentResourceStorage().m_currentScaleOffsetBufferIndex * g_descriptorStrideSRVCBVUAV)
|
||||||
|
);
|
||||||
getCurrentResourceStorage().m_currentScaleOffsetBufferIndex++;
|
getCurrentResourceStorage().m_currentScaleOffsetBufferIndex++;
|
||||||
|
|
||||||
size_t currentBufferIndex = getCurrentResourceStorage().m_constantsBufferIndex;
|
size_t currentBufferIndex = getCurrentResourceStorage().m_constantsBufferIndex;
|
||||||
|
@ -794,9 +798,10 @@ void D3D12GSRender::ExecCMD()
|
||||||
getCurrentResourceStorage().m_constantsBufferIndex++;
|
getCurrentResourceStorage().m_constantsBufferIndex++;
|
||||||
|
|
||||||
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_constantsBufferDescriptorsHeap);
|
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_constantsBufferDescriptorsHeap);
|
||||||
Handle = getCurrentResourceStorage().m_constantsBufferDescriptorsHeap->GetGPUDescriptorHandleForHeapStart();
|
commandList->SetGraphicsRootDescriptorTable(1,
|
||||||
Handle.ptr += currentBufferIndex * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
getGPUDescriptorHandle(getCurrentResourceStorage().m_constantsBufferDescriptorsHeap,
|
||||||
commandList->SetGraphicsRootDescriptorTable(1, Handle);
|
currentBufferIndex * g_descriptorStrideSRVCBVUAV)
|
||||||
|
);
|
||||||
commandList->SetPipelineState(m_PSO->first);
|
commandList->SetPipelineState(m_PSO->first);
|
||||||
|
|
||||||
if (m_PSO->second > 0)
|
if (m_PSO->second > 0)
|
||||||
|
@ -807,8 +812,6 @@ void D3D12GSRender::ExecCMD()
|
||||||
// Fill empty slots
|
// Fill empty slots
|
||||||
for (; usedTexture < m_PSO->second; usedTexture++)
|
for (; usedTexture < m_PSO->second; usedTexture++)
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||||
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||||
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
@ -818,27 +821,33 @@ void D3D12GSRender::ExecCMD()
|
||||||
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
|
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
|
||||||
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
|
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
|
||||||
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0);
|
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0);
|
||||||
m_device->CreateShaderResourceView(m_dummyTexture, &srvDesc, Handle);
|
m_device->CreateShaderResourceView(m_dummyTexture, &srvDesc,
|
||||||
|
getCPUDescriptorHandle(getCurrentResourceStorage().m_textureDescriptorsHeap,
|
||||||
|
(getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * g_descriptorStrideSRVCBVUAV)
|
||||||
|
);
|
||||||
|
|
||||||
D3D12_SAMPLER_DESC samplerDesc = {};
|
D3D12_SAMPLER_DESC samplerDesc = {};
|
||||||
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||||
samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||||
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;
|
||||||
Handle = getCurrentResourceStorage().m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
m_device->CreateSampler(&samplerDesc,
|
||||||
Handle.ptr += (getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
getCPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap,
|
||||||
m_device->CreateSampler(&samplerDesc, Handle);
|
(getCurrentResourceStorage().m_currentTextureIndex + usedTexture) * g_descriptorStrideSamplers)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle = getCurrentResourceStorage().m_textureDescriptorsHeap->GetGPUDescriptorHandleForHeapStart();
|
|
||||||
Handle.ptr += getCurrentResourceStorage().m_currentTextureIndex * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
|
||||||
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_textureDescriptorsHeap);
|
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_textureDescriptorsHeap);
|
||||||
commandList->SetGraphicsRootDescriptorTable(2, Handle);
|
commandList->SetGraphicsRootDescriptorTable(2,
|
||||||
|
getGPUDescriptorHandle(getCurrentResourceStorage().m_textureDescriptorsHeap,
|
||||||
|
getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSRVCBVUAV)
|
||||||
|
);
|
||||||
|
|
||||||
Handle = getCurrentResourceStorage().m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
|
||||||
Handle.ptr += getCurrentResourceStorage().m_currentTextureIndex * m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
|
||||||
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_samplerDescriptorHeap);
|
commandList->SetDescriptorHeaps(1, &getCurrentResourceStorage().m_samplerDescriptorHeap);
|
||||||
commandList->SetGraphicsRootDescriptorTable(3, Handle);
|
commandList->SetGraphicsRootDescriptorTable(3,
|
||||||
|
getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap,
|
||||||
|
getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSamplers)
|
||||||
|
);
|
||||||
|
|
||||||
getCurrentResourceStorage().m_currentTextureIndex += usedTexture;
|
getCurrentResourceStorage().m_currentTextureIndex += 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();
|
||||||
|
@ -866,8 +875,8 @@ void D3D12GSRender::ExecCMD()
|
||||||
LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target);
|
LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE *DepthStencilHandle = &m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
commandList->OMSetRenderTargets((UINT)numRTT, &m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(), true,
|
||||||
commandList->OMSetRenderTargets((UINT)numRTT, &m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(), true, DepthStencilHandle);
|
&getCPUDescriptorHandle(m_rtts.m_depthStencilDescriptorHeap, 0));
|
||||||
|
|
||||||
D3D12_VIEWPORT viewport =
|
D3D12_VIEWPORT viewport =
|
||||||
{
|
{
|
||||||
|
|
|
@ -342,6 +342,10 @@ private:
|
||||||
|
|
||||||
std::vector<D3D12_INPUT_ELEMENT_DESC> m_IASet;
|
std::vector<D3D12_INPUT_ELEMENT_DESC> m_IASet;
|
||||||
ID3D12Device* m_device;
|
ID3D12Device* m_device;
|
||||||
|
size_t g_descriptorStrideSRVCBVUAV;
|
||||||
|
size_t g_descriptorStrideDSV;
|
||||||
|
size_t g_descriptorStrideRTV;
|
||||||
|
size_t g_descriptorStrideSamplers;
|
||||||
ID3D12CommandQueue *m_commandQueueCopy;
|
ID3D12CommandQueue *m_commandQueueCopy;
|
||||||
ID3D12CommandQueue *m_commandQueueGraphic;
|
ID3D12CommandQueue *m_commandQueueGraphic;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue