From d320eef663c8f2ba3b0dd2cd43f0b25f5c10c42b Mon Sep 17 00:00:00 2001 From: Vitor K Date: Fri, 6 Jan 2023 04:05:21 -0300 Subject: [PATCH] Fix opengl and auto resolution crashes (#14) * video_core: fix UniformData size on opengl * video_core: check for renderer on auto resolution The rasterizer cache constructor will call GetResolutionScaleFactor before the renderer is initialized on the vulkan backend, so check for that case and return 1 as a placeholder scale factor. --- src/video_core/renderer_opengl/gl_shader_manager.h | 3 ++- src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp | 2 +- src/video_core/shader/shader_uniforms.h | 2 +- src/video_core/video_core.cpp | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index 89921f61f..0c6ddb7c3 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -75,10 +75,11 @@ struct UniformData { LightSrc light_src[8]; alignas(16) Common::Vec4f const_color[6]; // A vec4 color for each of the six tev stages alignas(16) Common::Vec4f tev_combiner_buffer_color; + alignas(16) Common::Vec3f tex_lod_bias; alignas(16) Common::Vec4f clip_coef; }; -static_assert(sizeof(UniformData) == 0x4F0, +static_assert(sizeof(UniformData) == 0x500, "The size of the UniformData does not match the structure in the shader"); static_assert(sizeof(UniformData) < 16384, "UniformData structure must be less than 16kb as per the OpenGL spec"); diff --git a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp index eb65bde64..fef8bfaf9 100644 --- a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp @@ -1344,7 +1344,7 @@ void FragmentModule::DefineUniformStructs() { i32_id, i32_id, f32_id, f32_id, f32_id, f32_id, i32_id, i32_id, i32_id, i32_id, i32_id, i32_id, i32_id, i32_id, i32_id, i32_id, f32_id, i32_id, u32_id, lighting_lut_array_id, vec_ids.Get(3), vec_ids.Get(2), vec_ids.Get(2), vec_ids.Get(2), vec_ids.Get(3), - light_src_array_id, const_color_array_id, vec_ids.Get(4), vec_ids.Get(4), vec_ids.Get(3))}; + light_src_array_id, const_color_array_id, vec_ids.Get(4), vec_ids.Get(3), vec_ids.Get(4))}; constexpr std::array light_src_offsets{0u, 16u, 32u, 48u, 64u, 80u, 92u, 96u}; constexpr std::array shader_data_offsets{ diff --git a/src/video_core/shader/shader_uniforms.h b/src/video_core/shader/shader_uniforms.h index f10fb11ba..da7b44337 100644 --- a/src/video_core/shader/shader_uniforms.h +++ b/src/video_core/shader/shader_uniforms.h @@ -63,8 +63,8 @@ struct UniformData { LightSrc light_src[8]; alignas(16) Common::Vec4f const_color[6]; // A vec4 color for each of the six tev stages alignas(16) Common::Vec4f tev_combiner_buffer_color; - alignas(16) Common::Vec4f clip_coef; alignas(16) Common::Vec3f tex_lod_bias; + alignas(16) Common::Vec4f clip_coef; }; static_assert(sizeof(UniformData) == 0x500, diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 273085237..a42bc5c0d 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -93,7 +93,7 @@ void RequestScreenshot(void* data, std::function callback, } u16 GetResolutionScaleFactor() { - if (g_hw_renderer_enabled) { + if (g_hw_renderer_enabled && g_renderer) { return Settings::values.resolution_factor.GetValue() ? Settings::values.resolution_factor.GetValue() : g_renderer->GetRenderWindow().GetFramebufferLayout().GetScalingRatio();