diff options
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/buffer_cache/buffer_cache.h | 5 | ||||
| -rw-r--r-- | src/video_core/buffer_cache/usage_tracker.h | 6 | ||||
| -rw-r--r-- | src/video_core/control/channel_state.cpp | 3 | ||||
| -rw-r--r-- | src/video_core/control/channel_state.h | 3 | ||||
| -rw-r--r-- | src/video_core/control/channel_state_cache.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/control/channel_state_cache.h | 8 | ||||
| -rw-r--r-- | src/video_core/control/channel_state_cache.inc | 2 | ||||
| -rw-r--r-- | src/video_core/engines/draw_manager.cpp | 11 | ||||
| -rw-r--r-- | src/video_core/gpu.cpp | 8 | ||||
| -rw-r--r-- | src/video_core/gpu.h | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 29 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_query_cache.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.cpp | 85 | ||||
| -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 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 30 |
17 files changed, 135 insertions, 86 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index ed7a5b27e..af237703d 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -1488,7 +1488,10 @@ void BufferCache<P>::ImmediateUploadMemory([[maybe_unused]] Buffer& buffer, | |||
| 1488 | std::span<const u8> upload_span; | 1488 | std::span<const u8> upload_span; |
| 1489 | const DAddr device_addr = buffer.CpuAddr() + copy.dst_offset; | 1489 | const DAddr device_addr = buffer.CpuAddr() + copy.dst_offset; |
| 1490 | if (IsRangeGranular(device_addr, copy.size)) { | 1490 | if (IsRangeGranular(device_addr, copy.size)) { |
| 1491 | upload_span = std::span(device_memory.GetPointer<u8>(device_addr), copy.size); | 1491 | auto* const ptr = device_memory.GetPointer<u8>(device_addr); |
| 1492 | if (ptr != nullptr) { | ||
| 1493 | upload_span = std::span(ptr, copy.size); | ||
| 1494 | } | ||
| 1492 | } else { | 1495 | } else { |
| 1493 | if (immediate_buffer.empty()) { | 1496 | if (immediate_buffer.empty()) { |
| 1494 | immediate_buffer = ImmediateBuffer(largest_copy); | 1497 | immediate_buffer = ImmediateBuffer(largest_copy); |
diff --git a/src/video_core/buffer_cache/usage_tracker.h b/src/video_core/buffer_cache/usage_tracker.h index 5f8688d31..ae511ccb6 100644 --- a/src/video_core/buffer_cache/usage_tracker.h +++ b/src/video_core/buffer_cache/usage_tracker.h | |||
| @@ -26,6 +26,9 @@ public: | |||
| 26 | void Track(u64 offset, u64 size) noexcept { | 26 | void Track(u64 offset, u64 size) noexcept { |
| 27 | const size_t page = offset >> PAGE_SHIFT; | 27 | const size_t page = offset >> PAGE_SHIFT; |
| 28 | const size_t page_end = (offset + size) >> PAGE_SHIFT; | 28 | const size_t page_end = (offset + size) >> PAGE_SHIFT; |
| 29 | if (page_end < page || page_end >= pages.size()) { | ||
| 30 | return; | ||
| 31 | } | ||
| 29 | TrackPage(page, offset, size); | 32 | TrackPage(page, offset, size); |
| 30 | if (page == page_end) { | 33 | if (page == page_end) { |
| 31 | return; | 34 | return; |
| @@ -41,6 +44,9 @@ public: | |||
| 41 | [[nodiscard]] bool IsUsed(u64 offset, u64 size) const noexcept { | 44 | [[nodiscard]] bool IsUsed(u64 offset, u64 size) const noexcept { |
| 42 | const size_t page = offset >> PAGE_SHIFT; | 45 | const size_t page = offset >> PAGE_SHIFT; |
| 43 | const size_t page_end = (offset + size) >> PAGE_SHIFT; | 46 | const size_t page_end = (offset + size) >> PAGE_SHIFT; |
| 47 | if (page_end < page || page_end >= pages.size()) { | ||
| 48 | return false; | ||
| 49 | } | ||
| 44 | if (IsPageUsed(page, offset, size)) { | 50 | if (IsPageUsed(page, offset, size)) { |
| 45 | return true; | 51 | return true; |
| 46 | } | 52 | } |
diff --git a/src/video_core/control/channel_state.cpp b/src/video_core/control/channel_state.cpp index 832025d75..2539997d5 100644 --- a/src/video_core/control/channel_state.cpp +++ b/src/video_core/control/channel_state.cpp | |||
| @@ -16,8 +16,9 @@ namespace Tegra::Control { | |||
| 16 | 16 | ||
| 17 | ChannelState::ChannelState(s32 bind_id_) : bind_id{bind_id_}, initialized{} {} | 17 | ChannelState::ChannelState(s32 bind_id_) : bind_id{bind_id_}, initialized{} {} |
| 18 | 18 | ||
| 19 | void ChannelState::Init(Core::System& system, GPU& gpu) { | 19 | void ChannelState::Init(Core::System& system, GPU& gpu, u64 program_id_) { |
| 20 | ASSERT(memory_manager); | 20 | ASSERT(memory_manager); |
| 21 | program_id = program_id_; | ||
| 21 | dma_pusher = std::make_unique<Tegra::DmaPusher>(system, gpu, *memory_manager, *this); | 22 | dma_pusher = std::make_unique<Tegra::DmaPusher>(system, gpu, *memory_manager, *this); |
| 22 | maxwell_3d = std::make_unique<Engines::Maxwell3D>(system, *memory_manager); | 23 | maxwell_3d = std::make_unique<Engines::Maxwell3D>(system, *memory_manager); |
| 23 | fermi_2d = std::make_unique<Engines::Fermi2D>(*memory_manager); | 24 | fermi_2d = std::make_unique<Engines::Fermi2D>(*memory_manager); |
diff --git a/src/video_core/control/channel_state.h b/src/video_core/control/channel_state.h index 3a7b9872c..b385f4939 100644 --- a/src/video_core/control/channel_state.h +++ b/src/video_core/control/channel_state.h | |||
| @@ -40,11 +40,12 @@ struct ChannelState { | |||
| 40 | ChannelState(ChannelState&& other) noexcept = default; | 40 | ChannelState(ChannelState&& other) noexcept = default; |
| 41 | ChannelState& operator=(ChannelState&& other) noexcept = default; | 41 | ChannelState& operator=(ChannelState&& other) noexcept = default; |
| 42 | 42 | ||
| 43 | void Init(Core::System& system, GPU& gpu); | 43 | void Init(Core::System& system, GPU& gpu, u64 program_id); |
| 44 | 44 | ||
| 45 | void BindRasterizer(VideoCore::RasterizerInterface* rasterizer); | 45 | void BindRasterizer(VideoCore::RasterizerInterface* rasterizer); |
| 46 | 46 | ||
| 47 | s32 bind_id = -1; | 47 | s32 bind_id = -1; |
| 48 | u64 program_id = 0; | ||
| 48 | /// 3D engine | 49 | /// 3D engine |
| 49 | std::unique_ptr<Engines::Maxwell3D> maxwell_3d; | 50 | std::unique_ptr<Engines::Maxwell3D> maxwell_3d; |
| 50 | /// 2D engine | 51 | /// 2D engine |
diff --git a/src/video_core/control/channel_state_cache.cpp b/src/video_core/control/channel_state_cache.cpp index 4ebeb6356..f8c6a762d 100644 --- a/src/video_core/control/channel_state_cache.cpp +++ b/src/video_core/control/channel_state_cache.cpp | |||
| @@ -7,7 +7,7 @@ namespace VideoCommon { | |||
| 7 | 7 | ||
| 8 | ChannelInfo::ChannelInfo(Tegra::Control::ChannelState& channel_state) | 8 | ChannelInfo::ChannelInfo(Tegra::Control::ChannelState& channel_state) |
| 9 | : maxwell3d{*channel_state.maxwell_3d}, kepler_compute{*channel_state.kepler_compute}, | 9 | : maxwell3d{*channel_state.maxwell_3d}, kepler_compute{*channel_state.kepler_compute}, |
| 10 | gpu_memory{*channel_state.memory_manager} {} | 10 | gpu_memory{*channel_state.memory_manager}, program_id{channel_state.program_id} {} |
| 11 | 11 | ||
| 12 | template class VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo>; | 12 | template class VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo>; |
| 13 | 13 | ||
diff --git a/src/video_core/control/channel_state_cache.h b/src/video_core/control/channel_state_cache.h index 1dbfda299..7480d60d1 100644 --- a/src/video_core/control/channel_state_cache.h +++ b/src/video_core/control/channel_state_cache.h | |||
| @@ -39,6 +39,7 @@ public: | |||
| 39 | Tegra::Engines::Maxwell3D& maxwell3d; | 39 | Tegra::Engines::Maxwell3D& maxwell3d; |
| 40 | Tegra::Engines::KeplerCompute& kepler_compute; | 40 | Tegra::Engines::KeplerCompute& kepler_compute; |
| 41 | Tegra::MemoryManager& gpu_memory; | 41 | Tegra::MemoryManager& gpu_memory; |
| 42 | u64 program_id; | ||
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| 44 | template <class P> | 45 | template <class P> |
| @@ -77,9 +78,10 @@ protected: | |||
| 77 | P* channel_state; | 78 | P* channel_state; |
| 78 | size_t current_channel_id{UNSET_CHANNEL}; | 79 | size_t current_channel_id{UNSET_CHANNEL}; |
| 79 | size_t current_address_space{}; | 80 | size_t current_address_space{}; |
| 80 | Tegra::Engines::Maxwell3D* maxwell3d; | 81 | Tegra::Engines::Maxwell3D* maxwell3d{}; |
| 81 | Tegra::Engines::KeplerCompute* kepler_compute; | 82 | Tegra::Engines::KeplerCompute* kepler_compute{}; |
| 82 | Tegra::MemoryManager* gpu_memory; | 83 | Tegra::MemoryManager* gpu_memory{}; |
| 84 | u64 program_id{}; | ||
| 83 | 85 | ||
| 84 | std::deque<P> channel_storage; | 86 | std::deque<P> channel_storage; |
| 85 | std::deque<size_t> free_channel_ids; | 87 | std::deque<size_t> free_channel_ids; |
diff --git a/src/video_core/control/channel_state_cache.inc b/src/video_core/control/channel_state_cache.inc index 31f792ddd..d882d8222 100644 --- a/src/video_core/control/channel_state_cache.inc +++ b/src/video_core/control/channel_state_cache.inc | |||
| @@ -58,6 +58,7 @@ void ChannelSetupCaches<P>::BindToChannel(s32 id) { | |||
| 58 | maxwell3d = &channel_state->maxwell3d; | 58 | maxwell3d = &channel_state->maxwell3d; |
| 59 | kepler_compute = &channel_state->kepler_compute; | 59 | kepler_compute = &channel_state->kepler_compute; |
| 60 | gpu_memory = &channel_state->gpu_memory; | 60 | gpu_memory = &channel_state->gpu_memory; |
| 61 | program_id = channel_state->program_id; | ||
| 61 | current_address_space = gpu_memory->GetID(); | 62 | current_address_space = gpu_memory->GetID(); |
| 62 | } | 63 | } |
| 63 | 64 | ||
| @@ -76,6 +77,7 @@ void ChannelSetupCaches<P>::EraseChannel(s32 id) { | |||
| 76 | maxwell3d = nullptr; | 77 | maxwell3d = nullptr; |
| 77 | kepler_compute = nullptr; | 78 | kepler_compute = nullptr; |
| 78 | gpu_memory = nullptr; | 79 | gpu_memory = nullptr; |
| 80 | program_id = 0; | ||
| 79 | } else if (current_channel_id != UNSET_CHANNEL) { | 81 | } else if (current_channel_id != UNSET_CHANNEL) { |
| 80 | channel_state = &channel_storage[current_channel_id]; | 82 | channel_state = &channel_storage[current_channel_id]; |
| 81 | } | 83 | } |
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/gpu.cpp b/src/video_core/gpu.cpp index 8e663f2a8..6d0b32339 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp | |||
| @@ -67,8 +67,8 @@ struct GPU::Impl { | |||
| 67 | return CreateChannel(new_channel_id++); | 67 | return CreateChannel(new_channel_id++); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | void InitChannel(Control::ChannelState& to_init) { | 70 | void InitChannel(Control::ChannelState& to_init, u64 program_id) { |
| 71 | to_init.Init(system, gpu); | 71 | to_init.Init(system, gpu, program_id); |
| 72 | to_init.BindRasterizer(rasterizer); | 72 | to_init.BindRasterizer(rasterizer); |
| 73 | rasterizer->InitializeChannel(to_init); | 73 | rasterizer->InitializeChannel(to_init); |
| 74 | } | 74 | } |
| @@ -412,8 +412,8 @@ std::shared_ptr<Control::ChannelState> GPU::AllocateChannel() { | |||
| 412 | return impl->AllocateChannel(); | 412 | return impl->AllocateChannel(); |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | void GPU::InitChannel(Control::ChannelState& to_init) { | 415 | void GPU::InitChannel(Control::ChannelState& to_init, u64 program_id) { |
| 416 | impl->InitChannel(to_init); | 416 | impl->InitChannel(to_init, program_id); |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | void GPU::BindChannel(s32 channel_id) { | 419 | void GPU::BindChannel(s32 channel_id) { |
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index ad535512c..50014e51f 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h | |||
| @@ -149,7 +149,7 @@ public: | |||
| 149 | 149 | ||
| 150 | std::shared_ptr<Control::ChannelState> AllocateChannel(); | 150 | std::shared_ptr<Control::ChannelState> AllocateChannel(); |
| 151 | 151 | ||
| 152 | void InitChannel(Control::ChannelState& to_init); | 152 | void InitChannel(Control::ChannelState& to_init, u64 program_id); |
| 153 | 153 | ||
| 154 | void BindChannel(s32 channel_id); | 154 | void BindChannel(s32 channel_id); |
| 155 | 155 | ||
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_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 50462cdde..c4bad6fca 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -215,6 +215,7 @@ ShaderCache::ShaderCache(Tegra::MaxwellDeviceMemoryManager& device_memory_, | |||
| 215 | .support_gl_variable_aoffi = device.HasVariableAoffi(), | 215 | .support_gl_variable_aoffi = device.HasVariableAoffi(), |
| 216 | .support_gl_sparse_textures = device.HasSparseTexture2(), | 216 | .support_gl_sparse_textures = device.HasSparseTexture2(), |
| 217 | .support_gl_derivative_control = device.HasDerivativeControl(), | 217 | .support_gl_derivative_control = device.HasDerivativeControl(), |
| 218 | .support_geometry_streams = true, | ||
| 218 | 219 | ||
| 219 | .warp_size_potentially_larger_than_guest = device.IsWarpSizePotentiallyLargerThanGuest(), | 220 | .warp_size_potentially_larger_than_guest = device.IsWarpSizePotentiallyLargerThanGuest(), |
| 220 | 221 | ||
diff --git a/src/video_core/renderer_vulkan/vk_query_cache.cpp b/src/video_core/renderer_vulkan/vk_query_cache.cpp index 7cbc9c73c..a28296bda 100644 --- a/src/video_core/renderer_vulkan/vk_query_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_query_cache.cpp | |||
| @@ -1064,8 +1064,6 @@ public: | |||
| 1064 | } | 1064 | } |
| 1065 | }); | 1065 | }); |
| 1066 | } | 1066 | } |
| 1067 | auto* ptr = device_memory.GetPointer<u8>(new_query->dependant_address); | ||
| 1068 | ASSERT(ptr != nullptr); | ||
| 1069 | 1067 | ||
| 1070 | new_query->dependant_manage = must_manage_dependance; | 1068 | new_query->dependant_manage = must_manage_dependance; |
| 1071 | pending_flush_queries.push_back(index); | 1069 | pending_flush_queries.push_back(index); |
| @@ -1104,9 +1102,11 @@ public: | |||
| 1104 | tfb_streamer.Free(query->dependant_index); | 1102 | tfb_streamer.Free(query->dependant_index); |
| 1105 | } else { | 1103 | } else { |
| 1106 | u8* pointer = device_memory.GetPointer<u8>(query->dependant_address); | 1104 | u8* pointer = device_memory.GetPointer<u8>(query->dependant_address); |
| 1107 | u32 result; | 1105 | if (pointer != nullptr) { |
| 1108 | std::memcpy(&result, pointer, sizeof(u32)); | 1106 | u32 result; |
| 1109 | num_vertices = static_cast<u64>(result) / query->stride; | 1107 | std::memcpy(&result, pointer, sizeof(u32)); |
| 1108 | num_vertices = static_cast<u64>(result) / query->stride; | ||
| 1109 | } | ||
| 1110 | } | 1110 | } |
| 1111 | query->value = [&]() -> u64 { | 1111 | query->value = [&]() -> u64 { |
| 1112 | switch (query->topology) { | 1112 | switch (query->topology) { |
| @@ -1360,7 +1360,9 @@ bool QueryCacheRuntime::HostConditionalRenderingCompareValues(VideoCommon::Looku | |||
| 1360 | const auto check_value = [&](DAddr address) { | 1360 | const auto check_value = [&](DAddr address) { |
| 1361 | u8* ptr = impl->device_memory.GetPointer<u8>(address); | 1361 | u8* ptr = impl->device_memory.GetPointer<u8>(address); |
| 1362 | u64 value{}; | 1362 | u64 value{}; |
| 1363 | std::memcpy(&value, ptr, sizeof(value)); | 1363 | if (ptr != nullptr) { |
| 1364 | std::memcpy(&value, ptr, sizeof(value)); | ||
| 1365 | } | ||
| 1364 | return value == 0; | 1366 | return value == 0; |
| 1365 | }; | 1367 | }; |
| 1366 | std::array<VideoCommon::LookupData*, 2> objects{&object_1, &object_2}; | 1368 | std::array<VideoCommon::LookupData*, 2> objects{&object_1, &object_2}; |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 74f9f099e..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) { |
| @@ -1054,37 +1082,16 @@ void RasterizerVulkan::UpdateDepthBias(Tegra::Engines::Maxwell3D::Regs& regs) { | |||
| 1054 | regs.zeta.format == Tegra::DepthFormat::X8Z24_UNORM || | 1082 | regs.zeta.format == Tegra::DepthFormat::X8Z24_UNORM || |
| 1055 | regs.zeta.format == Tegra::DepthFormat::S8Z24_UNORM || | 1083 | regs.zeta.format == Tegra::DepthFormat::S8Z24_UNORM || |
| 1056 | regs.zeta.format == Tegra::DepthFormat::V8Z24_UNORM; | 1084 | regs.zeta.format == Tegra::DepthFormat::V8Z24_UNORM; |
| 1057 | bool force_unorm = ([&] { | 1085 | if (is_d24 && !device.SupportsD24DepthBuffer() && program_id == 0x1006A800016E000ULL) { |
| 1058 | if (!is_d24 || device.SupportsD24DepthBuffer()) { | 1086 | // Only activate this in Super Smash Brothers Ultimate |
| 1059 | return false; | ||
| 1060 | } | ||
| 1061 | if (device.IsExtDepthBiasControlSupported()) { | ||
| 1062 | return true; | ||
| 1063 | } | ||
| 1064 | if (!Settings::values.renderer_amdvlk_depth_bias_workaround) { | ||
| 1065 | return false; | ||
| 1066 | } | ||
| 1067 | // the base formulas can be obtained from here: | 1087 | // the base formulas can be obtained from here: |
| 1068 | // https://docs.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-output-merger-stage-depth-bias | 1088 | // https://docs.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-output-merger-stage-depth-bias |
| 1069 | const double rescale_factor = | 1089 | const double rescale_factor = |
| 1070 | static_cast<double>(1ULL << (32 - 24)) / (static_cast<double>(0x1.ep+127)); | 1090 | static_cast<double>(1ULL << (32 - 24)) / (static_cast<double>(0x1.ep+127)); |
| 1071 | units = static_cast<float>(static_cast<double>(units) * rescale_factor); | 1091 | units = static_cast<float>(static_cast<double>(units) * rescale_factor); |
| 1072 | return false; | 1092 | } |
| 1073 | })(); | ||
| 1074 | scheduler.Record([constant = units, clamp = regs.depth_bias_clamp, | 1093 | scheduler.Record([constant = units, clamp = regs.depth_bias_clamp, |
| 1075 | factor = regs.slope_scale_depth_bias, force_unorm, | 1094 | factor = regs.slope_scale_depth_bias](vk::CommandBuffer cmdbuf) { |
| 1076 | precise = device.HasExactDepthBiasControl()](vk::CommandBuffer cmdbuf) { | ||
| 1077 | if (force_unorm) { | ||
| 1078 | VkDepthBiasRepresentationInfoEXT info{ | ||
| 1079 | .sType = VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT, | ||
| 1080 | .pNext = nullptr, | ||
| 1081 | .depthBiasRepresentation = | ||
| 1082 | VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT, | ||
| 1083 | .depthBiasExact = precise ? VK_TRUE : VK_FALSE, | ||
| 1084 | }; | ||
| 1085 | cmdbuf.SetDepthBias(constant, clamp, factor, &info); | ||
| 1086 | return; | ||
| 1087 | } | ||
| 1088 | cmdbuf.SetDepthBias(constant, clamp, factor); | 1095 | cmdbuf.SetDepthBias(constant, clamp, factor); |
| 1089 | }); | 1096 | }); |
| 1090 | } | 1097 | } |
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 { |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index bfd3d00b6..feb1c575e 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -72,12 +72,19 @@ TextureCache<P>::TextureCache(Runtime& runtime_, Tegra::MaxwellDeviceMemoryManag | |||
| 72 | 72 | ||
| 73 | template <class P> | 73 | template <class P> |
| 74 | void TextureCache<P>::RunGarbageCollector() { | 74 | void TextureCache<P>::RunGarbageCollector() { |
| 75 | bool high_priority_mode = total_used_memory >= expected_memory; | 75 | bool high_priority_mode = false; |
| 76 | bool aggressive_mode = total_used_memory >= critical_memory; | 76 | bool aggressive_mode = false; |
| 77 | const u64 ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL; | 77 | u64 ticks_to_destroy = 0; |
| 78 | size_t num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10); | 78 | size_t num_iterations = 0; |
| 79 | const auto clean_up = [this, &num_iterations, &high_priority_mode, | 79 | |
| 80 | &aggressive_mode](ImageId image_id) { | 80 | const auto Configure = [&](bool allow_aggressive) { |
| 81 | high_priority_mode = total_used_memory >= expected_memory; | ||
| 82 | aggressive_mode = allow_aggressive && total_used_memory >= critical_memory; | ||
| 83 | ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL; | ||
| 84 | num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10); | ||
| 85 | }; | ||
| 86 | const auto Cleanup = [this, &num_iterations, &high_priority_mode, | ||
| 87 | &aggressive_mode](ImageId image_id) { | ||
| 81 | if (num_iterations == 0) { | 88 | if (num_iterations == 0) { |
| 82 | return true; | 89 | return true; |
| 83 | } | 90 | } |
| @@ -123,7 +130,16 @@ void TextureCache<P>::RunGarbageCollector() { | |||
| 123 | } | 130 | } |
| 124 | return false; | 131 | return false; |
| 125 | }; | 132 | }; |
| 126 | lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up); | 133 | |
| 134 | // Try to remove anything old enough and not high priority. | ||
| 135 | Configure(false); | ||
| 136 | lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup); | ||
| 137 | |||
| 138 | // If pressure is still too high, prune aggressively. | ||
| 139 | if (total_used_memory >= critical_memory) { | ||
| 140 | Configure(true); | ||
| 141 | lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup); | ||
| 142 | } | ||
| 127 | } | 143 | } |
| 128 | 144 | ||
| 129 | template <class P> | 145 | template <class P> |