summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar ameerj2021-10-16 00:30:43 -0400
committerGravatar Fernando Sahmkow2021-11-16 22:11:31 +0100
commit618de4e7871898f165c028293becd235ce3ccb09 (patch)
treea41f25c847177f4f5d8c6ce8da5651f71f7418a5 /src/video_core
parentTexture Cahe: Fix downscaling on SMO. (diff)
downloadyuzu-618de4e7871898f165c028293becd235ce3ccb09.tar.gz
yuzu-618de4e7871898f165c028293becd235ce3ccb09.tar.xz
yuzu-618de4e7871898f165c028293becd235ce3ccb09.zip
vulkan: Fix rescaling push constant usage
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_vulkan/pipeline_helper.h25
-rw-r--r--src/video_core/renderer_vulkan/vk_compute_pipeline.cpp36
-rw-r--r--src/video_core/renderer_vulkan/vk_compute_pipeline.h1
-rw-r--r--src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp15
4 files changed, 42 insertions, 35 deletions
diff --git a/src/video_core/renderer_vulkan/pipeline_helper.h b/src/video_core/renderer_vulkan/pipeline_helper.h
index 3612e8a18..ae5e66ef4 100644
--- a/src/video_core/renderer_vulkan/pipeline_helper.h
+++ b/src/video_core/renderer_vulkan/pipeline_helper.h
@@ -22,7 +22,6 @@
22namespace Vulkan { 22namespace Vulkan {
23 23
24using Shader::Backend::SPIRV::NUM_TEXTURE_AND_IMAGE_SCALING_WORDS; 24using Shader::Backend::SPIRV::NUM_TEXTURE_AND_IMAGE_SCALING_WORDS;
25using Shader::Backend::SPIRV::RESCALING_PUSH_CONSTANT_WORDS_OFFSET;
26 25
27class DescriptorLayoutBuilder { 26class DescriptorLayoutBuilder {
28public: 27public:
@@ -73,12 +72,12 @@ public:
73 72
74 vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const { 73 vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const {
75 using Shader::Backend::SPIRV::RescalingLayout; 74 using Shader::Backend::SPIRV::RescalingLayout;
76 const u32 push_offset = is_compute ? RESCALING_PUSH_CONSTANT_WORDS_OFFSET : 0; 75 const u32 size_offset = is_compute ? sizeof(RescalingLayout::down_factor) : 0u;
77 const VkPushConstantRange range{ 76 const VkPushConstantRange range{
78 .stageFlags = static_cast<VkShaderStageFlags>( 77 .stageFlags = static_cast<VkShaderStageFlags>(
79 is_compute ? VK_SHADER_STAGE_COMPUTE_BIT : VK_SHADER_STAGE_ALL_GRAPHICS), 78 is_compute ? VK_SHADER_STAGE_COMPUTE_BIT : VK_SHADER_STAGE_ALL_GRAPHICS),
80 .offset = 0, 79 .offset = 0,
81 .size = sizeof(RescalingLayout) - push_offset, 80 .size = sizeof(RescalingLayout) - size_offset,
82 }; 81 };
83 return device->GetLogical().CreatePipelineLayout({ 82 return device->GetLogical().CreatePipelineLayout({
84 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, 83 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
@@ -139,21 +138,21 @@ private:
139 138
140class RescalingPushConstant { 139class RescalingPushConstant {
141public: 140public:
142 explicit RescalingPushConstant(u32 num_textures) noexcept {} 141 explicit RescalingPushConstant() noexcept {}
143 142
144 void PushTexture(bool is_rescaled) noexcept { 143 void PushTexture(bool is_rescaled) noexcept {
145 *texture_ptr |= is_rescaled ? texture_bit : 0; 144 *texture_ptr |= is_rescaled ? texture_bit : 0u;
146 texture_bit <<= 1; 145 texture_bit <<= 1u;
147 if (texture_bit == 0) { 146 if (texture_bit == 0u) {
148 texture_bit = 1u; 147 texture_bit = 1u;
149 ++texture_ptr; 148 ++texture_ptr;
150 } 149 }
151 } 150 }
152 151
153 void PushImage(bool is_rescaled) noexcept { 152 void PushImage(bool is_rescaled) noexcept {
154 *image_ptr |= is_rescaled ? image_bit : 0; 153 *image_ptr |= is_rescaled ? image_bit : 0u;
155 image_bit <<= 1; 154 image_bit <<= 1u;
156 if (image_bit == 0) { 155 if (image_bit == 0u) {
157 image_bit = 1u; 156 image_bit = 1u;
158 ++image_ptr; 157 ++image_ptr;
159 } 158 }
@@ -176,8 +175,10 @@ inline void PushImageDescriptors(TextureCache& texture_cache,
176 const Shader::Info& info, RescalingPushConstant& rescaling, 175 const Shader::Info& info, RescalingPushConstant& rescaling,
177 const VkSampler*& samplers, 176 const VkSampler*& samplers,
178 const VideoCommon::ImageViewInOut*& views) { 177 const VideoCommon::ImageViewInOut*& views) {
179 views += Shader::NumDescriptors(info.texture_buffer_descriptors); 178 const u32 num_texture_buffers = Shader::NumDescriptors(info.texture_buffer_descriptors);
180 views += Shader::NumDescriptors(info.image_buffer_descriptors); 179 const u32 num_image_buffers = Shader::NumDescriptors(info.image_buffer_descriptors);
180 views += num_texture_buffers;
181 views += num_image_buffers;
181 for (const auto& desc : info.texture_descriptors) { 182 for (const auto& desc : info.texture_descriptors) {
182 for (u32 index = 0; index < desc.count; ++index) { 183 for (u32 index = 0; index < desc.count; ++index) {
183 const VideoCommon::ImageViewId image_view_id{(views++)->id}; 184 const VideoCommon::ImageViewId image_view_id{(views++)->id};
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
index 6dc52e399..de36bcdb7 100644
--- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
+++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
@@ -22,6 +22,7 @@
22namespace Vulkan { 22namespace Vulkan {
23 23
24using Shader::ImageBufferDescriptor; 24using Shader::ImageBufferDescriptor;
25using Shader::Backend::SPIRV::RESCALING_LAYOUT_WORDS_OFFSET;
25using Tegra::Texture::TexturePair; 26using Tegra::Texture::TexturePair;
26 27
27ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descriptor_pool, 28ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descriptor_pool,
@@ -185,7 +186,7 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
185 buffer_cache.UpdateComputeBuffers(); 186 buffer_cache.UpdateComputeBuffers();
186 buffer_cache.BindHostComputeBuffers(); 187 buffer_cache.BindHostComputeBuffers();
187 188
188 RescalingPushConstant rescaling(num_textures); 189 RescalingPushConstant rescaling;
189 const VkSampler* samplers_it{samplers.data()}; 190 const VkSampler* samplers_it{samplers.data()};
190 const VideoCommon::ImageViewInOut* views_it{views.data()}; 191 const VideoCommon::ImageViewInOut* views_it{views.data()};
191 PushImageDescriptors(texture_cache, update_descriptor_queue, info, rescaling, samplers_it, 192 PushImageDescriptors(texture_cache, update_descriptor_queue, info, rescaling, samplers_it,
@@ -199,21 +200,24 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
199 }); 200 });
200 } 201 }
201 const void* const descriptor_data{update_descriptor_queue.UpdateData()}; 202 const void* const descriptor_data{update_descriptor_queue.UpdateData()};
202 scheduler.Record( 203 const bool is_rescaling = !info.texture_descriptors.empty() || !info.image_descriptors.empty();
203 [this, descriptor_data, rescaling_data = rescaling.Data()](vk::CommandBuffer cmdbuf) { 204 scheduler.Record([this, descriptor_data, is_rescaling,
204 cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 205 rescaling_data = rescaling.Data()](vk::CommandBuffer cmdbuf) {
205 if (!descriptor_set_layout) { 206 cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
206 return; 207 if (!descriptor_set_layout) {
207 } 208 return;
208 if (num_textures > 0) { 209 }
209 cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, rescaling_data); 210 if (is_rescaling) {
210 } 211 cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT,
211 const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; 212 RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
212 const vk::Device& dev{device.GetLogical()}; 213 rescaling_data.data());
213 dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data); 214 }
214 cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout, 0, 215 const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()};
215 descriptor_set, nullptr); 216 const vk::Device& dev{device.GetLogical()};
216 }); 217 dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data);
218 cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout, 0,
219 descriptor_set, nullptr);
220 });
217} 221}
218 222
219} // namespace Vulkan 223} // namespace Vulkan
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.h b/src/video_core/renderer_vulkan/vk_compute_pipeline.h
index e79ce4d7c..8c4b0a301 100644
--- a/src/video_core/renderer_vulkan/vk_compute_pipeline.h
+++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.h
@@ -59,7 +59,6 @@ private:
59 vk::PipelineLayout pipeline_layout; 59 vk::PipelineLayout pipeline_layout;
60 vk::DescriptorUpdateTemplateKHR descriptor_update_template; 60 vk::DescriptorUpdateTemplateKHR descriptor_update_template;
61 vk::Pipeline pipeline; 61 vk::Pipeline pipeline;
62 u32 num_textures{};
63 62
64 std::condition_variable build_condvar; 63 std::condition_variable build_condvar;
65 std::mutex build_mutex; 64 std::mutex build_mutex;
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
index f08e9e840..616a7b457 100644
--- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
+++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
@@ -32,6 +32,8 @@ namespace {
32using boost::container::small_vector; 32using boost::container::small_vector;
33using boost::container::static_vector; 33using boost::container::static_vector;
34using Shader::ImageBufferDescriptor; 34using Shader::ImageBufferDescriptor;
35using Shader::Backend::SPIRV::RESCALING_LAYOUT_DOWN_FACTOR_OFFSET;
36using Shader::Backend::SPIRV::RESCALING_LAYOUT_WORDS_OFFSET;
35using Tegra::Texture::TexturePair; 37using Tegra::Texture::TexturePair;
36using VideoCore::Surface::PixelFormat; 38using VideoCore::Surface::PixelFormat;
37using VideoCore::Surface::PixelFormatFromDepthFormat; 39using VideoCore::Surface::PixelFormatFromDepthFormat;
@@ -431,7 +433,7 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
431 433
432 update_descriptor_queue.Acquire(); 434 update_descriptor_queue.Acquire();
433 435
434 RescalingPushConstant rescaling(num_textures); 436 RescalingPushConstant rescaling;
435 const VkSampler* samplers_it{samplers.data()}; 437 const VkSampler* samplers_it{samplers.data()};
436 const VideoCommon::ImageViewInOut* views_it{views.data()}; 438 const VideoCommon::ImageViewInOut* views_it{views.data()};
437 const auto prepare_stage{[&](size_t stage) LAMBDA_FORCEINLINE { 439 const auto prepare_stage{[&](size_t stage) LAMBDA_FORCEINLINE {
@@ -477,15 +479,16 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling) {
477 if (bind_pipeline) { 479 if (bind_pipeline) {
478 cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 480 cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
479 } 481 }
482 cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
483 RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
484 rescaling_data.data());
480 if (update_rescaling) { 485 if (update_rescaling) {
481 const f32 config_down_factor{Settings::values.resolution_info.down_factor}; 486 const f32 config_down_factor{Settings::values.resolution_info.down_factor};
482 const f32 scale_down_factor{is_rescaling ? config_down_factor : 1.0f}; 487 const f32 scale_down_factor{is_rescaling ? config_down_factor : 1.0f};
483 cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS, 0, 488 cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
484 sizeof(scale_down_factor), &scale_down_factor); 489 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET, sizeof(scale_down_factor),
490 &scale_down_factor);
485 } 491 }
486 cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
487 RESCALING_PUSH_CONSTANT_WORDS_OFFSET, sizeof(rescaling_data),
488 rescaling_data.data());
489 if (!descriptor_set_layout) { 492 if (!descriptor_set_layout) {
490 return; 493 return;
491 } 494 }