From ea08178dde98bb4aee85ae7b1a7263928125e40e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 1 May 2020 05:52:45 -0400 Subject: [PATCH 1/5] gl_rasterizer: Remove unused emu_window variable in RasterizerOpenGL Silences an unused private variable warning. --- src/video_core/renderer_base.cpp | 2 +- src/video_core/renderer_opengl/gl_rasterizer.cpp | 7 +++---- src/video_core/renderer_opengl/gl_rasterizer.h | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp index 8d18b6800..48a3601c2 100644 --- a/src/video_core/renderer_base.cpp +++ b/src/video_core/renderer_base.cpp @@ -22,7 +22,7 @@ void RendererBase::RefreshRasterizerSetting() { opengl_rasterizer_active = hw_renderer_enabled; if (hw_renderer_enabled) { - rasterizer = std::make_unique(render_window); + rasterizer = std::make_unique(); } else { rasterizer = std::make_unique(); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index b2fd23ff7..92b99eee5 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -44,12 +44,11 @@ static bool IsVendorAmd() { return gpu_vendor == "ATI Technologies Inc." || gpu_vendor == "Advanced Micro Devices, Inc."; } -RasterizerOpenGL::RasterizerOpenGL(Frontend::EmuWindow& window) - : is_amd(IsVendorAmd()), shader_dirty(true), - vertex_buffer(GL_ARRAY_BUFFER, VERTEX_BUFFER_SIZE, is_amd), +RasterizerOpenGL::RasterizerOpenGL() + : is_amd(IsVendorAmd()), vertex_buffer(GL_ARRAY_BUFFER, VERTEX_BUFFER_SIZE, is_amd), uniform_buffer(GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE, false), index_buffer(GL_ELEMENT_ARRAY_BUFFER, INDEX_BUFFER_SIZE, false), - texture_buffer(GL_TEXTURE_BUFFER, TEXTURE_BUFFER_SIZE, false), emu_window{window} { + texture_buffer(GL_TEXTURE_BUFFER, TEXTURE_BUFFER_SIZE, false) { allow_shadow = GLAD_GL_ARB_shader_image_load_store && GLAD_GL_ARB_shader_image_size && GLAD_GL_ARB_framebuffer_no_attachments; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 11b479486..bfddef4d9 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -38,7 +38,7 @@ class ShaderProgramManager; class RasterizerOpenGL : public VideoCore::RasterizerInterface { public: - explicit RasterizerOpenGL(Frontend::EmuWindow& renderer); + explicit RasterizerOpenGL(); ~RasterizerOpenGL() override; void LoadDiskResources(const std::atomic_bool& stop_loading, @@ -268,11 +268,9 @@ private: RasterizerCacheOpenGL res_cache; - Frontend::EmuWindow& emu_window; - std::vector vertex_batch; - bool shader_dirty; + bool shader_dirty = true; struct { UniformData data; From de140a587063fe2d5de57ca080d4a8ad69cb95d2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 1 May 2020 05:53:40 -0400 Subject: [PATCH 2/5] gl_rasterizer: Default destructor in the cpp file --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 92b99eee5..d6200c4d0 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -168,7 +168,7 @@ RasterizerOpenGL::RasterizerOpenGL() SyncEntireState(); } -RasterizerOpenGL::~RasterizerOpenGL() {} +RasterizerOpenGL::~RasterizerOpenGL() = default; void RasterizerOpenGL::LoadDiskResources(const std::atomic_bool& stop_loading, const VideoCore::DiskResourceLoadCallback& callback) { From df97021f55b873c6e7c251277e72c2c8fd9e6d9f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 1 May 2020 05:54:47 -0400 Subject: [PATCH 3/5] gl_rasterizer: Make use of std::string_view in IsVendorAmd() Same behavior, no heap allocation. strings returned from glGetString() are guaranteed to be static strings, so this is safe to do. They're also guaranteed to be null-terminated. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index d6200c4d0..44ca9d4b1 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -40,7 +40,7 @@ MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255)); MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); static bool IsVendorAmd() { - std::string gpu_vendor{reinterpret_cast(glGetString(GL_VENDOR))}; + const std::string_view gpu_vendor{reinterpret_cast(glGetString(GL_VENDOR))}; return gpu_vendor == "ATI Technologies Inc." || gpu_vendor == "Advanced Micro Devices, Inc."; } From 81768bf0c235debe60513bcd59fca65e59c233bf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 1 May 2020 05:59:20 -0400 Subject: [PATCH 4/5] gl_rasterizer: Resolve truncation warnings --- src/video_core/regs_shader.h | 8 +-- .../renderer_opengl/gl_rasterizer.cpp | 54 ++++++++++--------- .../renderer_opengl/gl_rasterizer.h | 3 +- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/video_core/regs_shader.h b/src/video_core/regs_shader.h index c15d4d162..71aa9d11a 100644 --- a/src/video_core/regs_shader.h +++ b/src/video_core/regs_shader.h @@ -43,10 +43,10 @@ struct ShaderRegs { u32 input_attribute_to_register_map_low; u32 input_attribute_to_register_map_high; - unsigned int GetRegisterForAttribute(unsigned int attribute_index) const { - u64 map = ((u64)input_attribute_to_register_map_high << 32) | - (u64)input_attribute_to_register_map_low; - return (map >> (attribute_index * 4)) & 0b1111; + u32 GetRegisterForAttribute(std::size_t attribute_index) const { + const u64 map = (static_cast(input_attribute_to_register_map_high) << 32) | + static_cast(input_attribute_to_register_map_low); + return static_cast((map >> (attribute_index * 4)) & 0b1111); } BitField<0, 16, u32> output_mask; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 44ca9d4b1..4d4f8981e 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -271,17 +271,17 @@ RasterizerOpenGL::VertexArrayInfo RasterizerOpenGL::AnalyzeVertexArray(bool is_i u32 vertex_max; if (is_indexed) { const auto& index_info = regs.pipeline.index_array; - PAddr address = vertex_attributes.GetPhysicalBaseAddress() + index_info.offset; + const PAddr address = vertex_attributes.GetPhysicalBaseAddress() + index_info.offset; const u8* index_address_8 = VideoCore::g_memory->GetPhysicalPointer(address); const u16* index_address_16 = reinterpret_cast(index_address_8); - bool index_u16 = index_info.format != 0; + const bool index_u16 = index_info.format != 0; vertex_min = 0xFFFF; vertex_max = 0; - std::size_t size = regs.pipeline.num_vertices * (index_u16 ? 2 : 1); + const u32 size = regs.pipeline.num_vertices * (index_u16 ? 2 : 1); res_cache.FlushRegion(address, size, nullptr); for (u32 index = 0; index < regs.pipeline.num_vertices; ++index) { - u32 vertex = index_u16 ? index_address_16[index] : index_address_8[index]; + const u32 vertex = index_u16 ? index_address_16[index] : index_address_8[index]; vertex_min = std::min(vertex_min, vertex); vertex_max = std::max(vertex_max, vertex); } @@ -362,15 +362,15 @@ void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset, for (std::size_t i = 0; i < enable_attributes.size(); ++i) { if (enable_attributes[i] != hw_vao_enabled_attributes[i]) { if (enable_attributes[i]) { - glEnableVertexAttribArray(i); + glEnableVertexAttribArray(static_cast(i)); } else { - glDisableVertexAttribArray(i); + glDisableVertexAttribArray(static_cast(i)); } hw_vao_enabled_attributes[i] = enable_attributes[i]; } if (vertex_attributes.IsDefaultAttribute(i)) { - u32 reg = regs.vs.GetRegisterForAttribute(i); + const u32 reg = regs.vs.GetRegisterForAttribute(i); if (!enable_attributes[reg]) { const auto& attr = Pica::g_state.input_default_attributes.attr[i]; glVertexAttrib4f(reg, attr.x.ToFloat32(), attr.y.ToFloat32(), attr.z.ToFloat32(), @@ -797,15 +797,16 @@ bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) { std::size_t max_vertices = 3 * (VERTEX_BUFFER_SIZE / (3 * sizeof(HardwareVertex))); for (std::size_t base_vertex = 0; base_vertex < vertex_batch.size(); base_vertex += max_vertices) { - std::size_t vertices = std::min(max_vertices, vertex_batch.size() - base_vertex); - std::size_t vertex_size = vertices * sizeof(HardwareVertex); + const std::size_t vertices = std::min(max_vertices, vertex_batch.size() - base_vertex); + const std::size_t vertex_size = vertices * sizeof(HardwareVertex); u8* vbo; GLintptr offset; std::tie(vbo, offset, std::ignore) = vertex_buffer.Map(vertex_size, sizeof(HardwareVertex)); std::memcpy(vbo, vertex_batch.data() + base_vertex, vertex_size); vertex_buffer.Unmap(vertex_size); - glDrawArrays(GL_TRIANGLES, offset / sizeof(HardwareVertex), (GLsizei)vertices); + glDrawArrays(GL_TRIANGLES, static_cast(offset / sizeof(HardwareVertex)), + static_cast(vertices)); } } @@ -1563,8 +1564,8 @@ void RasterizerOpenGL::SamplerInfo::Create() { // default is 1000 and -1000 // Other attributes have correct defaults - glSamplerParameterf(sampler.handle, GL_TEXTURE_MAX_LOD, lod_max); - glSamplerParameterf(sampler.handle, GL_TEXTURE_MIN_LOD, lod_min); + glSamplerParameterf(sampler.handle, GL_TEXTURE_MAX_LOD, static_cast(lod_max)); + glSamplerParameterf(sampler.handle, GL_TEXTURE_MIN_LOD, static_cast(lod_min)); } void RasterizerOpenGL::SamplerInfo::SyncWithConfig( @@ -1614,12 +1615,12 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig( if (lod_min != config.lod.min_level) { lod_min = config.lod.min_level; - glSamplerParameterf(s, GL_TEXTURE_MIN_LOD, lod_min); + glSamplerParameterf(s, GL_TEXTURE_MIN_LOD, static_cast(lod_min)); } if (lod_max != config.lod.max_level) { lod_max = config.lod.max_level; - glSamplerParameterf(s, GL_TEXTURE_MAX_LOD, lod_max); + glSamplerParameterf(s, GL_TEXTURE_MAX_LOD, static_cast(lod_max)); } if (!GLES && lod_bias != config.lod.bias) { @@ -1836,13 +1837,16 @@ void RasterizerOpenGL::SyncCombinerColor() { } } -void RasterizerOpenGL::SyncTevConstColor(int stage_index, +void RasterizerOpenGL::SyncTevConstColor(std::size_t stage_index, const Pica::TexturingRegs::TevStageConfig& tev_stage) { - auto const_color = PicaToGL::ColorRGBA8(tev_stage.const_color); - if (const_color != uniform_block_data.data.const_color[stage_index]) { - uniform_block_data.data.const_color[stage_index] = const_color; - uniform_block_data.dirty = true; + const auto const_color = PicaToGL::ColorRGBA8(tev_stage.const_color); + + if (const_color == uniform_block_data.data.const_color[stage_index]) { + return; } + + uniform_block_data.data.const_color[stage_index] = const_color; + uniform_block_data.dirty = true; } void RasterizerOpenGL::SyncGlobalAmbient() { @@ -1989,7 +1993,7 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2)); uniform_block_data.data.lighting_lut_offset[index / 4][index % 4] = - (offset + bytes_used) / sizeof(GLvec2); + static_cast((offset + bytes_used) / sizeof(GLvec2)); uniform_block_data.dirty = true; bytes_used += new_data.size() * sizeof(GLvec2); } @@ -2011,7 +2015,8 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { if (new_data != fog_lut_data || invalidate) { fog_lut_data = new_data; std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2)); - uniform_block_data.data.fog_lut_offset = (offset + bytes_used) / sizeof(GLvec2); + uniform_block_data.data.fog_lut_offset = + static_cast((offset + bytes_used) / sizeof(GLvec2)); uniform_block_data.dirty = true; bytes_used += new_data.size() * sizeof(GLvec2); } @@ -2030,7 +2035,7 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { if (new_data != lut_data || invalidate) { lut_data = new_data; std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2)); - lut_offset = (offset + bytes_used) / sizeof(GLvec2); + lut_offset = static_cast((offset + bytes_used) / sizeof(GLvec2)); uniform_block_data.dirty = true; bytes_used += new_data.size() * sizeof(GLvec2); } @@ -2071,7 +2076,8 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { if (new_data != proctex_lut_data || invalidate) { proctex_lut_data = new_data; std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec4)); - uniform_block_data.data.proctex_lut_offset = (offset + bytes_used) / sizeof(GLvec4); + uniform_block_data.data.proctex_lut_offset = + static_cast((offset + bytes_used) / sizeof(GLvec4)); uniform_block_data.dirty = true; bytes_used += new_data.size() * sizeof(GLvec4); } @@ -2093,7 +2099,7 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { proctex_diff_lut_data = new_data; std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec4)); uniform_block_data.data.proctex_diff_lut_offset = - (offset + bytes_used) / sizeof(GLvec4); + static_cast((offset + bytes_used) / sizeof(GLvec4)); uniform_block_data.dirty = true; bytes_used += new_data.size() * sizeof(GLvec4); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index bfddef4d9..a28e9bda1 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -195,7 +195,8 @@ private: void SyncCombinerColor(); /// Syncs the TEV constant color to match the PICA register - void SyncTevConstColor(int tev_index, const Pica::TexturingRegs::TevStageConfig& tev_stage); + void SyncTevConstColor(std::size_t tev_index, + const Pica::TexturingRegs::TevStageConfig& tev_stage); /// Syncs the lighting global ambient color to match the PICA register void SyncGlobalAmbient(); From 763778e6c0bd6aaf2bd2f71a4d49f57d670816d4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 1 May 2020 06:19:18 -0400 Subject: [PATCH 5/5] gl_rasterizer: Make const on references consistent Applies const to auto& instances that would actually resolve to a const reference for readability and explicitness. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 4d4f8981e..b86683ef9 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -290,9 +290,9 @@ RasterizerOpenGL::VertexArrayInfo RasterizerOpenGL::AnalyzeVertexArray(bool is_i vertex_max = regs.pipeline.vertex_offset + regs.pipeline.num_vertices - 1; } - u32 vertex_num = vertex_max - vertex_min + 1; + const u32 vertex_num = vertex_max - vertex_min + 1; u32 vs_input_size = 0; - for (auto& loader : vertex_attributes.attribute_loaders) { + for (const auto& loader : vertex_attributes.attribute_loaders) { if (loader.component_count != 0) { vs_input_size += loader.byte_count * vertex_num; } @@ -1338,7 +1338,7 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { case PICA_REG_INDEX(lighting.lut_data[5]): case PICA_REG_INDEX(lighting.lut_data[6]): case PICA_REG_INDEX(lighting.lut_data[7]): { - auto& lut_config = regs.lighting.lut_config; + const auto& lut_config = regs.lighting.lut_config; uniform_block_data.lighting_lut_dirty[lut_config.type] = true; uniform_block_data.lighting_lut_dirty_any = true; break;