diff options
| -rw-r--r-- | src/video_core/engines/draw_manager.cpp | 11 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 29 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.cpp | 56 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.h | 5 |
5 files changed, 72 insertions, 36 deletions
diff --git a/src/video_core/engines/draw_manager.cpp b/src/video_core/engines/draw_manager.cpp index d77ff455b..971025cb5 100644 --- a/src/video_core/engines/draw_manager.cpp +++ b/src/video_core/engines/draw_manager.cpp | |||
| @@ -216,14 +216,11 @@ void DrawManager::DrawTexture() { | |||
| 216 | const bool lower_left{regs.window_origin.mode != | 216 | const bool lower_left{regs.window_origin.mode != |
| 217 | Maxwell3D::Regs::WindowOrigin::Mode::UpperLeft}; | 217 | Maxwell3D::Regs::WindowOrigin::Mode::UpperLeft}; |
| 218 | if (lower_left) { | 218 | if (lower_left) { |
| 219 | draw_texture_state.dst_y0 -= dst_height; | 219 | draw_texture_state.dst_y0 = |
| 220 | static_cast<f32>(regs.surface_clip.height) - draw_texture_state.dst_y0; | ||
| 220 | } | 221 | } |
| 221 | draw_texture_state.dst_x1 = | 222 | draw_texture_state.dst_x1 = draw_texture_state.dst_x0 + dst_width; |
| 222 | draw_texture_state.dst_x0 + | 223 | draw_texture_state.dst_y1 = draw_texture_state.dst_y0 + dst_height; |
| 223 | static_cast<f32>(Settings::values.resolution_info.ScaleUp(static_cast<u32>(dst_width))); | ||
| 224 | draw_texture_state.dst_y1 = | ||
| 225 | draw_texture_state.dst_y0 + | ||
| 226 | static_cast<f32>(Settings::values.resolution_info.ScaleUp(static_cast<u32>(dst_height))); | ||
| 227 | draw_texture_state.src_x0 = static_cast<float>(regs.draw_texture.src_x0) / 4096.f; | 224 | draw_texture_state.src_x0 = static_cast<float>(regs.draw_texture.src_x0) / 4096.f; |
| 228 | draw_texture_state.src_y0 = static_cast<float>(regs.draw_texture.src_y0) / 4096.f; | 225 | draw_texture_state.src_y0 = static_cast<float>(regs.draw_texture.src_y0) / 4096.f; |
| 229 | draw_texture_state.src_x1 = | 226 | draw_texture_state.src_x1 = |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 16af8e6bd..d376d86d8 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -370,27 +370,32 @@ void RasterizerOpenGL::DrawTexture() { | |||
| 370 | const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler); | 370 | const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler); |
| 371 | const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture); | 371 | const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture); |
| 372 | 372 | ||
| 373 | const auto Scale = [&](auto dim) -> s32 { | ||
| 374 | return Settings::values.resolution_info.ScaleUp(static_cast<s32>(dim)); | ||
| 375 | }; | ||
| 376 | |||
| 377 | Region2D dst_region = { | ||
| 378 | Offset2D{.x = Scale(draw_texture_state.dst_x0), .y = Scale(draw_texture_state.dst_y0)}, | ||
| 379 | Offset2D{.x = Scale(draw_texture_state.dst_x1), .y = Scale(draw_texture_state.dst_y1)}}; | ||
| 380 | Region2D src_region = { | ||
| 381 | Offset2D{.x = Scale(draw_texture_state.src_x0), .y = Scale(draw_texture_state.src_y0)}, | ||
| 382 | Offset2D{.x = Scale(draw_texture_state.src_x1), .y = Scale(draw_texture_state.src_y1)}}; | ||
| 383 | Extent3D src_size = {static_cast<u32>(Scale(texture.size.width)), | ||
| 384 | static_cast<u32>(Scale(texture.size.height)), texture.size.depth}; | ||
| 385 | |||
| 373 | if (device.HasDrawTexture()) { | 386 | if (device.HasDrawTexture()) { |
| 374 | state_tracker.BindFramebuffer(texture_cache.GetFramebuffer()->Handle()); | 387 | state_tracker.BindFramebuffer(texture_cache.GetFramebuffer()->Handle()); |
| 375 | 388 | ||
| 376 | glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(), draw_texture_state.dst_x0, | 389 | glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(), |
| 377 | draw_texture_state.dst_y0, draw_texture_state.dst_x1, | 390 | static_cast<f32>(dst_region.start.x), static_cast<f32>(dst_region.start.y), |
| 378 | draw_texture_state.dst_y1, 0, | 391 | static_cast<f32>(dst_region.end.x), static_cast<f32>(dst_region.end.y), 0, |
| 379 | draw_texture_state.src_x0 / static_cast<float>(texture.size.width), | 392 | draw_texture_state.src_x0 / static_cast<float>(texture.size.width), |
| 380 | draw_texture_state.src_y0 / static_cast<float>(texture.size.height), | 393 | draw_texture_state.src_y0 / static_cast<float>(texture.size.height), |
| 381 | draw_texture_state.src_x1 / static_cast<float>(texture.size.width), | 394 | draw_texture_state.src_x1 / static_cast<float>(texture.size.width), |
| 382 | draw_texture_state.src_y1 / static_cast<float>(texture.size.height)); | 395 | draw_texture_state.src_y1 / static_cast<float>(texture.size.height)); |
| 383 | } else { | 396 | } else { |
| 384 | Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0), | ||
| 385 | .y = static_cast<s32>(draw_texture_state.dst_y0)}, | ||
| 386 | Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1), | ||
| 387 | .y = static_cast<s32>(draw_texture_state.dst_y1)}}; | ||
| 388 | Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0), | ||
| 389 | .y = static_cast<s32>(draw_texture_state.src_y0)}, | ||
| 390 | Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1), | ||
| 391 | .y = static_cast<s32>(draw_texture_state.src_y1)}}; | ||
| 392 | blit_image.BlitColor(texture_cache.GetFramebuffer()->Handle(), texture.DefaultHandle(), | 397 | blit_image.BlitColor(texture_cache.GetFramebuffer()->Handle(), texture.DefaultHandle(), |
| 393 | sampler->Handle(), dst_region, src_region, texture.size); | 398 | sampler->Handle(), dst_region, src_region, src_size); |
| 394 | state_tracker.InvalidateState(); | 399 | state_tracker.InvalidateState(); |
| 395 | } | 400 | } |
| 396 | 401 | ||
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 | ||
| 324 | void RasterizerVulkan::Clear(u32 layer_count) { | 352 | void 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 | ||
| 1964 | Framebuffer::Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer, | 1964 | Framebuffer::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 | ||
| 1971 | Framebuffer::~Framebuffer() = default; | 1971 | Framebuffer::~Framebuffer() = default; |
| 1972 | 1972 | ||
| 1973 | void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, | 1973 | void 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 | |||
| 364 | private: | 368 | private: |
| 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 | ||
| 378 | struct TextureCacheParams { | 383 | struct TextureCacheParams { |