From 925d6889a68964a0853e25dc4c4616efa133c801 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 31 Oct 2015 23:06:59 +0100 Subject: [PATCH 1/5] d3d12: Use ring buffer like rtv/dsv descriptor heap --- rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.cpp | 8 +++ rpcs3/Emu/RSX/D3D12/D3D12MemoryHelpers.h | 5 ++ rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp | 60 ++++++++++--------- rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.h | 2 - 4 files changed, 46 insertions(+), 29 deletions(-) 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); From ae5d95d462e45f350f5d9d204f018c879570ab08 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 10 Nov 2015 22:34:57 +0100 Subject: [PATCH 2/5] rsx/common: Take primitive restart index in account and turns it into -1. --- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 51 ++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index df77c36aa6..dd91475a5b 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -62,11 +62,13 @@ void write_vertex_array_data_to_buffer(void *buffer, u32 first, u32 count, size_ namespace { template -void uploadAsIt(char *dst, u32 address, size_t indexCount, bool is_primitive_restart_enabled, u32 &min_index, u32 &max_index) noexcept +void uploadAsIt(char *dst, u32 address, size_t indexCount, bool is_primitive_restart_enabled, u32 primitive_restart_index, u32 &min_index, u32 &max_index) noexcept { for (u32 i = 0; i < indexCount; ++i) { IndexType index = vm::ps3::_ref(address + i * sizeof(IndexType)); + if (is_primitive_restart_enabled && index == (IndexType)primitive_restart_index) + index = (IndexType)-1; (IndexType&)dst[i * sizeof(IndexType)] = index; if (is_primitive_restart_enabled && index == (IndexType)-1) // Cut continue; @@ -75,16 +77,25 @@ void uploadAsIt(char *dst, u32 address, size_t indexCount, bool is_primitive_res } } +// FIXME: expanded primitive type may not support primitive restart correctly + template -void expandIndexedTriangleFan(char *dst, u32 address, size_t indexCount, bool is_primitive_restart_enabled, u32 &min_index, u32 &max_index) noexcept +void expandIndexedTriangleFan(char *dst, u32 address, size_t indexCount, bool is_primitive_restart_enabled, u32 primitive_restart_index, u32 &min_index, u32 &max_index) noexcept { for (unsigned i = 0; i < indexCount - 2; i++) { IndexType index0 = vm::ps3::_ref(address); - (IndexType&)dst[(3 * i) * sizeof(IndexType)] = index0; + if (index0 == (IndexType)primitive_restart_index) + index0 = (IndexType)-1; IndexType index1 = vm::ps3::_ref(address + (i + 2 - 1) * sizeof(IndexType)); - (IndexType&)dst[(3 * i + 1) * sizeof(IndexType)] = index1; + if (index1 == (IndexType)primitive_restart_index) + index1 = (IndexType)-1; IndexType index2 = vm::ps3::_ref(address + (i + 2) * sizeof(IndexType)); + if (index2 == (IndexType)primitive_restart_index) + index2 = (IndexType)-1; + + (IndexType&)dst[(3 * i) * sizeof(IndexType)] = index0; + (IndexType&)dst[(3 * i + 1) * sizeof(IndexType)] = index1; (IndexType&)dst[(3 * i + 2) * sizeof(IndexType)] = index2; if (!is_primitive_restart_enabled || index0 != (IndexType)-1) // Cut @@ -106,20 +117,29 @@ void expandIndexedTriangleFan(char *dst, u32 address, size_t indexCount, bool is } template -void expandIndexedQuads(char *dst, u32 address, size_t indexCount, bool is_primitive_restart_enabled, u32 &min_index, u32 &max_index) noexcept +void expandIndexedQuads(char *dst, u32 address, size_t indexCount, bool is_primitive_restart_enabled, u32 primitive_restart_index, u32 &min_index, u32 &max_index) noexcept { for (unsigned i = 0; i < indexCount / 4; i++) { - // First triangle IndexType index0 = vm::ps3::_ref(address + 4 * i * sizeof(IndexType)); - (IndexType&)dst[(6 * i) * sizeof(IndexType)] = index0; + if (is_primitive_restart_enabled && index0 == (IndexType)primitive_restart_index) + index0 = (IndexType)-1; IndexType index1 = vm::ps3::_ref(address + (4 * i + 1) * sizeof(IndexType)); - (IndexType&)dst[(6 * i + 1) * sizeof(IndexType)] = index1; + if (is_primitive_restart_enabled && index1 == (IndexType)primitive_restart_index) + index1 = (IndexType)-1; IndexType index2 = vm::ps3::_ref(address + (4 * i + 2) * sizeof(IndexType)); + if (is_primitive_restart_enabled && index2 == (IndexType)primitive_restart_index) + index2 = (IndexType)-1; + IndexType index3 = vm::ps3::_ref(address + (4 * i + 3) * sizeof(IndexType)); + if (is_primitive_restart_enabled &&index3 == (IndexType)primitive_restart_index) + index3 = (IndexType)-1; + + // First triangle + (IndexType&)dst[(6 * i) * sizeof(IndexType)] = index0; + (IndexType&)dst[(6 * i + 1) * sizeof(IndexType)] = index1; (IndexType&)dst[(6 * i + 2) * sizeof(IndexType)] = index2; // Second triangle (IndexType&)dst[(6 * i + 3) * sizeof(IndexType)] = index2; - IndexType index3 = vm::ps3::_ref(address + (4 * i + 3) * sizeof(IndexType)); (IndexType&)dst[(6 * i + 4) * sizeof(IndexType)] = index3; (IndexType&)dst[(6 * i + 5) * sizeof(IndexType)] = index0; @@ -234,6 +254,7 @@ void write_index_array_data_to_buffer(char* dst, unsigned m_draw_mode, unsigned u32 base_offset = rsx::method_registers[NV4097_SET_VERTEX_DATA_BASE_OFFSET]; u32 base_index = 0;//rsx::method_registers[NV4097_SET_VERTEX_DATA_BASE_INDEX]; bool is_primitive_restart_enabled = !!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE]; + u32 primitive_restart_index = rsx::method_registers[NV4097_SET_RESTART_INDEX]; switch (m_draw_mode) { @@ -248,10 +269,10 @@ void write_index_array_data_to_buffer(char* dst, unsigned m_draw_mode, unsigned switch (type) { case CELL_GCM_DRAW_INDEX_ARRAY_TYPE_32: - uploadAsIt(dst, address + (first + base_index) * sizeof(u32), count, is_primitive_restart_enabled, min_index, max_index); + uploadAsIt(dst, address + (first + base_index) * sizeof(u32), count, is_primitive_restart_enabled, primitive_restart_index, min_index, max_index); return; case CELL_GCM_DRAW_INDEX_ARRAY_TYPE_16: - uploadAsIt(dst, address + (first + base_index) * sizeof(u16), count, is_primitive_restart_enabled, min_index, max_index); + uploadAsIt(dst, address + (first + base_index) * sizeof(u16), count, is_primitive_restart_enabled, primitive_restart_index, min_index, max_index); return; } return; @@ -259,20 +280,20 @@ void write_index_array_data_to_buffer(char* dst, unsigned m_draw_mode, unsigned switch (type) { case CELL_GCM_DRAW_INDEX_ARRAY_TYPE_32: - expandIndexedTriangleFan(dst, address + (first + base_index) * sizeof(u32), count, is_primitive_restart_enabled, min_index, max_index); + expandIndexedTriangleFan(dst, address + (first + base_index) * sizeof(u32), count, is_primitive_restart_enabled, primitive_restart_index, min_index, max_index); return; case CELL_GCM_DRAW_INDEX_ARRAY_TYPE_16: - expandIndexedTriangleFan(dst, address + (first + base_index) * sizeof(u16), count, is_primitive_restart_enabled, min_index, max_index); + expandIndexedTriangleFan(dst, address + (first + base_index) * sizeof(u16), count, is_primitive_restart_enabled, primitive_restart_index, min_index, max_index); return; } case CELL_GCM_PRIMITIVE_QUADS: switch (type) { case CELL_GCM_DRAW_INDEX_ARRAY_TYPE_32: - expandIndexedQuads(dst, address + (first + base_index) * sizeof(u32), count, is_primitive_restart_enabled, min_index, max_index); + expandIndexedQuads(dst, address + (first + base_index) * sizeof(u32), count, is_primitive_restart_enabled, primitive_restart_index, min_index, max_index); return; case CELL_GCM_DRAW_INDEX_ARRAY_TYPE_16: - expandIndexedQuads(dst, address + (first + base_index) * sizeof(u16), count, is_primitive_restart_enabled, min_index, max_index); + expandIndexedQuads(dst, address + (first + base_index) * sizeof(u16), count, is_primitive_restart_enabled, primitive_restart_index, min_index, max_index); return; } } From 917f08c5346f5bc8730d40ba54d8b74567d11609 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 1 Nov 2015 01:07:15 +0100 Subject: [PATCH 3/5] d3d12: Fix depth range --- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 80059a1311..66c8c0fed6 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -346,8 +346,8 @@ void D3D12GSRender::end() 0.f, (float)clip_w, (float)clip_h, - -1.f, - 1.f + (f32&)rsx::method_registers[NV4097_SET_CLIP_MIN], + (f32&)rsx::method_registers[NV4097_SET_CLIP_MAX] }; getCurrentResourceStorage().command_list->RSSetViewports(1, &viewport); From c152c20d70fb85050f232f1786ec71303953731b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 1 Nov 2015 20:56:49 +0100 Subject: [PATCH 4/5] d3d12: Fix wrong front_face_ccw value for Disgaea 3 --- rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp index 9cd3bf11b9..53a7f4c3b5 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp @@ -364,8 +364,8 @@ BOOL get_front_face_ccw(u32 set_front_face_value) noexcept { switch (set_front_face_value) { - case CELL_GCM_CW: return FALSE; default: // Disgaea 3 pass some garbage value at startup, this is needed to survive. + case CELL_GCM_CW: return FALSE; case CELL_GCM_CCW: return TRUE; } unreachable("Wrong front face value"); From 039e729881ca88c4e13218fb8f2192f29852d1a9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 6 Nov 2015 22:16:12 +0100 Subject: [PATCH 5/5] d3d12: Fix scissor --- rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp | 10 ++++++++++ rpcs3/Emu/RSX/D3D12/D3D12Formats.h | 5 +++++ rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 9 +-------- rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp | 11 ++++++----- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp index 53a7f4c3b5..2242882d26 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp @@ -465,4 +465,14 @@ DXGI_FORMAT get_vertex_attribute_format(u8 type, u8 size) noexcept } unreachable("Wrong type"); } + +D3D12_RECT get_scissor(u32 horizontal, u32 vertical) noexcept +{ + return{ + horizontal & 0xFFFF, + vertical & 0xFFFF, + (horizontal & 0xFFFF) + (horizontal >> 16), + (vertical & 0xFFFF) + (vertical >> 16) + }; +} #endif diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Formats.h b/rpcs3/Emu/RSX/D3D12/D3D12Formats.h index 37fd9f6aee..45fdac4114 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Formats.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12Formats.h @@ -97,3 +97,8 @@ DXGI_FORMAT get_index_type(u8 index_type) noexcept; * Convert vertex attribute format and size to DXGI_FORMAT */ DXGI_FORMAT get_vertex_attribute_format(u8 type, u8 size) noexcept; + +/** + * Convert scissor register value to D3D12_RECT + */ +D3D12_RECT get_scissor(u32 horizontal, u32 vertical) noexcept; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 66c8c0fed6..3a135b9953 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -351,14 +351,7 @@ void D3D12GSRender::end() }; getCurrentResourceStorage().command_list->RSSetViewports(1, &viewport); - D3D12_RECT box = - { - 0, - 0, - (LONG)clip_w, - (LONG)clip_h, - }; - getCurrentResourceStorage().command_list->RSSetScissorRects(1, &box); + getCurrentResourceStorage().command_list->RSSetScissorRects(1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL])); getCurrentResourceStorage().command_list->IASetPrimitiveTopology(get_primitive_topology(draw_mode)); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp index e899983e74..066b73a1d4 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp @@ -86,12 +86,13 @@ void D3D12GSRender::clear_surface(u32 arg) { 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); + getCurrentResourceStorage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, clear_depth / (float)max_depth_value, 0, + 1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL])); } 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); + getCurrentResourceStorage().command_list->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_STENCIL, 0.f, get_clear_stencil(rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE]), + 1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL])); } if (arg & 0xF0) @@ -101,8 +102,8 @@ void D3D12GSRender::clear_surface(u32 arg) 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(handle.Offset(i, g_descriptorStrideRTV), - get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(), 0, nullptr); + getCurrentResourceStorage().command_list->ClearRenderTargetView(handle.Offset(i, g_descriptorStrideRTV), get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(), + 1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL])); } std::chrono::time_point end_duration = std::chrono::system_clock::now();