summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h5
-rw-r--r--src/video_core/buffer_cache/usage_tracker.h6
-rw-r--r--src/video_core/engines/draw_manager.cpp11
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp29
-rw-r--r--src/video_core/renderer_vulkan/vk_query_cache.cpp14
-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
-rw-r--r--src/video_core/texture_cache/texture_cache.h38
9 files changed, 119 insertions, 52 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,
std::span<const u8> upload_span;
const DAddr device_addr = buffer.CpuAddr() + copy.dst_offset;
if (IsRangeGranular(device_addr, copy.size)) {
- upload_span = std::span(device_memory.GetPointer<u8>(device_addr), copy.size);
+ auto* const ptr = device_memory.GetPointer<u8>(device_addr);
+ if (ptr != nullptr) {
+ upload_span = std::span(ptr, copy.size);
+ }
} else {
if (immediate_buffer.empty()) {
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:
void Track(u64 offset, u64 size) noexcept {
const size_t page = offset >> PAGE_SHIFT;
const size_t page_end = (offset + size) >> PAGE_SHIFT;
+ if (page_end < page || page_end >= pages.size()) {
+ return;
+ }
TrackPage(page, offset, size);
if (page == page_end) {
return;
@@ -41,6 +44,9 @@ public:
[[nodiscard]] bool IsUsed(u64 offset, u64 size) const noexcept {
const size_t page = offset >> PAGE_SHIFT;
const size_t page_end = (offset + size) >> PAGE_SHIFT;
+ if (page_end < page || page_end >= pages.size()) {
+ return false;
+ }
if (IsPageUsed(page, offset, size)) {
return true;
}
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() {
const bool lower_left{regs.window_origin.mode !=
Maxwell3D::Regs::WindowOrigin::Mode::UpperLeft};
if (lower_left) {
- draw_texture_state.dst_y0 -= dst_height;
+ draw_texture_state.dst_y0 =
+ static_cast<f32>(regs.surface_clip.height) - draw_texture_state.dst_y0;
}
- draw_texture_state.dst_x1 =
- draw_texture_state.dst_x0 +
- static_cast<f32>(Settings::values.resolution_info.ScaleUp(static_cast<u32>(dst_width)));
- draw_texture_state.dst_y1 =
- draw_texture_state.dst_y0 +
- static_cast<f32>(Settings::values.resolution_info.ScaleUp(static_cast<u32>(dst_height)));
+ draw_texture_state.dst_x1 = draw_texture_state.dst_x0 + dst_width;
+ draw_texture_state.dst_y1 = draw_texture_state.dst_y0 + dst_height;
draw_texture_state.src_x0 = static_cast<float>(regs.draw_texture.src_x0) / 4096.f;
draw_texture_state.src_y0 = static_cast<float>(regs.draw_texture.src_y0) / 4096.f;
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() {
const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler);
const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture);
+ const auto Scale = [&](auto dim) -> s32 {
+ return Settings::values.resolution_info.ScaleUp(static_cast<s32>(dim));
+ };
+
+ Region2D dst_region = {
+ Offset2D{.x = Scale(draw_texture_state.dst_x0), .y = Scale(draw_texture_state.dst_y0)},
+ Offset2D{.x = Scale(draw_texture_state.dst_x1), .y = Scale(draw_texture_state.dst_y1)}};
+ Region2D src_region = {
+ Offset2D{.x = Scale(draw_texture_state.src_x0), .y = Scale(draw_texture_state.src_y0)},
+ Offset2D{.x = Scale(draw_texture_state.src_x1), .y = Scale(draw_texture_state.src_y1)}};
+ Extent3D src_size = {static_cast<u32>(Scale(texture.size.width)),
+ static_cast<u32>(Scale(texture.size.height)), texture.size.depth};
+
if (device.HasDrawTexture()) {
state_tracker.BindFramebuffer(texture_cache.GetFramebuffer()->Handle());
- glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(), draw_texture_state.dst_x0,
- draw_texture_state.dst_y0, draw_texture_state.dst_x1,
- draw_texture_state.dst_y1, 0,
+ glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(),
+ static_cast<f32>(dst_region.start.x), static_cast<f32>(dst_region.start.y),
+ static_cast<f32>(dst_region.end.x), static_cast<f32>(dst_region.end.y), 0,
draw_texture_state.src_x0 / static_cast<float>(texture.size.width),
draw_texture_state.src_y0 / static_cast<float>(texture.size.height),
draw_texture_state.src_x1 / static_cast<float>(texture.size.width),
draw_texture_state.src_y1 / static_cast<float>(texture.size.height));
} else {
- Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0),
- .y = static_cast<s32>(draw_texture_state.dst_y0)},
- Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1),
- .y = static_cast<s32>(draw_texture_state.dst_y1)}};
- Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0),
- .y = static_cast<s32>(draw_texture_state.src_y0)},
- Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1),
- .y = static_cast<s32>(draw_texture_state.src_y1)}};
blit_image.BlitColor(texture_cache.GetFramebuffer()->Handle(), texture.DefaultHandle(),
- sampler->Handle(), dst_region, src_region, texture.size);
+ sampler->Handle(), dst_region, src_region, src_size);
state_tracker.InvalidateState();
}
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:
}
});
}
- auto* ptr = device_memory.GetPointer<u8>(new_query->dependant_address);
- ASSERT(ptr != nullptr);
new_query->dependant_manage = must_manage_dependance;
pending_flush_queries.push_back(index);
@@ -1104,9 +1102,11 @@ public:
tfb_streamer.Free(query->dependant_index);
} else {
u8* pointer = device_memory.GetPointer<u8>(query->dependant_address);
- u32 result;
- std::memcpy(&result, pointer, sizeof(u32));
- num_vertices = static_cast<u64>(result) / query->stride;
+ if (pointer != nullptr) {
+ u32 result;
+ std::memcpy(&result, pointer, sizeof(u32));
+ num_vertices = static_cast<u64>(result) / query->stride;
+ }
}
query->value = [&]() -> u64 {
switch (query->topology) {
@@ -1360,7 +1360,9 @@ bool QueryCacheRuntime::HostConditionalRenderingCompareValues(VideoCommon::Looku
const auto check_value = [&](DAddr address) {
u8* ptr = impl->device_memory.GetPointer<u8>(address);
u64 value{};
- std::memcpy(&value, ptr, sizeof(value));
+ if (ptr != nullptr) {
+ std::memcpy(&value, ptr, sizeof(value));
+ }
return value == 0;
};
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 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
return value < 0 ? std::min<s32>(converted_value - acumm, -1)
: std::max<s32>(converted_value + acumm, 1);
};
+
+ const bool lower_left = regs.window_origin.mode != Maxwell::WindowOrigin::Mode::UpperLeft;
+ const s32 clip_height = regs.surface_clip.height;
+
+ // Flip coordinates if lower left
+ s32 min_y = lower_left ? (clip_height - src.max_y) : src.min_y.Value();
+ s32 max_y = lower_left ? (clip_height - src.min_y) : src.max_y.Value();
+
+ // Bound to render area
+ min_y = std::max(min_y, 0);
+ max_y = std::max(max_y, 0);
+
if (src.enable) {
- scissor.offset.x = scale_up(static_cast<s32>(src.min_x));
- scissor.offset.y = scale_up(static_cast<s32>(src.min_y));
+ scissor.offset.x = scale_up(src.min_x);
+ scissor.offset.y = scale_up(min_y);
scissor.extent.width = scale_up(src.max_x - src.min_x);
- scissor.extent.height = scale_up(src.max_y - src.min_y);
+ scissor.extent.height = scale_up(max_y - min_y);
} else {
scissor.offset.x = 0;
scissor.offset.y = 0;
@@ -308,17 +320,33 @@ void RasterizerVulkan::DrawTexture() {
const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState();
const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler);
const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture);
- Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0),
- .y = static_cast<s32>(draw_texture_state.dst_y0)},
- Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1),
- .y = static_cast<s32>(draw_texture_state.dst_y1)}};
- Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0),
- .y = static_cast<s32>(draw_texture_state.src_y0)},
- Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1),
- .y = static_cast<s32>(draw_texture_state.src_y1)}};
- blit_image.BlitColor(texture_cache.GetFramebuffer(), texture.RenderTarget(),
- texture.ImageHandle(), sampler->Handle(), dst_region, src_region,
- texture.size);
+ const auto* framebuffer = texture_cache.GetFramebuffer();
+
+ const bool src_rescaling = texture_cache.IsRescaling() && texture.IsRescaled();
+ const bool dst_rescaling = texture_cache.IsRescaling() && framebuffer->IsRescaled();
+
+ const auto ScaleSrc = [&](auto dim_f) -> s32 {
+ auto dim = static_cast<s32>(dim_f);
+ return src_rescaling ? Settings::values.resolution_info.ScaleUp(dim) : dim;
+ };
+
+ const auto ScaleDst = [&](auto dim_f) -> s32 {
+ auto dim = static_cast<s32>(dim_f);
+ return dst_rescaling ? Settings::values.resolution_info.ScaleUp(dim) : dim;
+ };
+
+ Region2D dst_region = {Offset2D{.x = ScaleDst(draw_texture_state.dst_x0),
+ .y = ScaleDst(draw_texture_state.dst_y0)},
+ Offset2D{.x = ScaleDst(draw_texture_state.dst_x1),
+ .y = ScaleDst(draw_texture_state.dst_y1)}};
+ Region2D src_region = {Offset2D{.x = ScaleSrc(draw_texture_state.src_x0),
+ .y = ScaleSrc(draw_texture_state.src_y0)},
+ Offset2D{.x = ScaleSrc(draw_texture_state.src_x1),
+ .y = ScaleSrc(draw_texture_state.src_y1)}};
+ Extent3D src_size = {static_cast<u32>(ScaleSrc(texture.size.width)),
+ static_cast<u32>(ScaleSrc(texture.size.height)), texture.size.depth};
+ blit_image.BlitColor(framebuffer, texture.RenderTarget(), texture.ImageHandle(),
+ sampler->Handle(), dst_region, src_region, src_size);
}
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
}
Framebuffer::Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer,
- ImageView* depth_buffer, VkExtent2D extent, bool is_rescaled)
+ ImageView* depth_buffer, VkExtent2D extent, bool is_rescaled_)
: render_area{extent} {
std::array<ImageView*, NUM_RT> color_buffers{color_buffer};
- CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled);
+ CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled_);
}
Framebuffer::~Framebuffer() = default;
void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime,
std::span<ImageView*, NUM_RT> color_buffers,
- ImageView* depth_buffer, bool is_rescaled) {
+ ImageView* depth_buffer, bool is_rescaled_) {
boost::container::small_vector<VkImageView, NUM_RT + 1> attachments;
RenderPassKey renderpass_key{};
s32 num_layers = 1;
+ is_rescaled = is_rescaled_;
const auto& resolution = runtime.resolution;
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:
return has_stencil;
}
+ [[nodiscard]] bool IsRescaled() const noexcept {
+ return is_rescaled;
+ }
+
private:
vk::Framebuffer framebuffer;
VkRenderPass renderpass{};
@@ -373,6 +377,7 @@ private:
std::array<size_t, NUM_RT> rt_map{};
bool has_depth{};
bool has_stencil{};
+ bool is_rescaled{};
};
struct TextureCacheParams {
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 53b4876f2..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
template <class P>
void TextureCache<P>::RunGarbageCollector() {
- bool high_priority_mode = total_used_memory >= expected_memory;
- bool aggressive_mode = total_used_memory >= critical_memory;
- const u64 ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL;
- size_t num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10);
- const auto clean_up = [this, &num_iterations, &high_priority_mode,
- &aggressive_mode](ImageId image_id) {
+ bool high_priority_mode = false;
+ bool aggressive_mode = false;
+ u64 ticks_to_destroy = 0;
+ size_t num_iterations = 0;
+
+ const auto Configure = [&](bool allow_aggressive) {
+ high_priority_mode = total_used_memory >= expected_memory;
+ aggressive_mode = allow_aggressive && total_used_memory >= critical_memory;
+ ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL;
+ num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10);
+ };
+ const auto Cleanup = [this, &num_iterations, &high_priority_mode,
+ &aggressive_mode](ImageId image_id) {
if (num_iterations == 0) {
return true;
}
@@ -123,7 +130,16 @@ void TextureCache<P>::RunGarbageCollector() {
}
return false;
};
- lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up);
+
+ // Try to remove anything old enough and not high priority.
+ Configure(false);
+ lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup);
+
+ // If pressure is still too high, prune aggressively.
+ if (total_used_memory >= critical_memory) {
+ Configure(true);
+ lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup);
+ }
}
template <class P>
@@ -2098,7 +2114,9 @@ void TextureCache<P>::TrackImage(ImageBase& image, ImageId image_id) {
ASSERT(False(image.flags & ImageFlagBits::Tracked));
image.flags |= ImageFlagBits::Tracked;
if (False(image.flags & ImageFlagBits::Sparse)) {
- device_memory.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, 1);
+ if (image.cpu_addr < ~(1ULL << 40)) {
+ device_memory.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, 1);
+ }
return;
}
if (True(image.flags & ImageFlagBits::Registered)) {
@@ -2124,7 +2142,9 @@ void TextureCache<P>::UntrackImage(ImageBase& image, ImageId image_id) {
ASSERT(True(image.flags & ImageFlagBits::Tracked));
image.flags &= ~ImageFlagBits::Tracked;
if (False(image.flags & ImageFlagBits::Sparse)) {
- device_memory.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, -1);
+ if (image.cpu_addr < ~(1ULL << 40)) {
+ device_memory.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, -1);
+ }
return;
}
ASSERT(True(image.flags & ImageFlagBits::Registered));