From ffeb4ef83e731bb54a82080749ca22a263466788 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 23 Sep 2020 15:06:21 -0400 Subject: [PATCH 1/3] shader/registry: Make use of designated initializers where applicable Same behavior, less repetition. --- src/video_core/shader/registry.cpp | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/video_core/shader/registry.cpp b/src/video_core/shader/registry.cpp index cdf274e544..de9a3df903 100644 --- a/src/video_core/shader/registry.cpp +++ b/src/video_core/shader/registry.cpp @@ -24,31 +24,33 @@ GraphicsInfo MakeGraphicsInfo(ShaderType shader_stage, ConstBufferEngineInterfac if (shader_stage == ShaderType::Compute) { return {}; } - auto& graphics = static_cast(engine); - GraphicsInfo info; - info.tfb_layouts = graphics.regs.tfb_layouts; - info.tfb_varying_locs = graphics.regs.tfb_varying_locs; - info.primitive_topology = graphics.regs.draw.topology; - info.tessellation_primitive = graphics.regs.tess_mode.prim; - info.tessellation_spacing = graphics.regs.tess_mode.spacing; - info.tfb_enabled = graphics.regs.tfb_enabled; - info.tessellation_clockwise = graphics.regs.tess_mode.cw; - return info; + auto& graphics = dynamic_cast(engine); + + return { + .tfb_layouts = graphics.regs.tfb_layouts, + .tfb_varying_locs = graphics.regs.tfb_varying_locs, + .primitive_topology = graphics.regs.draw.topology, + .tessellation_primitive = graphics.regs.tess_mode.prim, + .tessellation_spacing = graphics.regs.tess_mode.spacing, + .tfb_enabled = graphics.regs.tfb_enabled != 0, + .tessellation_clockwise = graphics.regs.tess_mode.cw.Value() != 0, + }; } ComputeInfo MakeComputeInfo(ShaderType shader_stage, ConstBufferEngineInterface& engine) { if (shader_stage != ShaderType::Compute) { return {}; } - auto& compute = static_cast(engine); + + auto& compute = dynamic_cast(engine); const auto& launch = compute.launch_description; - ComputeInfo info; - info.workgroup_size = {launch.block_dim_x, launch.block_dim_y, launch.block_dim_z}; - info.local_memory_size_in_words = launch.local_pos_alloc; - info.shared_memory_size_in_words = launch.shared_alloc; - return info; + return { + .workgroup_size = {launch.block_dim_x, launch.block_dim_y, launch.block_dim_z}, + .shared_memory_size_in_words = launch.shared_alloc, + .local_memory_size_in_words = launch.local_pos_alloc, + }; } } // Anonymous namespace From cd6f4f7eed24d8562fbc8daec424e5a816ce6233 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 23 Sep 2020 15:08:31 -0400 Subject: [PATCH 2/3] shader/registry: Remove unnecessary namespace qualifiers Using statements already make these unnecessary. --- src/video_core/shader/registry.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/video_core/shader/registry.cpp b/src/video_core/shader/registry.cpp index de9a3df903..3cf922002b 100644 --- a/src/video_core/shader/registry.cpp +++ b/src/video_core/shader/registry.cpp @@ -55,12 +55,11 @@ ComputeInfo MakeComputeInfo(ShaderType shader_stage, ConstBufferEngineInterface& } // Anonymous namespace -Registry::Registry(Tegra::Engines::ShaderType shader_stage, const SerializedRegistryInfo& info) +Registry::Registry(ShaderType shader_stage, const SerializedRegistryInfo& info) : stage{shader_stage}, stored_guest_driver_profile{info.guest_driver_profile}, bound_buffer{info.bound_buffer}, graphics_info{info.graphics}, compute_info{info.compute} {} -Registry::Registry(Tegra::Engines::ShaderType shader_stage, - Tegra::Engines::ConstBufferEngineInterface& engine) +Registry::Registry(ShaderType shader_stage, ConstBufferEngineInterface& engine) : stage{shader_stage}, engine{&engine}, bound_buffer{engine.GetBoundBuffer()}, graphics_info{MakeGraphicsInfo(shader_stage, engine)}, compute_info{MakeComputeInfo( shader_stage, engine)} {} @@ -115,8 +114,7 @@ std::optional Registry::ObtainSeparateSampler return value; } -std::optional Registry::ObtainBindlessSampler(u32 buffer, - u32 offset) { +std::optional Registry::ObtainBindlessSampler(u32 buffer, u32 offset) { const std::pair key = {buffer, offset}; const auto iter = bindless_samplers.find(key); if (iter != bindless_samplers.end()) { From 77532ebde3be78aa9a5471c496784d0151453289 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 23 Sep 2020 15:10:25 -0400 Subject: [PATCH 3/3] shader/registry: Silence a -Wshadow warning --- src/video_core/shader/registry.cpp | 8 ++++---- src/video_core/shader/registry.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/video_core/shader/registry.cpp b/src/video_core/shader/registry.cpp index 3cf922002b..148d91fcb0 100644 --- a/src/video_core/shader/registry.cpp +++ b/src/video_core/shader/registry.cpp @@ -59,10 +59,10 @@ Registry::Registry(ShaderType shader_stage, const SerializedRegistryInfo& info) : stage{shader_stage}, stored_guest_driver_profile{info.guest_driver_profile}, bound_buffer{info.bound_buffer}, graphics_info{info.graphics}, compute_info{info.compute} {} -Registry::Registry(ShaderType shader_stage, ConstBufferEngineInterface& engine) - : stage{shader_stage}, engine{&engine}, bound_buffer{engine.GetBoundBuffer()}, - graphics_info{MakeGraphicsInfo(shader_stage, engine)}, compute_info{MakeComputeInfo( - shader_stage, engine)} {} +Registry::Registry(ShaderType shader_stage, ConstBufferEngineInterface& engine_) + : stage{shader_stage}, engine{&engine_}, bound_buffer{engine_.GetBoundBuffer()}, + graphics_info{MakeGraphicsInfo(shader_stage, engine_)}, compute_info{MakeComputeInfo( + shader_stage, engine_)} {} Registry::~Registry() = default; diff --git a/src/video_core/shader/registry.h b/src/video_core/shader/registry.h index 2312067657..4bebefdde5 100644 --- a/src/video_core/shader/registry.h +++ b/src/video_core/shader/registry.h @@ -94,7 +94,7 @@ public: explicit Registry(Tegra::Engines::ShaderType shader_stage, const SerializedRegistryInfo& info); explicit Registry(Tegra::Engines::ShaderType shader_stage, - Tegra::Engines::ConstBufferEngineInterface& engine); + Tegra::Engines::ConstBufferEngineInterface& engine_); ~Registry();