diff --git a/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.cpp b/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.cpp index 66f38b41d2..13fbd3b658 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.cpp @@ -74,6 +74,8 @@ void resource_storage::reset() descriptors_heap_index = 0; current_sampler_index = 0; sampler_descriptors_heap_index = 0; + render_targets_descriptors_heap_index = 0; + depth_stencil_descriptor_heap_index = 0; ThrowIfFailed(command_allocator->Reset()); set_new_command_list(); @@ -102,6 +104,12 @@ void resource_storage::init(ID3D12Device *device) ThrowIfFailed(device->CreateDescriptorHeap(&sampler_heap_desc, IID_PPV_ARGS(&sampler_descriptor_heap[0]))); ThrowIfFailed(device->CreateDescriptorHeap(&sampler_heap_desc, IID_PPV_ARGS(&sampler_descriptor_heap[1]))); + D3D12_DESCRIPTOR_HEAP_DESC ds_descriptor_heap_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_DSV , 10000}; + device->CreateDescriptorHeap(&ds_descriptor_heap_desc, IID_PPV_ARGS(&depth_stencil_descriptor_heap)); + + D3D12_DESCRIPTOR_HEAP_DESC rtv_descriptor_heap_desc = { D3D12_DESCRIPTOR_HEAP_TYPE_RTV , 10000 }; + device->CreateDescriptorHeap(&rtv_descriptor_heap_desc, IID_PPV_ARGS(&render_targets_descriptors_heap)); + frame_finished_handle = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS); fence_value = 0; ThrowIfFailed(device->CreateFence(fence_value++, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(frame_finished_fence.GetAddressOf()))); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.h b/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.h index 7c0781b92f..33c026a93c 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.h @@ -214,6 +214,11 @@ struct resource_storage size_t sampler_descriptors_heap_index; size_t current_sampler_index; + size_t render_targets_descriptors_heap_index; + ComPtr render_targets_descriptors_heap; + size_t depth_stencil_descriptor_heap_index; + ComPtr depth_stencil_descriptor_heap; + ComPtr ram_framebuffer; /// Texture that were invalidated diff --git a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp index 83b5e5c84b..e899983e74 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp @@ -76,24 +76,32 @@ void D3D12GSRender::clear_surface(u32 arg) m_timers.m_rttDuration += std::chrono::duration_cast(rtt_duration_end - rtt_duration_start).count(); if (arg & 0x1 || arg & 0x2) - m_rtts.bind_depth_stencil(m_device.Get(), m_surface.depth_format, m_rtts.depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()); - - if (arg & 0x1) { - u32 clear_depth = rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE] >> 8; - u32 max_depth_value = m_surface.depth_format == CELL_GCM_SURFACE_Z16 ? 0x0000ffff : 0x00ffffff; - getCurrentResourceStorage().command_list->ClearDepthStencilView(m_rtts.depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, clear_depth / (float)max_depth_value, 0, 0, nullptr); - } + CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()) + .Offset(getCurrentResourceStorage().depth_stencil_descriptor_heap_index * g_descriptorStrideRTV); + m_rtts.bind_depth_stencil(m_device.Get(), m_surface.depth_format, handle); + getCurrentResourceStorage().depth_stencil_descriptor_heap_index++; - if (arg & 0x2) - getCurrentResourceStorage().command_list->ClearDepthStencilView(m_rtts.depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_STENCIL, 0.f, - get_clear_stencil(rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE]), 0, nullptr); + if (arg & 0x1) + { + u32 clear_depth = rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE] >> 8; + u32 max_depth_value = m_surface.depth_format == CELL_GCM_SURFACE_Z16 ? 0x0000ffff : 0x00ffffff; + getCurrentResourceStorage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, clear_depth / (float)max_depth_value, 0, 0, nullptr); + } + + if (arg & 0x2) + getCurrentResourceStorage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_STENCIL, 0.f, + get_clear_stencil(rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE]), 0, nullptr); + } if (arg & 0xF0) { - size_t rtt_index = m_rtts.bind_render_targets(m_device.Get(), m_surface.color_format, m_rtts.render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()); + CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()) + .Offset(getCurrentResourceStorage().render_targets_descriptors_heap_index * g_descriptorStrideRTV); + size_t rtt_index = m_rtts.bind_render_targets(m_device.Get(), m_surface.color_format, handle); + getCurrentResourceStorage().render_targets_descriptors_heap_index += rtt_index; for (unsigned i = 0; i < rtt_index; i++) - getCurrentResourceStorage().command_list->ClearRenderTargetView(CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()).Offset(i, g_descriptorStrideRTV), + getCurrentResourceStorage().command_list->ClearRenderTargetView(handle.Offset(i, g_descriptorStrideRTV), get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(), 0, nullptr); } @@ -220,7 +228,7 @@ size_t render_targets::bind_render_targets(ID3D12Device *device, u32 color_forma if (bound_render_targets[i] == nullptr) continue; device->CreateRenderTargetView(bound_render_targets[i], &rtt_view_desc, - CD3DX12_CPU_DESCRIPTOR_HANDLE(render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()).Offset((INT)rtt_index * g_descriptor_stride_rtv)); + CD3DX12_CPU_DESCRIPTOR_HANDLE(handle).Offset((INT)rtt_index * g_descriptor_stride_rtv)); rtt_index++; } return rtt_index; @@ -233,16 +241,22 @@ size_t render_targets::bind_depth_stencil(ID3D12Device *device, u32 depth_format D3D12_DEPTH_STENCIL_VIEW_DESC depth_stencil_view_desc = {}; depth_stencil_view_desc.Format = get_depth_stencil_surface_format(depth_format); depth_stencil_view_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; - device->CreateDepthStencilView(bound_depth_stencil, &depth_stencil_view_desc, depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()); + device->CreateDepthStencilView(bound_depth_stencil, &depth_stencil_view_desc, handle); return 1; } void D3D12GSRender::set_rtt_and_ds(ID3D12GraphicsCommandList *command_list) { - size_t num_rtt = m_rtts.bind_render_targets(m_device.Get(), m_surface.color_format, m_rtts.render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()); - size_t num_ds = m_rtts.bind_depth_stencil(m_device.Get(), m_surface.depth_format, m_rtts.depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()); - command_list->OMSetRenderTargets((UINT)num_rtt, num_rtt > 0 ? &m_rtts.render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart() : nullptr, !!num_rtt, - num_ds > 0 ? &CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()) : nullptr); + CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()) + .Offset(getCurrentResourceStorage().render_targets_descriptors_heap_index * g_descriptorStrideRTV); + size_t num_rtt = m_rtts.bind_render_targets(m_device.Get(), m_surface.color_format, handle); + getCurrentResourceStorage().render_targets_descriptors_heap_index += num_rtt; + CD3DX12_CPU_DESCRIPTOR_HANDLE depth_stencil_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(getCurrentResourceStorage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()) + .Offset(getCurrentResourceStorage().depth_stencil_descriptor_heap_index * g_descriptorStrideRTV); + size_t num_ds = m_rtts.bind_depth_stencil(m_device.Get(), m_surface.depth_format, depth_stencil_handle); + getCurrentResourceStorage().depth_stencil_descriptor_heap_index += num_ds; + command_list->OMSetRenderTargets((UINT)num_rtt, num_rtt > 0 ? &handle : nullptr, !!num_rtt, + num_ds > 0 ? &depth_stencil_handle : nullptr); } ID3D12Resource *render_targets::bind_address_as_render_targets(ID3D12Device *device, ID3D12GraphicsCommandList *cmdList, u32 address, @@ -322,15 +336,6 @@ ID3D12Resource * render_targets::bind_address_as_depth_stencil(ID3D12Device * de void render_targets::init(ID3D12Device *device)//, u8 surfaceDepthFormat, size_t width, size_t height, float clearColor[4], float clearDepth) { - D3D12_DESCRIPTOR_HEAP_DESC descriptor_heap_desc = {}; - descriptor_heap_desc.NumDescriptors = 1; - descriptor_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV; - device->CreateDescriptorHeap(&descriptor_heap_desc, IID_PPV_ARGS(depth_stencil_descriptor_heap.GetAddressOf())); - - descriptor_heap_desc.NumDescriptors = 4; - descriptor_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; - device->CreateDescriptorHeap(&descriptor_heap_desc, IID_PPV_ARGS(render_targets_descriptors_heap.GetAddressOf())); - memset(bound_render_targets_address, 0, 4 * sizeof(u32)); memset(bound_render_targets, 0, 4 * sizeof(ID3D12Resource*)); bound_depth_stencil = nullptr; @@ -338,6 +343,7 @@ void render_targets::init(ID3D12Device *device)//, u8 surfaceDepthFormat, size_t g_descriptor_stride_rtv = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); } + namespace { /** diff --git a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.h b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.h index 0f0c065ea7..80eb3d1b0e 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.h @@ -11,8 +11,6 @@ struct render_targets std::unordered_map > depth_stencil_storage; ID3D12Resource *bound_depth_stencil; u32 bound_depth_stencil_address; - ComPtr render_targets_descriptors_heap; - ComPtr depth_stencil_descriptor_heap; size_t bind_render_targets(ID3D12Device *, u32 color_format, D3D12_CPU_DESCRIPTOR_HANDLE); size_t bind_depth_stencil(ID3D12Device *, u32 depth_format, D3D12_CPU_DESCRIPTOR_HANDLE);