From a5ac5a9861551a69f70bcda9a52b2db79e218f7d Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 15 Aug 2020 14:07:18 +0300 Subject: [PATCH] rsx: Separate uint depth formats from float depth formats --- rpcs3/Emu/RSX/Common/TextureUtils.cpp | 39 +++++++++++++++++++++-- rpcs3/Emu/RSX/Common/TextureUtils.h | 5 ++- rpcs3/Emu/RSX/Common/surface_store.h | 6 ++-- rpcs3/Emu/RSX/Common/surface_utils.h | 17 +++++----- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 19 ++--------- rpcs3/Emu/RSX/GL/GLHelpers.cpp | 3 +- rpcs3/Emu/RSX/GL/GLHelpers.h | 4 +-- rpcs3/Emu/RSX/GL/GLRenderTargets.cpp | 17 +++++----- rpcs3/Emu/RSX/GL/GLRenderTargets.h | 13 +++----- rpcs3/Emu/RSX/GL/GLTextureCache.h | 5 ++- rpcs3/Emu/RSX/RSXThread.cpp | 10 +++--- rpcs3/Emu/RSX/RSXThread.h | 3 +- rpcs3/Emu/RSX/VK/VKFormats.cpp | 14 +++++++-- rpcs3/Emu/RSX/VK/VKFormats.h | 2 +- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 37 ++-------------------- rpcs3/Emu/RSX/VK/VKRenderTargets.h | 10 ++---- rpcs3/Emu/RSX/gcm_enums.h | 45 +++++++++++++++++++++++++-- rpcs3/Emu/RSX/rsx_methods.h | 34 ++++++++++++-------- rpcs3/Emu/RSX/rsx_utils.h | 3 +- 19 files changed, 161 insertions(+), 125 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index d34b172aa7..a0fa8215f4 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -839,6 +839,18 @@ u8 get_format_block_size_in_bytes(rsx::surface_color_format format) } } +u8 get_format_block_size_in_bytes(rsx::surface_depth_format2 format) +{ + switch (format) + { + case rsx::surface_depth_format2::z24s8_uint: + case rsx::surface_depth_format2::z24s8_float: + return 4; + default: + return 2; + } +} + u8 get_format_sample_count(rsx::surface_antialiasing antialias) { switch (antialias) @@ -856,6 +868,18 @@ u8 get_format_sample_count(rsx::surface_antialiasing antialias) } } +bool is_depth_stencil_format(rsx::surface_depth_format2 format) +{ + switch (format) + { + case rsx::surface_depth_format2::z24s8_uint: + case rsx::surface_depth_format2::z24s8_float: + return true; + default: + return false; + } +} + /** * Returns number of texel lines decoded in one pitch-length number of bytes */ @@ -1047,15 +1071,24 @@ std::pair get_compatible_gcm_format(rsx::surface_color_format format) } } -std::pair get_compatible_gcm_format(rsx::surface_depth_format format) +std::pair get_compatible_gcm_format(rsx::surface_depth_format2 format) { switch (format) { - case rsx::surface_depth_format::z16: + case rsx::surface_depth_format2::z16_uint: return{ CELL_GCM_TEXTURE_DEPTH16, true }; - case rsx::surface_depth_format::z24s8: + case rsx::surface_depth_format2::z24s8_uint: return{ CELL_GCM_TEXTURE_DEPTH24_D8, true }; + case rsx::surface_depth_format2::z16_float : + return{ CELL_GCM_TEXTURE_DEPTH16_FLOAT, true }; + case rsx::surface_depth_format2::z24s8_float: + return{ CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT, true }; default: ASSUME(0); } } + +u32 get_max_depth_value(rsx::surface_depth_format2 format) +{ + return get_format_block_size_in_bytes(format) == 2 ? 0xFFFF : 0xFFFFFF; +} diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.h b/rpcs3/Emu/RSX/Common/TextureUtils.h index 07f3df6d44..78300de896 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.h +++ b/rpcs3/Emu/RSX/Common/TextureUtils.h @@ -135,8 +135,11 @@ texture_memory_info upload_texture_subresource(gsl::span dst_buffer, u8 get_format_block_size_in_bytes(int format); u8 get_format_block_size_in_texel(int format); u8 get_format_block_size_in_bytes(rsx::surface_color_format format); +u8 get_format_block_size_in_bytes(rsx::surface_depth_format2 format); u8 get_format_sample_count(rsx::surface_antialiasing antialias); +u32 get_max_depth_value(rsx::surface_depth_format2 format); +bool is_depth_stencil_format(rsx::surface_depth_format2 format); /** * Returns number of texel rows encoded in one pitch-length line of bytes @@ -163,4 +166,4 @@ u32 get_remap_encoding(const std::pair, std::array>& re * Get gcm texel layout. Returns */ std::pair get_compatible_gcm_format(rsx::surface_color_format format); -std::pair get_compatible_gcm_format(rsx::surface_depth_format format); +std::pair get_compatible_gcm_format(rsx::surface_depth_format2 format); diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index 1e57604d1a..363ff481da 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -650,7 +650,7 @@ namespace rsx surface_type bind_address_as_depth_stencil( command_list_type command_list, u32 address, - surface_depth_format depth_format, + surface_depth_format2 depth_format, surface_antialiasing antialias, size_t width, size_t height, size_t pitch, Args&&... extra_params) @@ -658,7 +658,7 @@ namespace rsx return bind_surface_address( command_list, address, depth_format, antialias, width, height, pitch, - depth_format == rsx::surface_depth_format::z16? 2 : 4, + get_format_block_size_in_bytes(depth_format), std::forward(extra_params)...); } @@ -670,7 +670,7 @@ namespace rsx template void prepare_render_target( command_list_type command_list, - surface_color_format color_format, surface_depth_format depth_format, + surface_color_format color_format, surface_depth_format2 depth_format, u32 clip_horizontal_reg, u32 clip_vertical_reg, surface_target set_surface_target, surface_antialiasing antialias, diff --git a/rpcs3/Emu/RSX/Common/surface_utils.h b/rpcs3/Emu/RSX/Common/surface_utils.h index 9173ddd749..cb13937bed 100644 --- a/rpcs3/Emu/RSX/Common/surface_utils.h +++ b/rpcs3/Emu/RSX/Common/surface_utils.h @@ -149,7 +149,7 @@ namespace rsx union { rsx::surface_color_format gcm_color_format; - rsx::surface_depth_format gcm_depth_format; + rsx::surface_depth_format2 gcm_depth_format; } format_info; @@ -263,16 +263,17 @@ namespace rsx format_info.gcm_color_format = format; } - void set_format(rsx::surface_depth_format format) + void set_format(rsx::surface_depth_format2 format) { format_info.gcm_depth_format = format; - } - void set_depth_render_mode(bool integer) - { - if (is_depth_surface()) + if (format >= rsx::surface_depth_format2::z16_float) { - format_class = (integer) ? format_type::depth_uint : format_type::depth_float; + format_class = rsx::format_type::depth_float; + } + else + { + format_class = rsx::format_type::depth_uint; } } @@ -281,7 +282,7 @@ namespace rsx return format_info.gcm_color_format; } - rsx::surface_depth_format get_surface_depth_format() const + rsx::surface_depth_format2 get_surface_depth_format() const { return format_info.gcm_depth_format; } diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 7f5b18468e..340106dc61 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -7,19 +7,6 @@ #define DUMP_VERTEX_DATA 0 -namespace -{ - u32 get_max_depth_value(rsx::surface_depth_format format) - { - switch (format) - { - case rsx::surface_depth_format::z16: return 0xFFFF; - case rsx::surface_depth_format::z24s8: return 0xFFFFFF; - } - fmt::throw_exception("Unknown depth format" HERE); - } -} - u64 GLGSRender::get_cycles() { return thread_ctrl::get_cycles(static_cast&>(*this)); @@ -510,21 +497,21 @@ void GLGSRender::clear_surface(u32 arg) rsx::method_registers.scissor_height() < rsx::method_registers.surface_clip_height(); bool update_color = false, update_z = false; - rsx::surface_depth_format surface_depth_format = rsx::method_registers.surface_depth_fmt(); + rsx::surface_depth_format2 surface_depth_format = rsx::method_registers.surface_depth_fmt(); if (auto ds = std::get<1>(m_rtts.m_bound_depth_stencil); arg & 0x3) { if (arg & 0x1) { u32 max_depth_value = get_max_depth_value(surface_depth_format); - u32 clear_depth = rsx::method_registers.z_clear_value(surface_depth_format == rsx::surface_depth_format::z24s8); + u32 clear_depth = rsx::method_registers.z_clear_value(is_depth_stencil_format(surface_depth_format)); gl_state.depth_mask(GL_TRUE); gl_state.clear_depth(f32(clear_depth) / max_depth_value); mask |= GLenum(gl::buffers::depth); } - if (surface_depth_format == rsx::surface_depth_format::z24s8) + if (is_depth_stencil_format(surface_depth_format)) { if (arg & 0x2) { diff --git a/rpcs3/Emu/RSX/GL/GLHelpers.cpp b/rpcs3/Emu/RSX/GL/GLHelpers.cpp index 64bf927e8e..5c0810076c 100644 --- a/rpcs3/Emu/RSX/GL/GLHelpers.cpp +++ b/rpcs3/Emu/RSX/GL/GLHelpers.cpp @@ -631,12 +631,11 @@ namespace gl switch (const auto fmt = dst->get_internal_format()) { - case texture::internal_format::depth: case texture::internal_format::depth16: + case texture::internal_format::depth32f: clear_mask = GL_DEPTH_BUFFER_BIT; attachment = GL_DEPTH_ATTACHMENT; break; - case texture::internal_format::depth_stencil: case texture::internal_format::depth24_stencil8: case texture::internal_format::depth32f_stencil8: clear_mask = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; diff --git a/rpcs3/Emu/RSX/GL/GLHelpers.h b/rpcs3/Emu/RSX/GL/GLHelpers.h index bf5655a504..1424c5d0df 100644 --- a/rpcs3/Emu/RSX/GL/GLHelpers.h +++ b/rpcs3/Emu/RSX/GL/GLHelpers.h @@ -1473,11 +1473,9 @@ namespace gl bgr = GL_BGR, bgra = GL_BGRA, - stencil = GL_STENCIL_INDEX, stencil8 = GL_STENCIL_INDEX8, - depth = GL_DEPTH_COMPONENT, depth16 = GL_DEPTH_COMPONENT16, - depth_stencil = GL_DEPTH_STENCIL, + depth32f = GL_DEPTH_COMPONENT32F, depth24_stencil8 = GL_DEPTH24_STENCIL8, depth32f_stencil8 = GL_DEPTH32F_STENCIL8, diff --git a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp index 665875e53d..06be7cab72 100644 --- a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp +++ b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp @@ -66,18 +66,23 @@ color_format rsx::internals::surface_color_format_to_gl(rsx::surface_color_forma } } -depth_format rsx::internals::surface_depth_format_to_gl(rsx::surface_depth_format depth_format) +depth_format rsx::internals::surface_depth_format_to_gl(rsx::surface_depth_format2 depth_format) { switch (depth_format) { - case rsx::surface_depth_format::z16: + case rsx::surface_depth_format2::z16_uint: return{ ::gl::texture::type::ushort, ::gl::texture::format::depth, ::gl::texture::internal_format::depth16 }; + case rsx::surface_depth_format2::z16_float: + return{ ::gl::texture::type::f16, ::gl::texture::format::depth, ::gl::texture::internal_format::depth32f }; - case rsx::surface_depth_format::z24s8: + case rsx::surface_depth_format2::z24s8_uint: if (g_cfg.video.force_high_precision_z_buffer && ::gl::get_driver_caps().ARB_depth_buffer_float_supported) return{ ::gl::texture::type::uint_24_8, ::gl::texture::format::depth_stencil, ::gl::texture::internal_format::depth32f_stencil8 }; else return{ ::gl::texture::type::uint_24_8, ::gl::texture::format::depth_stencil, ::gl::texture::internal_format::depth24_stencil8 }; + case rsx::surface_depth_format2::z24s8_float: + // TODO, requires separate aspect transfer for reading + return{ ::gl::texture::type::uint_24_8, ::gl::texture::format::depth_stencil, ::gl::texture::internal_format::depth32f_stencil8 }; default: fmt::throw_exception("Unsupported depth format 0x%x" HERE, static_cast(depth_format)); @@ -215,7 +220,6 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk { auto ds = std::get<1>(m_rtts.m_bound_depth_stencil); depth_stencil_target = ds->id(); - ds->set_depth_render_mode(!m_framebuffer_layout.depth_float); verify("Pitch mismatch!" HERE), std::get<1>(m_rtts.m_bound_depth_stencil)->get_rsx_pitch() == m_framebuffer_layout.actual_zeta_pitch; @@ -224,8 +228,7 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk m_depth_surface_info.width = m_framebuffer_layout.width; m_depth_surface_info.height = m_framebuffer_layout.height; m_depth_surface_info.depth_format = m_framebuffer_layout.depth_format; - m_depth_surface_info.depth_buffer_float = m_framebuffer_layout.depth_float; - m_depth_surface_info.bpp = (m_framebuffer_layout.depth_format == rsx::surface_depth_format::z16? 2 : 4); + m_depth_surface_info.bpp = get_format_block_size_in_bytes(m_framebuffer_layout.depth_format); m_depth_surface_info.samples = samples; m_gl_texture_cache.notify_surface_changed(m_depth_surface_info.get_memory_range(m_framebuffer_layout.aa_factors)); @@ -279,7 +282,7 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk if (depth_stencil_target) { - if (m_framebuffer_layout.depth_format == rsx::surface_depth_format::z24s8) + if (is_depth_stencil_format(m_framebuffer_layout.depth_format)) { m_draw_fbo->depth_stencil = depth_stencil_target; } diff --git a/rpcs3/Emu/RSX/GL/GLRenderTargets.h b/rpcs3/Emu/RSX/GL/GLRenderTargets.h index 728d9094cb..79b3743880 100644 --- a/rpcs3/Emu/RSX/GL/GLRenderTargets.h +++ b/rpcs3/Emu/RSX/GL/GLRenderTargets.h @@ -38,7 +38,7 @@ namespace rsx namespace internals { color_format surface_color_format_to_gl(rsx::surface_color_format color_format); - depth_format surface_depth_format_to_gl(rsx::surface_depth_format depth_format); + depth_format surface_depth_format_to_gl(rsx::surface_depth_format2 depth_format); u8 get_pixel_size(rsx::surface_depth_format format); } } @@ -166,7 +166,7 @@ struct gl_render_target_traits static std::unique_ptr create_new_surface( u32 address, - rsx::surface_depth_format surface_depth_format, + rsx::surface_depth_format2 surface_depth_format, size_t width, size_t height, size_t pitch, rsx::surface_antialiasing antialias ) @@ -178,12 +178,7 @@ struct gl_render_target_traits result->set_aa_mode(antialias); result->set_surface_dimensions(static_cast(width), static_cast(height), static_cast(pitch)); result->set_format(surface_depth_format); - - u16 native_pitch = static_cast(width) * 2 * result->samples_x; - if (surface_depth_format == rsx::surface_depth_format::z24s8) - native_pitch *= 2; - - result->set_native_pitch(native_pitch); + result->set_native_pitch(static_cast(width) * get_format_block_size_in_bytes(surface_depth_format) * result->samples_x); std::array native_layout = { GL_RED, GL_RED, GL_RED, GL_RED }; result->set_native_component_layout(native_layout); @@ -333,7 +328,7 @@ struct gl_render_target_traits static bool surface_matches_properties( const std::unique_ptr &surface, - rsx::surface_depth_format format, + rsx::surface_depth_format2 format, size_t width, size_t height, rsx::surface_antialiasing antialias, bool check_refs = false) diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.h b/rpcs3/Emu/RSX/GL/GLTextureCache.h index 3385f191e2..df7101e802 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.h +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.h @@ -960,13 +960,12 @@ namespace gl case CELL_GCM_TEXTURE_DEPTH24_D8: case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT: return (ifmt == gl::texture::internal_format::depth24_stencil8 || - ifmt == gl::texture::internal_format::depth32f_stencil8 || - ifmt == gl::texture::internal_format::depth_stencil); + ifmt == gl::texture::internal_format::depth32f_stencil8); case CELL_GCM_TEXTURE_X16: case CELL_GCM_TEXTURE_DEPTH16: case CELL_GCM_TEXTURE_DEPTH16_FLOAT: return (ifmt == gl::texture::internal_format::depth16 || - ifmt == gl::texture::internal_format::depth); + ifmt == gl::texture::internal_format::depth32f); } } diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 57ac6d15d0..31ed7cc294 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -1011,7 +1011,6 @@ namespace rsx layout.color_format = rsx::method_registers.surface_color(); layout.depth_format = rsx::method_registers.surface_depth_fmt(); - layout.depth_float = rsx::method_registers.depth_buffer_float_enabled(); layout.target = rsx::method_registers.surface_color_target(); const auto mrt_buffers = rsx::utility::get_rtt_indexes(layout.target); @@ -1020,9 +1019,9 @@ namespace rsx const u32 aa_factor_v = (aa_mode == rsx::surface_antialiasing::center_1_sample || aa_mode == rsx::surface_antialiasing::diagonal_centered_2_samples) ? 1 : 2; const u8 sample_count = get_format_sample_count(aa_mode); - const auto depth_texel_size = (layout.depth_format == rsx::surface_depth_format::z16 ? 2 : 4) * aa_factor_u; + const auto depth_texel_size = get_format_block_size_in_bytes(layout.depth_format) * aa_factor_u; const auto color_texel_size = get_format_block_size_in_bytes(layout.color_format) * aa_factor_u; - const bool stencil_test_enabled = layout.depth_format == rsx::surface_depth_format::z24s8 && rsx::method_registers.stencil_test_enabled(); + const bool stencil_test_enabled = is_depth_stencil_format(layout.depth_format) && rsx::method_registers.stencil_test_enabled(); const bool depth_test_enabled = rsx::method_registers.depth_test_enabled(); // Check write masks @@ -1301,7 +1300,6 @@ namespace rsx { if (layout.zeta_address == m_depth_surface_info.address && layout.depth_format == m_depth_surface_info.depth_format && - layout.depth_float == m_depth_surface_info.depth_buffer_float && sample_count == m_depth_surface_info.samples) { // Same target is reused @@ -1324,7 +1322,7 @@ namespace rsx { if (!m_framebuffer_layout.zeta_write_enabled && rsx::method_registers.stencil_test_enabled() && - m_framebuffer_layout.depth_format == rsx::surface_depth_format::z24s8) + is_depth_stencil_format(m_framebuffer_layout.depth_format)) { // Check if stencil data is modified auto mask = rsx::method_registers.stencil_mask(); @@ -1378,7 +1376,7 @@ namespace rsx } // Check if stencil read is enabled - if (m_framebuffer_layout.depth_format == rsx::surface_depth_format::z24s8 && + if (is_depth_stencil_format(m_framebuffer_layout.depth_format) && rsx::method_registers.stencil_test_enabled()) { return true; diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index 858d32b07b..82f9e63ef0 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -340,11 +340,10 @@ namespace rsx bool zeta_write_enabled; rsx::surface_target target; rsx::surface_color_format color_format; - rsx::surface_depth_format depth_format; + rsx::surface_depth_format2 depth_format; rsx::surface_antialiasing aa_mode; rsx::surface_raster_type raster_type; u32 aa_factors[2]; - bool depth_float; bool ignore_change; }; diff --git a/rpcs3/Emu/RSX/VK/VKFormats.cpp b/rpcs3/Emu/RSX/VK/VKFormats.cpp index 23a587a7fa..42d58b9874 100644 --- a/rpcs3/Emu/RSX/VK/VKFormats.cpp +++ b/rpcs3/Emu/RSX/VK/VKFormats.cpp @@ -42,17 +42,25 @@ namespace vk return result; } - VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format format) + VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format2 format) { switch (format) { - case rsx::surface_depth_format::z16: return VK_FORMAT_D16_UNORM; - case rsx::surface_depth_format::z24s8: + case rsx::surface_depth_format2::z16_uint: + return VK_FORMAT_D16_UNORM; + case rsx::surface_depth_format2::z16_float: + return VK_FORMAT_D32_SFLOAT; + case rsx::surface_depth_format2::z24s8_uint: { if (support.d24_unorm_s8) return VK_FORMAT_D24_UNORM_S8_UINT; if (support.d32_sfloat_s8) return VK_FORMAT_D32_SFLOAT_S8_UINT; fmt::throw_exception("No hardware support for z24s8" HERE); } + case rsx::surface_depth_format2::z24s8_float: + { + if (support.d32_sfloat_s8) return VK_FORMAT_D32_SFLOAT_S8_UINT; + fmt::throw_exception("No hardware support for z24s8_float" HERE); + } default: break; } diff --git a/rpcs3/Emu/RSX/VK/VKFormats.h b/rpcs3/Emu/RSX/VK/VKFormats.h index 86c0bfbedd..43119e397a 100644 --- a/rpcs3/Emu/RSX/VK/VKFormats.h +++ b/rpcs3/Emu/RSX/VK/VKFormats.h @@ -13,7 +13,7 @@ namespace vk VkBorderColor get_border_color(u32 color); - VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format format); + VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format2 format); VkFormat get_compatible_sampler_format(const gpu_formats_support &support, u32 format); VkFormat get_compatible_srgb_format(VkFormat rgb_format); u8 get_format_texel_width(VkFormat format); diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index 8dd2c4baf2..42a603707e 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -7,35 +7,6 @@ #include "VKResourceManager.h" #include "VKCommandStream.h" -namespace -{ - u32 get_max_depth_value(rsx::surface_depth_format format) - { - switch (format) - { - case rsx::surface_depth_format::z16: return 0xFFFF; - case rsx::surface_depth_format::z24s8: return 0xFFFFFF; - default: - ASSUME(0); - break; - } - fmt::throw_exception("Unknown depth format" HERE); - } - - u8 get_pixel_size(rsx::surface_depth_format format) - { - switch (format) - { - case rsx::surface_depth_format::z16: return 2; - case rsx::surface_depth_format::z24s8: return 4; - default: - ASSUME(0); - break; - } - fmt::throw_exception("Unknown depth format" HERE); - } -} - namespace vk { VkCompareOp get_compare_func(rsx::comparison_function op, bool reverse_direction = false); @@ -1089,7 +1060,7 @@ void VKGSRender::clear_surface(u32 mask) { u32 max_depth_value = get_max_depth_value(surface_depth_format); - u32 clear_depth = rsx::method_registers.z_clear_value(surface_depth_format == rsx::surface_depth_format::z24s8); + u32 clear_depth = rsx::method_registers.z_clear_value(is_depth_stencil_format(surface_depth_format)); float depth_clear = static_cast(clear_depth) / max_depth_value; depth_stencil_clear_values.depthStencil.depth = depth_clear; @@ -1098,7 +1069,7 @@ void VKGSRender::clear_surface(u32 mask) depth_stencil_mask |= VK_IMAGE_ASPECT_DEPTH_BIT; } - if (surface_depth_format == rsx::surface_depth_format::z24s8) + if (is_depth_stencil_format(surface_depth_format)) { if (mask & 0x2) { @@ -2067,8 +2038,7 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context) m_depth_surface_info.width = m_framebuffer_layout.width; m_depth_surface_info.height = m_framebuffer_layout.height; m_depth_surface_info.depth_format = m_framebuffer_layout.depth_format; - m_depth_surface_info.depth_buffer_float = m_framebuffer_layout.depth_float; - m_depth_surface_info.bpp = (m_framebuffer_layout.depth_format == rsx::surface_depth_format::z16? 2 : 4); + m_depth_surface_info.bpp = get_format_block_size_in_bytes(m_framebuffer_layout.depth_format); m_depth_surface_info.samples = samples; } @@ -2095,7 +2065,6 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context) if (std::get<0>(m_rtts.m_bound_depth_stencil) != 0) { auto ds = std::get<1>(m_rtts.m_bound_depth_stencil); - ds->set_depth_render_mode(!m_framebuffer_layout.depth_float); m_fbo_images.push_back(ds); m_depth_surface_info.address = m_framebuffer_layout.zeta_address; diff --git a/rpcs3/Emu/RSX/VK/VKRenderTargets.h b/rpcs3/Emu/RSX/VK/VKRenderTargets.h index c7d8e85794..6b7acd3d78 100644 --- a/rpcs3/Emu/RSX/VK/VKRenderTargets.h +++ b/rpcs3/Emu/RSX/VK/VKRenderTargets.h @@ -692,7 +692,7 @@ namespace rsx static std::unique_ptr create_new_surface( u32 address, - surface_depth_format format, + surface_depth_format2 format, size_t width, size_t height, size_t pitch, rsx::surface_antialiasing antialias, vk::render_device &device, vk::command_buffer& cmd) @@ -738,11 +738,7 @@ namespace rsx ds->memory_usage_flags= rsx::surface_usage_flags::attachment; ds->state_flags = rsx::surface_state_flags::erase_bkgnd; ds->native_component_map = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R }; - - ds->native_pitch = static_cast(width) * 2 * ds->samples_x; - if (format == rsx::surface_depth_format::z24s8) - ds->native_pitch *= 2; - + ds->native_pitch = static_cast(width) * get_format_block_size_in_bytes(format) * ds->samples_x; ds->rsx_pitch = static_cast(pitch); ds->surface_width = static_cast(width); ds->surface_height = static_cast(height); @@ -911,7 +907,7 @@ namespace rsx static bool surface_matches_properties( const std::unique_ptr &surface, - surface_depth_format format, + surface_depth_format2 format, size_t width, size_t height, rsx::surface_antialiasing antialias, bool check_refs = false) diff --git a/rpcs3/Emu/RSX/gcm_enums.h b/rpcs3/Emu/RSX/gcm_enums.h index e43b7bf1fe..60917ddb6f 100644 --- a/rpcs3/Emu/RSX/gcm_enums.h +++ b/rpcs3/Emu/RSX/gcm_enums.h @@ -53,12 +53,53 @@ namespace rsx enum class surface_depth_format : u8 { - z16, // unsigned 16 bits depth - z24s8, // unsigned 24 bits depth + 8 bits stencil + z16, // typeless 16 bits depth + z24s8, // typeless 24 bits depth + 8 bits stencil + }; + + enum class surface_depth_format2 : u8 + { + z16_uint, // unsigned 16 bits depth + z24s8_uint, // unsigned 24 bits depth + 8 bits stencil + z16_float, // floating point 16 bits depth + z24s8_float, // floating point 24 bits depth + 8 bits stencil }; surface_depth_format to_surface_depth_format(u8 in); + constexpr + bool operator == (surface_depth_format2 rhs, surface_depth_format lhs) + { + switch (lhs) + { + case surface_depth_format::z16: + return (rhs == surface_depth_format2::z16_uint || rhs == surface_depth_format2::z16_float); + case surface_depth_format::z24s8: + return (rhs == surface_depth_format2::z24s8_uint || rhs == surface_depth_format2::z24s8_float); + default: + ASSUME(0); + } + } + + // GCC requires every operator declared explicitly + constexpr + bool operator == (surface_depth_format rhs, surface_depth_format2 lhs) + { + return lhs == rhs; + } + + constexpr + bool operator != (surface_depth_format2 rhs, surface_depth_format lhs) + { + return !(rhs == lhs); + } + + constexpr + bool operator != (surface_depth_format rhs, surface_depth_format2 lhs) + { + return !(lhs == rhs); + } + enum class surface_raster_type : u8 { undefined = 0, diff --git a/rpcs3/Emu/RSX/rsx_methods.h b/rpcs3/Emu/RSX/rsx_methods.h index e73b7cd933..4a045a7393 100644 --- a/rpcs3/Emu/RSX/rsx_methods.h +++ b/rpcs3/Emu/RSX/rsx_methods.h @@ -1310,9 +1310,17 @@ namespace rsx return decode().color_fmt(); } - surface_depth_format surface_depth_fmt() const + surface_depth_format2 surface_depth_fmt() const { - return decode().depth_fmt(); + const auto base_fmt = decode().depth_fmt(); + if (!depth_buffer_float_enabled()) [[likely]] + { + return static_cast(base_fmt); + } + + return base_fmt == surface_depth_format::z16 ? + surface_depth_format2::z16_float : + surface_depth_format2::z24s8_float; } surface_raster_type surface_type() const @@ -1640,57 +1648,57 @@ namespace rsx registers[NV4097_SET_TRANSFORM_PROGRAM_LOAD] = value; } - u32 transform_constant_load() + u32 transform_constant_load() const { return registers[NV4097_SET_TRANSFORM_CONSTANT_LOAD]; } - u32 transform_branch_bits() + u32 transform_branch_bits() const { return registers[NV4097_SET_TRANSFORM_BRANCH_BITS]; } - u16 msaa_sample_mask() + u16 msaa_sample_mask() const { return decode().msaa_sample_mask(); } - bool msaa_enabled() + bool msaa_enabled() const { return decode().msaa_enabled(); } - bool msaa_alpha_to_coverage_enabled() + bool msaa_alpha_to_coverage_enabled() const { return decode().msaa_alpha_to_coverage(); } - bool msaa_alpha_to_one_enabled() + bool msaa_alpha_to_one_enabled() const { return decode().msaa_alpha_to_one(); } - bool depth_clamp_enabled() + bool depth_clamp_enabled() const { return decode().depth_clamp_enabled(); } - bool depth_clip_enabled() + bool depth_clip_enabled() const { return decode().depth_clip_enabled(); } - bool depth_clip_ignore_w() + bool depth_clip_ignore_w() const { return decode().depth_clip_ignore_w(); } - bool framebuffer_srgb_enabled() + bool framebuffer_srgb_enabled() const { return decode().srgb_output_enabled(); } - bool depth_buffer_float_enabled() + bool depth_buffer_float_enabled() const { return decode().depth_float(); } diff --git a/rpcs3/Emu/RSX/rsx_utils.h b/rpcs3/Emu/RSX/rsx_utils.h index ed80b6120b..6076ed5bed 100644 --- a/rpcs3/Emu/RSX/rsx_utils.h +++ b/rpcs3/Emu/RSX/rsx_utils.h @@ -114,8 +114,7 @@ namespace rsx u32 pitch = 0; rsx::surface_color_format color_format; - rsx::surface_depth_format depth_format; - bool depth_buffer_float; + rsx::surface_depth_format2 depth_format; u16 width = 0; u16 height = 0;