gl_texture_cache: Avoid format views on Intel and AMD
Intel and AMD proprietary drivers are incapable of rendering to texture views of different formats than the original texture. Avoid creating these at a cache level. This will consume more memory, emulating them with copies.
This commit is contained in:
parent
3a49c1a691
commit
7d904fef2e
|
@ -10,9 +10,7 @@
|
||||||
#include "video_core/surface.h"
|
#include "video_core/surface.h"
|
||||||
|
|
||||||
namespace VideoCore::Surface {
|
namespace VideoCore::Surface {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using Table = std::array<std::array<u64, 2>, MaxPixelFormat>;
|
using Table = std::array<std::array<u64, 2>, MaxPixelFormat>;
|
||||||
|
|
||||||
// Compatibility table taken from Table 3.X.2 in:
|
// Compatibility table taken from Table 3.X.2 in:
|
||||||
|
@ -233,10 +231,13 @@ constexpr Table MakeCopyTable() {
|
||||||
EnableRange(copy, COPY_CLASS_64_BITS);
|
EnableRange(copy, COPY_CLASS_64_BITS);
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b) {
|
bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_views) {
|
||||||
|
if (broken_views) {
|
||||||
|
// If format views are broken, only accept formats that are identical.
|
||||||
|
return format_a == format_b;
|
||||||
|
}
|
||||||
static constexpr Table TABLE = MakeViewTable();
|
static constexpr Table TABLE = MakeViewTable();
|
||||||
return IsSupported(TABLE, format_a, format_b);
|
return IsSupported(TABLE, format_a, format_b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace VideoCore::Surface {
|
namespace VideoCore::Surface {
|
||||||
|
|
||||||
bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b);
|
bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_views);
|
||||||
|
|
||||||
bool IsCopyCompatible(PixelFormat format_a, PixelFormat format_b);
|
bool IsCopyCompatible(PixelFormat format_a, PixelFormat format_b);
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,7 @@ Device::Device()
|
||||||
|
|
||||||
const bool is_nvidia = vendor == "NVIDIA Corporation";
|
const bool is_nvidia = vendor == "NVIDIA Corporation";
|
||||||
const bool is_amd = vendor == "ATI Technologies Inc.";
|
const bool is_amd = vendor == "ATI Technologies Inc.";
|
||||||
|
const bool is_intel = vendor == "Intel";
|
||||||
|
|
||||||
bool disable_fast_buffer_sub_data = false;
|
bool disable_fast_buffer_sub_data = false;
|
||||||
if (is_nvidia && version == "4.6.0 NVIDIA 443.24") {
|
if (is_nvidia && version == "4.6.0 NVIDIA 443.24") {
|
||||||
|
@ -231,6 +232,7 @@ Device::Device()
|
||||||
has_variable_aoffi = TestVariableAoffi();
|
has_variable_aoffi = TestVariableAoffi();
|
||||||
has_component_indexing_bug = is_amd;
|
has_component_indexing_bug = is_amd;
|
||||||
has_precise_bug = TestPreciseBug();
|
has_precise_bug = TestPreciseBug();
|
||||||
|
has_broken_texture_view_formats = is_amd || is_intel;
|
||||||
has_nv_viewport_array2 = GLAD_GL_NV_viewport_array2;
|
has_nv_viewport_array2 = GLAD_GL_NV_viewport_array2;
|
||||||
has_vertex_buffer_unified_memory = GLAD_GL_NV_vertex_buffer_unified_memory;
|
has_vertex_buffer_unified_memory = GLAD_GL_NV_vertex_buffer_unified_memory;
|
||||||
has_debugging_tool_attached = IsDebugToolAttached(extensions);
|
has_debugging_tool_attached = IsDebugToolAttached(extensions);
|
||||||
|
@ -248,6 +250,8 @@ Device::Device()
|
||||||
LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi);
|
LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi);
|
||||||
LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug);
|
LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug);
|
||||||
LOG_INFO(Render_OpenGL, "Renderer_PreciseBug: {}", has_precise_bug);
|
LOG_INFO(Render_OpenGL, "Renderer_PreciseBug: {}", has_precise_bug);
|
||||||
|
LOG_INFO(Render_OpenGL, "Renderer_BrokenTextureViewFormats: {}",
|
||||||
|
has_broken_texture_view_formats);
|
||||||
|
|
||||||
if (Settings::values.use_assembly_shaders.GetValue() && !use_assembly_shaders) {
|
if (Settings::values.use_assembly_shaders.GetValue() && !use_assembly_shaders) {
|
||||||
LOG_ERROR(Render_OpenGL, "Assembly shaders enabled but not supported");
|
LOG_ERROR(Render_OpenGL, "Assembly shaders enabled but not supported");
|
||||||
|
|
|
@ -96,6 +96,10 @@ public:
|
||||||
return has_precise_bug;
|
return has_precise_bug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasBrokenTextureViewFormats() const {
|
||||||
|
return has_broken_texture_view_formats;
|
||||||
|
}
|
||||||
|
|
||||||
bool HasFastBufferSubData() const {
|
bool HasFastBufferSubData() const {
|
||||||
return has_fast_buffer_sub_data;
|
return has_fast_buffer_sub_data;
|
||||||
}
|
}
|
||||||
|
@ -137,6 +141,7 @@ private:
|
||||||
bool has_variable_aoffi{};
|
bool has_variable_aoffi{};
|
||||||
bool has_component_indexing_bug{};
|
bool has_component_indexing_bug{};
|
||||||
bool has_precise_bug{};
|
bool has_precise_bug{};
|
||||||
|
bool has_broken_texture_view_formats{};
|
||||||
bool has_fast_buffer_sub_data{};
|
bool has_fast_buffer_sub_data{};
|
||||||
bool has_nv_viewport_array2{};
|
bool has_nv_viewport_array2{};
|
||||||
bool has_debugging_tool_attached{};
|
bool has_debugging_tool_attached{};
|
||||||
|
|
|
@ -430,6 +430,8 @@ TextureCacheRuntime::TextureCacheRuntime(const Device& device_, ProgramManager&
|
||||||
format_properties[i].emplace(format, properties);
|
format_properties[i].emplace(format, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
has_broken_texture_view_formats = device.HasBrokenTextureViewFormats();
|
||||||
|
|
||||||
null_image_1d_array.Create(GL_TEXTURE_1D_ARRAY);
|
null_image_1d_array.Create(GL_TEXTURE_1D_ARRAY);
|
||||||
null_image_cube_array.Create(GL_TEXTURE_CUBE_MAP_ARRAY);
|
null_image_cube_array.Create(GL_TEXTURE_CUBE_MAP_ARRAY);
|
||||||
null_image_3d.Create(GL_TEXTURE_3D);
|
null_image_3d.Create(GL_TEXTURE_3D);
|
||||||
|
|
|
@ -104,6 +104,11 @@ struct TextureCacheRuntime {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InsertUploadMemoryBarrier() {}
|
void InsertUploadMemoryBarrier() {}
|
||||||
|
|
||||||
|
bool HasBrokenTextureViewFormats() const noexcept {
|
||||||
|
// No known Vulkan driver has broken image views
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Image : public VideoCommon::ImageBase {
|
class Image : public VideoCommon::ImageBase {
|
||||||
|
|
|
@ -120,7 +120,9 @@ void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_i
|
||||||
if (lhs.info.type == ImageType::Linear) {
|
if (lhs.info.type == ImageType::Linear) {
|
||||||
base = SubresourceBase{.level = 0, .layer = 0};
|
base = SubresourceBase{.level = 0, .layer = 0};
|
||||||
} else {
|
} else {
|
||||||
base = FindSubresource(rhs.info, lhs, rhs.gpu_addr, OPTIONS);
|
// We are passing relaxed formats as an option, having broken views or not won't matter
|
||||||
|
static constexpr bool broken_views = false;
|
||||||
|
base = FindSubresource(rhs.info, lhs, rhs.gpu_addr, OPTIONS, broken_views);
|
||||||
}
|
}
|
||||||
if (!base) {
|
if (!base) {
|
||||||
LOG_ERROR(HW_GPU, "Image alias should have been flipped");
|
LOG_ERROR(HW_GPU, "Image alias should have been flipped");
|
||||||
|
|
|
@ -24,7 +24,7 @@ ImageViewBase::ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_i
|
||||||
.height = std::max(image_info.size.height >> range.base.level, 1u),
|
.height = std::max(image_info.size.height >> range.base.level, 1u),
|
||||||
.depth = std::max(image_info.size.depth >> range.base.level, 1u),
|
.depth = std::max(image_info.size.depth >> range.base.level, 1u),
|
||||||
} {
|
} {
|
||||||
ASSERT_MSG(VideoCore::Surface::IsViewCompatible(image_info.format, info.format),
|
ASSERT_MSG(VideoCore::Surface::IsViewCompatible(image_info.format, info.format, false),
|
||||||
"Image view format {} is incompatible with image format {}", info.format,
|
"Image view format {} is incompatible with image format {}", info.format,
|
||||||
image_info.format);
|
image_info.format);
|
||||||
const bool is_async = Settings::values.use_asynchronous_gpu_emulation.GetValue();
|
const bool is_async = Settings::values.use_asynchronous_gpu_emulation.GetValue();
|
||||||
|
|
|
@ -883,6 +883,7 @@ ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
|
||||||
if (!cpu_addr) {
|
if (!cpu_addr) {
|
||||||
return ImageId{};
|
return ImageId{};
|
||||||
}
|
}
|
||||||
|
const bool broken_views = runtime.HasBrokenTextureViewFormats();
|
||||||
ImageId image_id;
|
ImageId image_id;
|
||||||
const auto lambda = [&](ImageId existing_image_id, ImageBase& existing_image) {
|
const auto lambda = [&](ImageId existing_image_id, ImageBase& existing_image) {
|
||||||
if (info.type == ImageType::Linear || existing_image.info.type == ImageType::Linear) {
|
if (info.type == ImageType::Linear || existing_image.info.type == ImageType::Linear) {
|
||||||
|
@ -892,11 +893,11 @@ ImageId TextureCache<P>::FindImage(const ImageInfo& info, GPUVAddr gpu_addr,
|
||||||
if (existing_image.gpu_addr == gpu_addr && existing.type == info.type &&
|
if (existing_image.gpu_addr == gpu_addr && existing.type == info.type &&
|
||||||
existing.pitch == info.pitch &&
|
existing.pitch == info.pitch &&
|
||||||
IsPitchLinearSameSize(existing, info, strict_size) &&
|
IsPitchLinearSameSize(existing, info, strict_size) &&
|
||||||
IsViewCompatible(existing.format, info.format)) {
|
IsViewCompatible(existing.format, info.format, broken_views)) {
|
||||||
image_id = existing_image_id;
|
image_id = existing_image_id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (IsSubresource(info, existing_image, gpu_addr, options)) {
|
} else if (IsSubresource(info, existing_image, gpu_addr, options, broken_views)) {
|
||||||
image_id = existing_image_id;
|
image_id = existing_image_id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -926,6 +927,7 @@ template <class P>
|
||||||
ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr) {
|
ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr) {
|
||||||
ImageInfo new_info = info;
|
ImageInfo new_info = info;
|
||||||
const size_t size_bytes = CalculateGuestSizeInBytes(new_info);
|
const size_t size_bytes = CalculateGuestSizeInBytes(new_info);
|
||||||
|
const bool broken_views = runtime.HasBrokenTextureViewFormats();
|
||||||
std::vector<ImageId> overlap_ids;
|
std::vector<ImageId> overlap_ids;
|
||||||
std::vector<ImageId> left_aliased_ids;
|
std::vector<ImageId> left_aliased_ids;
|
||||||
std::vector<ImageId> right_aliased_ids;
|
std::vector<ImageId> right_aliased_ids;
|
||||||
|
@ -940,7 +942,9 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto solution = ResolveOverlap(new_info, gpu_addr, cpu_addr, overlap, true);
|
static constexpr bool strict_size = true;
|
||||||
|
const std::optional<OverlapResult> solution =
|
||||||
|
ResolveOverlap(new_info, gpu_addr, cpu_addr, overlap, strict_size, broken_views);
|
||||||
if (solution) {
|
if (solution) {
|
||||||
gpu_addr = solution->gpu_addr;
|
gpu_addr = solution->gpu_addr;
|
||||||
cpu_addr = solution->cpu_addr;
|
cpu_addr = solution->cpu_addr;
|
||||||
|
@ -950,9 +954,10 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA
|
||||||
}
|
}
|
||||||
static constexpr auto options = RelaxedOptions::Size | RelaxedOptions::Format;
|
static constexpr auto options = RelaxedOptions::Size | RelaxedOptions::Format;
|
||||||
const ImageBase new_image_base(new_info, gpu_addr, cpu_addr);
|
const ImageBase new_image_base(new_info, gpu_addr, cpu_addr);
|
||||||
if (IsSubresource(new_info, overlap, gpu_addr, options)) {
|
if (IsSubresource(new_info, overlap, gpu_addr, options, broken_views)) {
|
||||||
left_aliased_ids.push_back(overlap_id);
|
left_aliased_ids.push_back(overlap_id);
|
||||||
} else if (IsSubresource(overlap.info, new_image_base, overlap.gpu_addr, options)) {
|
} else if (IsSubresource(overlap.info, new_image_base, overlap.gpu_addr, options,
|
||||||
|
broken_views)) {
|
||||||
right_aliased_ids.push_back(overlap_id);
|
right_aliased_ids.push_back(overlap_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1069,13 +1069,13 @@ bool IsPitchLinearSameSize(const ImageInfo& lhs, const ImageInfo& rhs, bool stri
|
||||||
|
|
||||||
std::optional<OverlapResult> ResolveOverlap(const ImageInfo& new_info, GPUVAddr gpu_addr,
|
std::optional<OverlapResult> ResolveOverlap(const ImageInfo& new_info, GPUVAddr gpu_addr,
|
||||||
VAddr cpu_addr, const ImageBase& overlap,
|
VAddr cpu_addr, const ImageBase& overlap,
|
||||||
bool strict_size) {
|
bool strict_size, bool broken_views) {
|
||||||
ASSERT(new_info.type != ImageType::Linear);
|
ASSERT(new_info.type != ImageType::Linear);
|
||||||
ASSERT(overlap.info.type != ImageType::Linear);
|
ASSERT(overlap.info.type != ImageType::Linear);
|
||||||
if (!IsLayerStrideCompatible(new_info, overlap.info)) {
|
if (!IsLayerStrideCompatible(new_info, overlap.info)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
if (!IsViewCompatible(overlap.info.format, new_info.format)) {
|
if (!IsViewCompatible(overlap.info.format, new_info.format, broken_views)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
if (gpu_addr == overlap.gpu_addr) {
|
if (gpu_addr == overlap.gpu_addr) {
|
||||||
|
@ -1118,14 +1118,15 @@ bool IsLayerStrideCompatible(const ImageInfo& lhs, const ImageInfo& rhs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const ImageBase& image,
|
std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const ImageBase& image,
|
||||||
GPUVAddr candidate_addr, RelaxedOptions options) {
|
GPUVAddr candidate_addr, RelaxedOptions options,
|
||||||
|
bool broken_views) {
|
||||||
const std::optional<SubresourceBase> base = image.TryFindBase(candidate_addr);
|
const std::optional<SubresourceBase> base = image.TryFindBase(candidate_addr);
|
||||||
if (!base) {
|
if (!base) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
const ImageInfo& existing = image.info;
|
const ImageInfo& existing = image.info;
|
||||||
if (False(options & RelaxedOptions::Format)) {
|
if (False(options & RelaxedOptions::Format)) {
|
||||||
if (!IsViewCompatible(existing.format, candidate.format)) {
|
if (!IsViewCompatible(existing.format, candidate.format, broken_views)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1162,8 +1163,8 @@ std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSubresource(const ImageInfo& candidate, const ImageBase& image, GPUVAddr candidate_addr,
|
bool IsSubresource(const ImageInfo& candidate, const ImageBase& image, GPUVAddr candidate_addr,
|
||||||
RelaxedOptions options) {
|
RelaxedOptions options, bool broken_views) {
|
||||||
return FindSubresource(candidate, image, candidate_addr, options).has_value();
|
return FindSubresource(candidate, image, candidate_addr, options, broken_views).has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
|
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
|
||||||
|
|
|
@ -87,17 +87,19 @@ void SwizzleImage(Tegra::MemoryManager& gpu_memory, GPUVAddr gpu_addr, const Ima
|
||||||
[[nodiscard]] std::optional<OverlapResult> ResolveOverlap(const ImageInfo& new_info,
|
[[nodiscard]] std::optional<OverlapResult> ResolveOverlap(const ImageInfo& new_info,
|
||||||
GPUVAddr gpu_addr, VAddr cpu_addr,
|
GPUVAddr gpu_addr, VAddr cpu_addr,
|
||||||
const ImageBase& overlap,
|
const ImageBase& overlap,
|
||||||
bool strict_size);
|
bool strict_size, bool broken_views);
|
||||||
|
|
||||||
[[nodiscard]] bool IsLayerStrideCompatible(const ImageInfo& lhs, const ImageInfo& rhs);
|
[[nodiscard]] bool IsLayerStrideCompatible(const ImageInfo& lhs, const ImageInfo& rhs);
|
||||||
|
|
||||||
[[nodiscard]] std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate,
|
[[nodiscard]] std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate,
|
||||||
const ImageBase& image,
|
const ImageBase& image,
|
||||||
GPUVAddr candidate_addr,
|
GPUVAddr candidate_addr,
|
||||||
RelaxedOptions options);
|
RelaxedOptions options,
|
||||||
|
bool broken_views);
|
||||||
|
|
||||||
[[nodiscard]] bool IsSubresource(const ImageInfo& candidate, const ImageBase& image,
|
[[nodiscard]] bool IsSubresource(const ImageInfo& candidate, const ImageBase& image,
|
||||||
GPUVAddr candidate_addr, RelaxedOptions options);
|
GPUVAddr candidate_addr, RelaxedOptions options,
|
||||||
|
bool broken_views);
|
||||||
|
|
||||||
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
|
void DeduceBlitImages(ImageInfo& dst_info, ImageInfo& src_info, const ImageBase* dst,
|
||||||
const ImageBase* src);
|
const ImageBase* src);
|
||||||
|
|
Loading…
Reference in New Issue