From effd379c2556285221752695a655c59c019a1324 Mon Sep 17 00:00:00 2001 From: raven02 Date: Sun, 3 Jul 2016 10:35:51 +0800 Subject: [PATCH] Vulkan/DX12 : refactor cull face code (#1849) * Vulkan/DX12 : refactor cull face code 1 * Add optimal build options to CMakeLists (#1841) Provides two options when building RPCS3 USE_SYSTEM_FFMPEG BOOL (default: OFF) USE_SYSTEM_LIBPNG BOOL (default: OFF) These options lets the user select between the system provided and builtin libraries of ffmpeg and libpng to overcome possible system issues. Also adds support for older libpng releases if the user doesn't have libpng 1.5 or higher. * DX12: depth buffer compare should perform only if depth testing is enabled (#1848) * GL: front face regression fix (#1854) * GUI: Add bulk decryption of LLE modules (#1845) Adds a new menu to "Tools" called "&Decrypt SPRX libraries" which opens a dialog to select multiple *.sprx files, which are than decrypted all at once. This speeds up the LLE module decryption and saves users a lot of time. The output path is the same where the input module resides and the extension is changed to *.prx * vk: Avoid double-copy for vertex attributes (#1852) * vk: Avoid double-copy for vertex attributes fix buffer overflow vk: Fix vertex attrib offset_in_dst for batched draw calls * whitespace fix only --- rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp | 11 +++++++ rpcs3/Emu/RSX/D3D12/D3D12Formats.h | 5 ++++ rpcs3/Emu/RSX/D3D12/D3D12PipelineState.cpp | 16 ++-------- rpcs3/Emu/RSX/VK/VKFormats.h | 1 + rpcs3/Emu/RSX/VK/VKGSRender.cpp | 34 ++++++++++------------ 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp index 6a783aef7c..2e37cfae94 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Formats.cpp @@ -382,6 +382,17 @@ BOOL get_front_face_ccw(u32 ffv) throw EXCEPTION("Invalid front face value (0x%x)", ffv); } +D3D12_CULL_MODE get_cull_face(u32 cfv) +{ + switch (cfv) + { + case CELL_GCM_FRONT: return D3D12_CULL_MODE_FRONT; + case CELL_GCM_BACK: return D3D12_CULL_MODE_BACK; + default: return D3D12_CULL_MODE_NONE; + } + throw EXCEPTION("Invalid cull face value (0x%x)", cfv); +} + DXGI_FORMAT get_index_type(rsx::index_array_type index_type) { switch (index_type) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Formats.h b/rpcs3/Emu/RSX/D3D12/D3D12Formats.h index c507c46510..677986e5a6 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Formats.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12Formats.h @@ -93,6 +93,11 @@ DXGI_FORMAT get_depth_samplable_surface_format(rsx::surface_depth_format format) */ BOOL get_front_face_ccw(u32 set_front_face_value); +/** +* Convert cull face value to a D3D12_CULL_MODE telling wheter cull face is front or back +*/ +D3D12_CULL_MODE get_cull_face(u32 set_cull_face_value); + /** * Convert index type to DXGI_FORMAT */ diff --git a/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.cpp b/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.cpp index 702c127ab7..e844e4a765 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12PipelineState.cpp @@ -202,23 +202,11 @@ void D3D12GSRender::load_program() D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF, }; prop.Rasterization = CD3D12_RASTERIZER_DESC; + if (!!rsx::method_registers[NV4097_SET_CULL_FACE_ENABLE]) { - switch (rsx::method_registers[NV4097_SET_CULL_FACE]) - { - case CELL_GCM_FRONT: - prop.Rasterization.CullMode = D3D12_CULL_MODE_FRONT; - break; - case CELL_GCM_BACK: - prop.Rasterization.CullMode = D3D12_CULL_MODE_BACK; - break; - default: - prop.Rasterization.CullMode = D3D12_CULL_MODE_NONE; - break; - } + prop.Rasterization.CullMode = get_cull_face(rsx::method_registers[NV4097_SET_CULL_FACE]); } - else - prop.Rasterization.CullMode = D3D12_CULL_MODE_NONE; prop.Rasterization.FrontCounterClockwise = get_front_face_ccw(rsx::method_registers[NV4097_SET_FRONT_FACE]); diff --git a/rpcs3/Emu/RSX/VK/VKFormats.h b/rpcs3/Emu/RSX/VK/VKFormats.h index 31760b0863..376bf6f97b 100644 --- a/rpcs3/Emu/RSX/VK/VKFormats.h +++ b/rpcs3/Emu/RSX/VK/VKFormats.h @@ -15,6 +15,7 @@ namespace vk VkStencilOp get_stencil_op(u32 op); VkLogicOp get_logic_op(u32 op); VkFrontFace get_front_face_ccw(u32 ffv); + VkCullModeFlags get_cull_face(u32 cfv); VkBorderColor get_border_color(u8 color); std::tuple get_min_filter_and_mip(rsx::texture_minify_filter min_filter); diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index fffde04e1a..ba930606d3 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -269,6 +269,18 @@ namespace vk } throw EXCEPTION("Unknown front face value: 0x%X", ffv); } + + VkCullModeFlags get_cull_face(u32 cfv) + { + switch (cfv) + { + case CELL_GCM_FRONT: return VK_CULL_MODE_FRONT_BIT; + case CELL_GCM_BACK: return VK_CULL_MODE_BACK_BIT; + case CELL_GCM_FRONT_AND_BACK: return VK_CULL_MODE_FRONT_AND_BACK; + default: return VK_CULL_MODE_NONE; + } + throw EXCEPTION("Unknown cull face value: 0x%X", cfv); + } } @@ -990,26 +1002,10 @@ bool VKGSRender::load_program() else properties.ds.depthTestEnable = VK_FALSE; - if (!!rsx::method_registers[NV4097_SET_CULL_FACE_ENABLE]) - { - switch (rsx::method_registers[NV4097_SET_CULL_FACE]) - { - case CELL_GCM_FRONT: - properties.rs.cullMode = VK_CULL_MODE_FRONT_BIT; - break; - case CELL_GCM_BACK: - properties.rs.cullMode = VK_CULL_MODE_BACK_BIT; - break; - case CELL_GCM_FRONT_AND_BACK: - properties.rs.cullMode = VK_CULL_MODE_FRONT_AND_BACK; - break; - default: - properties.rs.cullMode = VK_CULL_MODE_NONE; - break; - } + if (!!rsx::method_registers[NV4097_SET_CULL_FACE_ENABLE]) + { + properties.rs.cullMode = vk::get_cull_face(rsx::method_registers[NV4097_SET_CULL_FACE]); } - else - properties.rs.cullMode = VK_CULL_MODE_NONE; properties.rs.frontFace = vk::get_front_face_ccw(rsx::method_registers[NV4097_SET_FRONT_FACE]);