summaryrefslogtreecommitdiff
path: root/src/video_core/renderer_vulkan
diff options
context:
space:
mode:
authorGravatar liamwhite2024-02-27 09:40:33 -0500
committerGravatar GitHub2024-02-27 15:40:33 +0100
commitb2e129eaa5c97f216dcf02e2d853ca809ce392b7 (patch)
tree00008f3292759b20e529514b067bc798ae19b21d /src/video_core/renderer_vulkan
parentbuffer_cache: avoid overflow in usage tracker (#13166) (diff)
downloadyuzu-b2e129eaa5c97f216dcf02e2d853ca809ce392b7.tar.gz
yuzu-b2e129eaa5c97f216dcf02e2d853ca809ce392b7.tar.xz
yuzu-b2e129eaa5c97f216dcf02e2d853ca809ce392b7.zip
vk_rasterizer: flip scissor y on lower left origin mode (#13122)
Diffstat (limited to 'src/video_core/renderer_vulkan')
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp56
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.cpp7
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.h5
3 files changed, 51 insertions, 17 deletions
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index 84955bdc8..8ba50a834 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -125,11 +125,23 @@ VkRect2D GetScissorState(const Maxwell& regs, size_t index, u32 up_scale = 1, u3
125 return value < 0 ? std::min<s32>(converted_value - acumm, -1) 125 return value < 0 ? std::min<s32>(converted_value - acumm, -1)
126 : std::max<s32>(converted_value + acumm, 1); 126 : std::max<s32>(converted_value + acumm, 1);
127 }; 127 };
128
129 const bool lower_left = regs.window_origin.mode != Maxwell::WindowOrigin::Mode::UpperLeft;
130 const s32 clip_height = regs.surface_clip.height;
131
132 // Flip coordinates if lower left
133 s32 min_y = lower_left ? (clip_height - src.max_y) : src.min_y.Value();
134 s32 max_y = lower_left ? (clip_height - src.min_y) : src.max_y.Value();
135
136 // Bound to render area
137 min_y = std::max(min_y, 0);
138 max_y = std::max(max_y, 0);
139
128 if (src.enable) { 140 if (src.enable) {
129 scissor.offset.x = scale_up(static_cast<s32>(src.min_x)); 141 scissor.offset.x = scale_up(src.min_x);
130 scissor.offset.y = scale_up(static_cast<s32>(src.min_y)); 142 scissor.offset.y = scale_up(min_y);
131 scissor.extent.width = scale_up(src.max_x - src.min_x); 143 scissor.extent.width = scale_up(src.max_x - src.min_x);
132 scissor.extent.height = scale_up(src.max_y - src.min_y); 144 scissor.extent.height = scale_up(max_y - min_y);
133 } else { 145 } else {
134 scissor.offset.x = 0; 146 scissor.offset.x = 0;
135 scissor.offset.y = 0; 147 scissor.offset.y = 0;
@@ -308,17 +320,33 @@ void RasterizerVulkan::DrawTexture() {
308 const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState(); 320 const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState();
309 const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler); 321 const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler);
310 const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture); 322 const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture);
311 Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0), 323 const auto* framebuffer = texture_cache.GetFramebuffer();
312 .y = static_cast<s32>(draw_texture_state.dst_y0)}, 324
313 Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1), 325 const bool src_rescaling = texture_cache.IsRescaling() && texture.IsRescaled();
314 .y = static_cast<s32>(draw_texture_state.dst_y1)}}; 326 const bool dst_rescaling = texture_cache.IsRescaling() && framebuffer->IsRescaled();
315 Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0), 327
316 .y = static_cast<s32>(draw_texture_state.src_y0)}, 328 const auto ScaleSrc = [&](auto dim_f) -> s32 {
317 Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1), 329 auto dim = static_cast<s32>(dim_f);
318 .y = static_cast<s32>(draw_texture_state.src_y1)}}; 330 return src_rescaling ? Settings::values.resolution_info.ScaleUp(dim) : dim;
319 blit_image.BlitColor(texture_cache.GetFramebuffer(), texture.RenderTarget(), 331 };
320 texture.ImageHandle(), sampler->Handle(), dst_region, src_region, 332
321 texture.size); 333 const auto ScaleDst = [&](auto dim_f) -> s32 {
334 auto dim = static_cast<s32>(dim_f);
335 return dst_rescaling ? Settings::values.resolution_info.ScaleUp(dim) : dim;
336 };
337
338 Region2D dst_region = {Offset2D{.x = ScaleDst(draw_texture_state.dst_x0),
339 .y = ScaleDst(draw_texture_state.dst_y0)},
340 Offset2D{.x = ScaleDst(draw_texture_state.dst_x1),
341 .y = ScaleDst(draw_texture_state.dst_y1)}};
342 Region2D src_region = {Offset2D{.x = ScaleSrc(draw_texture_state.src_x0),
343 .y = ScaleSrc(draw_texture_state.src_y0)},
344 Offset2D{.x = ScaleSrc(draw_texture_state.src_x1),
345 .y = ScaleSrc(draw_texture_state.src_y1)}};
346 Extent3D src_size = {static_cast<u32>(ScaleSrc(texture.size.width)),
347 static_cast<u32>(ScaleSrc(texture.size.height)), texture.size.depth};
348 blit_image.BlitColor(framebuffer, texture.RenderTarget(), texture.ImageHandle(),
349 sampler->Handle(), dst_region, src_region, src_size);
322} 350}
323 351
324void RasterizerVulkan::Clear(u32 layer_count) { 352void RasterizerVulkan::Clear(u32 layer_count) {
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index 832b5e2b1..6d4deb0eb 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -1962,21 +1962,22 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM
1962} 1962}
1963 1963
1964Framebuffer::Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer, 1964Framebuffer::Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer,
1965 ImageView* depth_buffer, VkExtent2D extent, bool is_rescaled) 1965 ImageView* depth_buffer, VkExtent2D extent, bool is_rescaled_)
1966 : render_area{extent} { 1966 : render_area{extent} {
1967 std::array<ImageView*, NUM_RT> color_buffers{color_buffer}; 1967 std::array<ImageView*, NUM_RT> color_buffers{color_buffer};
1968 CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled); 1968 CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled_);
1969} 1969}
1970 1970
1971Framebuffer::~Framebuffer() = default; 1971Framebuffer::~Framebuffer() = default;
1972 1972
1973void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, 1973void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime,
1974 std::span<ImageView*, NUM_RT> color_buffers, 1974 std::span<ImageView*, NUM_RT> color_buffers,
1975 ImageView* depth_buffer, bool is_rescaled) { 1975 ImageView* depth_buffer, bool is_rescaled_) {
1976 boost::container::small_vector<VkImageView, NUM_RT + 1> attachments; 1976 boost::container::small_vector<VkImageView, NUM_RT + 1> attachments;
1977 RenderPassKey renderpass_key{}; 1977 RenderPassKey renderpass_key{};
1978 s32 num_layers = 1; 1978 s32 num_layers = 1;
1979 1979
1980 is_rescaled = is_rescaled_;
1980 const auto& resolution = runtime.resolution; 1981 const auto& resolution = runtime.resolution;
1981 1982
1982 u32 width = std::numeric_limits<u32>::max(); 1983 u32 width = std::numeric_limits<u32>::max();
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h
index aaeb5ef93..8501ec384 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.h
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.h
@@ -361,6 +361,10 @@ public:
361 return has_stencil; 361 return has_stencil;
362 } 362 }
363 363
364 [[nodiscard]] bool IsRescaled() const noexcept {
365 return is_rescaled;
366 }
367
364private: 368private:
365 vk::Framebuffer framebuffer; 369 vk::Framebuffer framebuffer;
366 VkRenderPass renderpass{}; 370 VkRenderPass renderpass{};
@@ -373,6 +377,7 @@ private:
373 std::array<size_t, NUM_RT> rt_map{}; 377 std::array<size_t, NUM_RT> rt_map{};
374 bool has_depth{}; 378 bool has_depth{};
375 bool has_stencil{}; 379 bool has_stencil{};
380 bool is_rescaled{};
376}; 381};
377 382
378struct TextureCacheParams { 383struct TextureCacheParams {