aboutsummaryrefslogtreecommitdiff
path: root/src/video_core/renderer_vulkan
diff options
context:
space:
mode:
authorCamilleLaVey <camillelavey99@gmail.com>2026-07-09 06:55:54 +0200
committercrueter <crueter@eden-emu.dev>2026-07-09 06:55:54 +0200
commit372bdfccbc06aead40fc4d14620df6c292728656 (patch)
tree339492949dca538f67e64836c6bf1687bbc0f5e4 /src/video_core/renderer_vulkan
parent3699795315a1fa4d47542f70da0c6c6e529697e6 (diff)
[vulkan, android] Mediacodec implementation + Vulkan fixes (#4191)
This is the first step into the conversion on full GPU video decoding for Android; currently due to the VIC structure, I couldn't set it on surface mode to prevent the latency when sending video decoded (which is processed by GPU now), because currently we convert YUV420 into the Nvidia's format each frame constantly on CPU, aside the requirements from other extensions to work + VIC rewrite, which is a work currently not planned to happen on this PR; the actual configuration for video decoding is ByteBuffer, using GPU to decode NVDEC data (all codecs supported, h264, vp8 and vp9) and send it to CPU for display purposes, which is more faster than relying purely on CPU for any drawing task, saving devices resources/ heating, the downside on this will be the slight latency when a new frame is displayed, which is gonna be a black frame for less than a second, nothing major to harm the experience rather than actually trying our best to take advantage on hardware accelerated. Aside this, I also added a bunch of minor Vulkan fixes to grant drivers less thinkering when receiving spir-v instructions, meaning this has new bans for extensions on QCOM (following reported issues on other projects working around Adreno driver behavior), this more than providing performance aims to enhance the stability on the driver, performance it's gonna likely to be hit based on the UBO's (StorageBufferAccess) operations and SSBO (uniformStorageBufferAccess), there was an already existing path for the emulation which forces to wide them into 32bit packed operations. I also included some smaller changes/ bugs + VUID's fixes from earlier changes on my work. Special Thanks: -> Mr. Smoly Gidolard (@gidoly) Sources: 1.- https://github.com/microsoft/DirectXShaderCompiler/issues/2842 2.- https://github.com/mlc-ai/web-llm/issues/836 3.- https://github.com/ggml-org/llama.cpp/issues/5186 4.- https://github.com/encounter/aurora/pull/202 Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4191
Diffstat (limited to 'src/video_core/renderer_vulkan')
-rw-r--r--src/video_core/renderer_vulkan/pipeline_helper.h4
-rw-r--r--src/video_core/renderer_vulkan/vk_compute_pass.cpp6
-rw-r--r--src/video_core/renderer_vulkan/vk_compute_pipeline.cpp25
-rw-r--r--src/video_core/renderer_vulkan/vk_compute_pipeline.h3
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.cpp18
-rw-r--r--src/video_core/renderer_vulkan/vk_query_cache.cpp5
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.cpp53
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.h17
8 files changed, 107 insertions, 24 deletions
diff --git a/src/video_core/renderer_vulkan/pipeline_helper.h b/src/video_core/renderer_vulkan/pipeline_helper.h
index 0523a040c8..882372aee2 100644
--- a/src/video_core/renderer_vulkan/pipeline_helper.h
+++ b/src/video_core/renderer_vulkan/pipeline_helper.h
@@ -242,6 +242,10 @@ inline void PushImageDescriptors(TextureCache& texture_cache,
VideoCore::Surface::IsPixelFormatInteger(image_view.format)) {
vk_sampler = sampler.HandleWithNearestFilter();
}
+ if (desc.is_depth && sampler.HasDepthComparison() &&
+ !image_view.SupportsDepthComparison()) {
+ vk_sampler = sampler.HandleWithoutDepthComparison();
+ }
guest_descriptor_queue.AddSampledImage(vk_image_view, vk_sampler);
const bool element_rescaled{texture_cache.IsRescaling(image_view)};
is_rescaled |= element_rescaled;
diff --git a/src/video_core/renderer_vulkan/vk_compute_pass.cpp b/src/video_core/renderer_vulkan/vk_compute_pass.cpp
index f361c34f44..edc0283d9a 100644
--- a/src/video_core/renderer_vulkan/vk_compute_pass.cpp
+++ b/src/video_core/renderer_vulkan/vk_compute_pass.cpp
@@ -746,10 +746,8 @@ void BlockLinearUnswizzle3DPass::Unswizzle(
const u32 MAX_BATCH_SLICES = (std::min)(z_count, image.info.size.depth);
- if (!image.has_compute_unswizzle_buffer) {
- // Allocate exactly what this batch needs
- image.AllocateComputeUnswizzleBuffer(MAX_BATCH_SLICES);
- }
+ // Allocate or grow to cover this batch's slice count
+ image.AllocateComputeUnswizzleBuffer(MAX_BATCH_SLICES);
ASSERT(swizzles.size() == 1);
const auto& sw = swizzles[0];
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
index 5525ce0e95..006bfc0a09 100644
--- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
+++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp
@@ -22,6 +22,7 @@
#include "video_core/vulkan_common/vulkan_device.h"
#include "video_core/vulkan_common/vulkan_wrapper.h"
#include "video_core/gpu_logging/gpu_logging.h"
+#include "common/logging.h"
#include "common/settings.h"
namespace Vulkan {
@@ -36,10 +37,10 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
Common::ThreadWorker* thread_worker,
PipelineStatistics* pipeline_statistics,
VideoCore::ShaderNotify* shader_notify, const Shader::Info& info_,
- vk::ShaderModule spv_module_)
+ vk::ShaderModule spv_module_, u64 shader_hash_)
: device{device_},
pipeline_cache(pipeline_cache_), guest_descriptor_queue{guest_descriptor_queue_}, info{info_},
- spv_module(std::move(spv_module_)) {
+ shader_hash{shader_hash_}, spv_module(std::move(spv_module_)) {
if (shader_notify) {
shader_notify->MarkShaderBuilding();
}
@@ -68,7 +69,7 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
if (device.IsKhrPipelineExecutablePropertiesEnabled() && Settings::values.renderer_debug.GetValue()) {
flags |= VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR;
}
- pipeline = device.GetLogical().CreateComputePipeline(VkComputePipelineCreateInfo{
+ const VkComputePipelineCreateInfo compute_ci{
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
.pNext = nullptr,
.flags = flags,
@@ -85,7 +86,20 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
.layout = *pipeline_layout,
.basePipelineHandle = 0,
.basePipelineIndex = 0,
- }, *pipeline_cache);
+ };
+ try {
+ pipeline = device.GetLogical().CreateComputePipeline(compute_ci, *pipeline_cache);
+ } catch (const vk::Exception& exception) {
+ LOG_CRITICAL(Render_Vulkan, "Adreno rejected compute shader {:016X}: {}", shader_hash,
+ exception.what());
+ std::scoped_lock lock{build_mutex};
+ is_built = true;
+ build_condvar.notify_one();
+ if (shader_notify) {
+ shader_notify->MarkShaderComplete();
+ }
+ return;
+ }
// Log compute pipeline creation
if (GPU::Logging::IsActive()) {
@@ -239,6 +253,9 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
const bool is_rescaling = !info.texture_descriptors.empty() || !info.image_descriptors.empty();
scheduler.Record([this, descriptor_data, is_rescaling,
rescaling_data = rescaling.Data()](vk::CommandBuffer cmdbuf) {
+ if (!pipeline) {
+ return;
+ }
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
if (!descriptor_set_layout) {
return;
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.h b/src/video_core/renderer_vulkan/vk_compute_pipeline.h
index 1feeed4840..c9704b7c6c 100644
--- a/src/video_core/renderer_vulkan/vk_compute_pipeline.h
+++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.h
@@ -37,7 +37,7 @@ public:
Common::ThreadWorker* thread_worker,
PipelineStatistics* pipeline_statistics,
VideoCore::ShaderNotify* shader_notify, const Shader::Info& info,
- vk::ShaderModule spv_module);
+ vk::ShaderModule spv_module, u64 shader_hash);
ComputePipeline& operator=(ComputePipeline&&) noexcept = delete;
ComputePipeline(ComputePipeline&&) noexcept = delete;
@@ -53,6 +53,7 @@ private:
vk::PipelineCache& pipeline_cache;
GuestDescriptorQueue& guest_descriptor_queue;
Shader::Info info;
+ u64 shader_hash{};
u32 num_descriptor_entries{};
VideoCommon::ComputeUniformBufferSizes uniform_buffer_sizes{};
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
index 2eea66802d..6ca9fe4c71 100644
--- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
@@ -353,6 +353,20 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
serialization_thread(1, "VkPipelineSerialization") {
const auto& float_control{device.FloatControlProperties()};
const VkDriverId driver_id{device.GetDriverID()};
+ const VkShaderStageFlags subgroup_stages{device.GetSubgroupSupportedStages()};
+ const auto subgroup_stage_bit{[subgroup_stages](VkShaderStageFlags flag, Shader::Stage stage) {
+ return (subgroup_stages & flag) != 0 ? (1u << static_cast<u32>(stage)) : 0u;
+ }};
+ const u32 supported_subgroup_stages{
+ subgroup_stage_bit(VK_SHADER_STAGE_VERTEX_BIT, Shader::Stage::VertexA) |
+ subgroup_stage_bit(VK_SHADER_STAGE_VERTEX_BIT, Shader::Stage::VertexB) |
+ subgroup_stage_bit(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
+ Shader::Stage::TessellationControl) |
+ subgroup_stage_bit(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
+ Shader::Stage::TessellationEval) |
+ subgroup_stage_bit(VK_SHADER_STAGE_GEOMETRY_BIT, Shader::Stage::Geometry) |
+ subgroup_stage_bit(VK_SHADER_STAGE_FRAGMENT_BIT, Shader::Stage::Fragment) |
+ subgroup_stage_bit(VK_SHADER_STAGE_COMPUTE_BIT, Shader::Stage::Compute)};
profile = Shader::Profile{
.supported_spirv = device.SupportedSpirvVersion(),
.unified_descriptor_binding = true,
@@ -382,6 +396,7 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
float_control.shaderSignedZeroInfNanPreserveFloat64 != VK_FALSE,
.support_explicit_workgroup_layout = device.IsKhrWorkgroupMemoryExplicitLayoutSupported(),
.support_vote = device.IsSubgroupFeatureSupported(VK_SUBGROUP_FEATURE_VOTE_BIT),
+ .supported_subgroup_stages = supported_subgroup_stages,
.support_viewport_index_layer_non_geometry =
device.IsExtShaderViewportIndexLayerSupported(),
.support_viewport_mask = device.IsNvViewportArray2Supported(),
@@ -930,7 +945,8 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline(
Common::ThreadWorker* const thread_worker{build_in_parallel ? &workers : nullptr};
return std::make_unique<ComputePipeline>(device, scheduler, vulkan_pipeline_cache, descriptor_pool,
guest_descriptor_queue, thread_worker, statistics,
- &shader_notify, program.info, std::move(spv_module));
+ &shader_notify, program.info, std::move(spv_module),
+ key.unique_hash);
} catch (const Shader::Exception& exception) {
LOG_ERROR(Render_Vulkan, "{}", exception.what());
diff --git a/src/video_core/renderer_vulkan/vk_query_cache.cpp b/src/video_core/renderer_vulkan/vk_query_cache.cpp
index 8d352f3b73..709f65dc25 100644
--- a/src/video_core/renderer_vulkan/vk_query_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_query_cache.cpp
@@ -236,7 +236,8 @@ public:
}
PauseCounter();
const auto driver_id = device.GetDriverID();
- if (driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
+ if (driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
+ driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
pending_sync.clear();
sync_values_stash.clear();
return;
@@ -1520,7 +1521,7 @@ bool QueryCacheRuntime::HostConditionalRenderingCompareValues(VideoCommon::Looku
auto driver_id = impl->device.GetDriverID();
const bool is_gpu_high = Settings::IsGPULevelHigh();
- if ((!is_gpu_high && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) || driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
+ if ((!is_gpu_high && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) || driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY || driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
EndHostConditionalRendering();
return true;
}
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index ac4bc29905..960dafb99d 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -1635,9 +1635,6 @@ Image::Image(const VideoCommon::NullImageParams& params) : VideoCommon::ImageBas
Image::~Image() = default;
void Image::AllocateComputeUnswizzleBuffer(u32 max_slices) {
- if (has_compute_unswizzle_buffer)
- return;
-
using VideoCore::Surface::BytesPerBlock;
const u32 block_bytes = BytesPerBlock(info.format); // 8 for BC1, 16 for BC6H
@@ -1654,7 +1651,12 @@ void Image::AllocateComputeUnswizzleBuffer(u32 max_slices) {
static_cast<u64>(blocks_y) *
static_cast<u64>(blocks_z);
- compute_unswizzle_buffer_size = block_count * block_bytes;
+ const VkDeviceSize required_size = block_count * block_bytes;
+ if (has_compute_unswizzle_buffer && required_size <= compute_unswizzle_buffer_size) {
+ return;
+ }
+
+ compute_unswizzle_buffer_size = required_size;
VkBufferCreateInfo ci{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
@@ -2152,6 +2154,15 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewI
if (uses_widened_astc_format) {
format_info.format = VK_FORMAT_R32G32B32A32_SFLOAT;
}
+ if (device->ApiVersion() >= VK_API_VERSION_1_3) {
+ const VkFormatProperties3 properties3 =
+ device->GetPhysical().GetFormatProperties3(format_info.format);
+ supports_depth_comparison =
+ (properties3.optimalTilingFeatures &
+ VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT) != 0;
+ } else {
+ supports_depth_comparison = true;
+ }
const VkImageUsageFlags requested_view_usage = ImageUsageFlags(format_info, format);
const VkImageUsageFlags image_usage = image.UsageFlags();
const VkImageUsageFlags clamped_view_usage = requested_view_usage & image_usage;
@@ -2290,7 +2301,7 @@ VkImageView ImageView::StorageView(Shader::TextureType texture_type,
if (uses_widened_astc_format) {
info.format = VK_FORMAT_R32G32B32A32_SFLOAT;
}
- typeless_storage_view = MakeView(info.format, VK_IMAGE_ASPECT_COLOR_BIT);
+ typeless_storage_view = MakeView(info.format, VK_IMAGE_ASPECT_COLOR_BIT, texture_type);
}
return *typeless_storage_view;
}
@@ -2301,7 +2312,7 @@ VkImageView ImageView::StorageView(Shader::TextureType texture_type,
auto& views{is_signed ? storage_views->signeds : storage_views->unsigneds};
auto& view{views[size_t(texture_type)]};
if (!view)
- view = MakeView(Format(image_format), VK_IMAGE_ASPECT_COLOR_BIT);
+ view = MakeView(Format(image_format), VK_IMAGE_ASPECT_COLOR_BIT, texture_type);
return *view;
}
return VK_NULL_HANDLE;
@@ -2311,13 +2322,28 @@ bool ImageView::IsRescaled() const noexcept {
return (*slot_images)[image_id].IsRescaled();
}
-vk::ImageView ImageView::MakeView(VkFormat vk_format, VkImageAspectFlags aspect_mask) {
+vk::ImageView ImageView::MakeView(VkFormat vk_format, VkImageAspectFlags aspect_mask,
+ std::optional<Shader::TextureType> texture_type) {
+ VkImageViewType view_type = ImageViewType(type);
+ VkImageSubresourceRange subresource_range = MakeSubresourceRange(aspect_mask, range);
+ if (texture_type) {
+ view_type = ImageViewType(*texture_type);
+ switch (view_type) {
+ case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
+ case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
+ case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
+ break;
+ default:
+ subresource_range.layerCount = 1;
+ break;
+ }
+ }
return device->GetLogical().CreateImageView({
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.image = image_handle,
- .viewType = ImageViewType(type),
+ .viewType = view_type,
.format = vk_format,
.components{
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
@@ -2325,7 +2351,7 @@ vk::ImageView ImageView::MakeView(VkFormat vk_format, VkImageAspectFlags aspect_
.b = VK_COMPONENT_SWIZZLE_IDENTITY,
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
},
- .subresourceRange = MakeSubresourceRange(aspect_mask, range),
+ .subresourceRange = subresource_range,
});
}
@@ -2376,7 +2402,8 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const Tegra::Texture::TSCEntry& t
min_filter == VK_FILTER_LINEAR ||
mipmap_mode == VK_SAMPLER_MIPMAP_MODE_LINEAR};
- const auto create_sampler = [&](const f32 anisotropy, bool force_nearest) {
+ const auto create_sampler = [&](const f32 anisotropy, bool force_nearest,
+ bool disable_compare = false) {
return device.GetLogical().CreateSampler(VkSamplerCreateInfo{
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = pnext,
@@ -2391,7 +2418,8 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const Tegra::Texture::TSCEntry& t
.anisotropyEnable =
static_cast<VkBool32>(!force_nearest && anisotropy > 1.0f ? VK_TRUE : VK_FALSE),
.maxAnisotropy = force_nearest ? 1.0f : anisotropy,
- .compareEnable = tsc.depth_compare_enabled,
+ .compareEnable = disable_compare ? VK_FALSE
+ : static_cast<VkBool32>(tsc.depth_compare_enabled),
.compareOp = MaxwellToVK::Sampler::DepthCompareFunction(tsc.depth_compare_func),
.minLod = tsc.mipmap_filter == TextureMipmapFilter::None ? 0.0f : tsc.MinLod(),
.maxLod = tsc.mipmap_filter == TextureMipmapFilter::None ? 0.25f : tsc.MaxLod(),
@@ -2410,6 +2438,9 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const Tegra::Texture::TSCEntry& t
if (has_linear_filtering) {
sampler_nearest = create_sampler(1.0f, true);
}
+ if (tsc.depth_compare_enabled) {
+ sampler_noncompare = create_sampler(max_anisotropy, false, true);
+ }
}
Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM_RT> color_buffers,
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h
index 027143fdbc..13f51555a3 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.h
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.h
@@ -356,6 +356,10 @@ public:
return samples;
}
+ [[nodiscard]] bool SupportsDepthComparison() const noexcept {
+ return supports_depth_comparison;
+ }
+
[[nodiscard]] GPUVAddr GpuAddr() const noexcept {
return gpu_addr;
}
@@ -370,7 +374,8 @@ private:
std::array<vk::ImageView, Shader::NUM_TEXTURE_TYPES> unsigneds;
};
- [[nodiscard]] vk::ImageView MakeView(VkFormat vk_format, VkImageAspectFlags aspect_mask);
+ [[nodiscard]] vk::ImageView MakeView(VkFormat vk_format, VkImageAspectFlags aspect_mask,
+ std::optional<Shader::TextureType> texture_type = std::nullopt);
const Device* device = nullptr;
const SlotVector<Image>* slot_images = nullptr;
@@ -388,6 +393,7 @@ private:
u32 buffer_size = 0;
bool uses_widened_astc_format = false;
+ bool supports_depth_comparison = false;
};
class ImageAlloc : public VideoCommon::ImageAllocBase {};
@@ -416,10 +422,19 @@ public:
return static_cast<bool>(sampler_nearest);
}
+ [[nodiscard]] VkSampler HandleWithoutDepthComparison() const noexcept {
+ return *sampler_noncompare;
+ }
+
+ [[nodiscard]] bool HasDepthComparison() const noexcept {
+ return static_cast<bool>(sampler_noncompare);
+ }
+
private:
vk::Sampler sampler;
vk::Sampler sampler_default_anisotropy;
vk::Sampler sampler_nearest;
+ vk::Sampler sampler_noncompare;
};
struct TextureCacheParams {