diff options
| author | 2021-05-23 04:28:34 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:30 -0400 | |
| commit | d621e96d0de212cc16897eadf71e8a1b2e1eb5dc (patch) | |
| tree | 8695f2f4dddf2564b63e4574d6616ccb0e79568c /src/video_core/renderer_vulkan | |
| parent | spirv: Be aware of NAN unaware drivers (diff) | |
| download | yuzu-d621e96d0de212cc16897eadf71e8a1b2e1eb5dc.tar.gz yuzu-d621e96d0de212cc16897eadf71e8a1b2e1eb5dc.tar.xz yuzu-d621e96d0de212cc16897eadf71e8a1b2e1eb5dc.zip | |
shader: Initial OpenGL implementation
Diffstat (limited to 'src/video_core/renderer_vulkan')
6 files changed, 31 insertions, 66 deletions
diff --git a/src/video_core/renderer_vulkan/pipeline_helper.h b/src/video_core/renderer_vulkan/pipeline_helper.h index dd7d2cc0c..c6e5e059b 100644 --- a/src/video_core/renderer_vulkan/pipeline_helper.h +++ b/src/video_core/renderer_vulkan/pipeline_helper.h | |||
| @@ -19,23 +19,6 @@ | |||
| 19 | 19 | ||
| 20 | namespace Vulkan { | 20 | namespace Vulkan { |
| 21 | 21 | ||
| 22 | struct TextureHandle { | ||
| 23 | explicit TextureHandle(u32 data, bool via_header_index) { | ||
| 24 | [[likely]] if (via_header_index) { | ||
| 25 | image = data; | ||
| 26 | sampler = data; | ||
| 27 | } | ||
| 28 | else { | ||
| 29 | const Tegra::Texture::TextureHandle handle{data}; | ||
| 30 | image = handle.tic_id; | ||
| 31 | sampler = via_header_index ? image : handle.tsc_id.Value(); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | u32 image; | ||
| 36 | u32 sampler; | ||
| 37 | }; | ||
| 38 | |||
| 39 | class DescriptorLayoutBuilder { | 22 | class DescriptorLayoutBuilder { |
| 40 | public: | 23 | public: |
| 41 | DescriptorLayoutBuilder(const vk::Device& device_) : device{&device_} {} | 24 | DescriptorLayoutBuilder(const vk::Device& device_) : device{&device_} {} |
diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.h b/src/video_core/renderer_vulkan/vk_buffer_cache.h index c52001b5a..c27402ff0 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.h +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.h | |||
| @@ -140,8 +140,8 @@ struct BufferCacheParams { | |||
| 140 | static constexpr bool HAS_FULL_INDEX_AND_PRIMITIVE_SUPPORT = false; | 140 | static constexpr bool HAS_FULL_INDEX_AND_PRIMITIVE_SUPPORT = false; |
| 141 | static constexpr bool NEEDS_BIND_UNIFORM_INDEX = false; | 141 | static constexpr bool NEEDS_BIND_UNIFORM_INDEX = false; |
| 142 | static constexpr bool NEEDS_BIND_STORAGE_INDEX = false; | 142 | static constexpr bool NEEDS_BIND_STORAGE_INDEX = false; |
| 143 | static constexpr bool NEEDS_BIND_TEXTURE_BUFFER_INDEX = false; | ||
| 144 | static constexpr bool USE_MEMORY_MAPS = true; | 143 | static constexpr bool USE_MEMORY_MAPS = true; |
| 144 | static constexpr bool SEPARATE_IMAGE_BUFFER_BINDINGS = false; | ||
| 145 | }; | 145 | }; |
| 146 | 146 | ||
| 147 | using BufferCache = VideoCommon::BufferCache<BufferCacheParams>; | 147 | using BufferCache = VideoCommon::BufferCache<BufferCacheParams>; |
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp index feaace0c5..168ffa7e9 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp | |||
| @@ -18,6 +18,9 @@ | |||
| 18 | 18 | ||
| 19 | namespace Vulkan { | 19 | namespace Vulkan { |
| 20 | 20 | ||
| 21 | using Shader::ImageBufferDescriptor; | ||
| 22 | using Tegra::Texture::TexturePair; | ||
| 23 | |||
| 21 | ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descriptor_pool, | 24 | ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descriptor_pool, |
| 22 | VKUpdateDescriptorQueue& update_descriptor_queue_, | 25 | VKUpdateDescriptorQueue& update_descriptor_queue_, |
| 23 | Common::ThreadWorker* thread_worker, const Shader::Info& info_, | 26 | Common::ThreadWorker* thread_worker, const Shader::Info& info_, |
| @@ -106,25 +109,25 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute, | |||
| 106 | secondary_offset}; | 109 | secondary_offset}; |
| 107 | const u32 lhs_raw{gpu_memory.Read<u32>(addr)}; | 110 | const u32 lhs_raw{gpu_memory.Read<u32>(addr)}; |
| 108 | const u32 rhs_raw{gpu_memory.Read<u32>(separate_addr)}; | 111 | const u32 rhs_raw{gpu_memory.Read<u32>(separate_addr)}; |
| 109 | return TextureHandle{lhs_raw | rhs_raw, via_header_index}; | 112 | return TexturePair(lhs_raw | rhs_raw, via_header_index); |
| 110 | } | 113 | } |
| 111 | } | 114 | } |
| 112 | return TextureHandle{gpu_memory.Read<u32>(addr), via_header_index}; | 115 | return TexturePair(gpu_memory.Read<u32>(addr), via_header_index); |
| 113 | }}; | 116 | }}; |
| 114 | const auto add_image{[&](const auto& desc) { | 117 | const auto add_image{[&](const auto& desc) { |
| 115 | for (u32 index = 0; index < desc.count; ++index) { | 118 | for (u32 index = 0; index < desc.count; ++index) { |
| 116 | const TextureHandle handle{read_handle(desc, index)}; | 119 | const auto handle{read_handle(desc, index)}; |
| 117 | image_view_indices.push_back(handle.image); | 120 | image_view_indices.push_back(handle.first); |
| 118 | } | 121 | } |
| 119 | }}; | 122 | }}; |
| 120 | std::ranges::for_each(info.texture_buffer_descriptors, add_image); | 123 | std::ranges::for_each(info.texture_buffer_descriptors, add_image); |
| 121 | std::ranges::for_each(info.image_buffer_descriptors, add_image); | 124 | std::ranges::for_each(info.image_buffer_descriptors, add_image); |
| 122 | for (const auto& desc : info.texture_descriptors) { | 125 | for (const auto& desc : info.texture_descriptors) { |
| 123 | for (u32 index = 0; index < desc.count; ++index) { | 126 | for (u32 index = 0; index < desc.count; ++index) { |
| 124 | const TextureHandle handle{read_handle(desc, index)}; | 127 | const auto handle{read_handle(desc, index)}; |
| 125 | image_view_indices.push_back(handle.image); | 128 | image_view_indices.push_back(handle.first); |
| 126 | 129 | ||
| 127 | Sampler* const sampler = texture_cache.GetComputeSampler(handle.sampler); | 130 | Sampler* const sampler = texture_cache.GetComputeSampler(handle.second); |
| 128 | samplers.push_back(sampler->Handle()); | 131 | samplers.push_back(sampler->Handle()); |
| 129 | } | 132 | } |
| 130 | } | 133 | } |
| @@ -137,15 +140,16 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute, | |||
| 137 | ImageId* texture_buffer_ids{image_view_ids.data()}; | 140 | ImageId* texture_buffer_ids{image_view_ids.data()}; |
| 138 | size_t index{}; | 141 | size_t index{}; |
| 139 | const auto add_buffer{[&](const auto& desc) { | 142 | const auto add_buffer{[&](const auto& desc) { |
| 143 | constexpr bool is_image = std::is_same_v<decltype(desc), const ImageBufferDescriptor&>; | ||
| 140 | for (u32 i = 0; i < desc.count; ++i) { | 144 | for (u32 i = 0; i < desc.count; ++i) { |
| 141 | bool is_written{false}; | 145 | bool is_written{false}; |
| 142 | if constexpr (std::is_same_v<decltype(desc), const Shader::ImageBufferDescriptor&>) { | 146 | if constexpr (is_image) { |
| 143 | is_written = desc.is_written; | 147 | is_written = desc.is_written; |
| 144 | } | 148 | } |
| 145 | ImageView& image_view = texture_cache.GetImageView(*texture_buffer_ids); | 149 | ImageView& image_view = texture_cache.GetImageView(*texture_buffer_ids); |
| 146 | buffer_cache.BindComputeTextureBuffer(index, image_view.GpuAddr(), | 150 | buffer_cache.BindComputeTextureBuffer(index, image_view.GpuAddr(), |
| 147 | image_view.BufferSize(), image_view.format, | 151 | image_view.BufferSize(), image_view.format, |
| 148 | is_written); | 152 | is_written, is_image); |
| 149 | ++texture_buffer_ids; | 153 | ++texture_buffer_ids; |
| 150 | ++index; | 154 | ++index; |
| 151 | } | 155 | } |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index 9f5d30fe8..e5f54a84f 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include "video_core/renderer_vulkan/vk_update_descriptor.h" | 19 | #include "video_core/renderer_vulkan/vk_update_descriptor.h" |
| 20 | #include "video_core/vulkan_common/vulkan_device.h" | 20 | #include "video_core/vulkan_common/vulkan_device.h" |
| 21 | 21 | ||
| 22 | #ifdef _MSC_VER | 22 | #if defined(_MSC_VER) && defined(NDEBUG) |
| 23 | #define LAMBDA_FORCEINLINE [[msvc::forceinline]] | 23 | #define LAMBDA_FORCEINLINE [[msvc::forceinline]] |
| 24 | #else | 24 | #else |
| 25 | #define LAMBDA_FORCEINLINE | 25 | #define LAMBDA_FORCEINLINE |
| @@ -30,6 +30,7 @@ namespace { | |||
| 30 | using boost::container::small_vector; | 30 | using boost::container::small_vector; |
| 31 | using boost::container::static_vector; | 31 | using boost::container::static_vector; |
| 32 | using Shader::ImageBufferDescriptor; | 32 | using Shader::ImageBufferDescriptor; |
| 33 | using Tegra::Texture::TexturePair; | ||
| 33 | using VideoCore::Surface::PixelFormat; | 34 | using VideoCore::Surface::PixelFormat; |
| 34 | using VideoCore::Surface::PixelFormatFromDepthFormat; | 35 | using VideoCore::Surface::PixelFormatFromDepthFormat; |
| 35 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; | 36 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; |
| @@ -289,15 +290,15 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) { | |||
| 289 | const u32 lhs_raw{gpu_memory.Read<u32>(addr)}; | 290 | const u32 lhs_raw{gpu_memory.Read<u32>(addr)}; |
| 290 | const u32 rhs_raw{gpu_memory.Read<u32>(separate_addr)}; | 291 | const u32 rhs_raw{gpu_memory.Read<u32>(separate_addr)}; |
| 291 | const u32 raw{lhs_raw | rhs_raw}; | 292 | const u32 raw{lhs_raw | rhs_raw}; |
| 292 | return TextureHandle{raw, via_header_index}; | 293 | return TexturePair(raw, via_header_index); |
| 293 | } | 294 | } |
| 294 | } | 295 | } |
| 295 | return TextureHandle{gpu_memory.Read<u32>(addr), via_header_index}; | 296 | return TexturePair(gpu_memory.Read<u32>(addr), via_header_index); |
| 296 | }}; | 297 | }}; |
| 297 | const auto add_image{[&](const auto& desc) { | 298 | const auto add_image{[&](const auto& desc) { |
| 298 | for (u32 index = 0; index < desc.count; ++index) { | 299 | for (u32 index = 0; index < desc.count; ++index) { |
| 299 | const TextureHandle handle{read_handle(desc, index)}; | 300 | const auto handle{read_handle(desc, index)}; |
| 300 | image_view_indices[image_index++] = handle.image; | 301 | image_view_indices[image_index++] = handle.first; |
| 301 | } | 302 | } |
| 302 | }}; | 303 | }}; |
| 303 | if constexpr (Spec::has_texture_buffers) { | 304 | if constexpr (Spec::has_texture_buffers) { |
| @@ -312,10 +313,10 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) { | |||
| 312 | } | 313 | } |
| 313 | for (const auto& desc : info.texture_descriptors) { | 314 | for (const auto& desc : info.texture_descriptors) { |
| 314 | for (u32 index = 0; index < desc.count; ++index) { | 315 | for (u32 index = 0; index < desc.count; ++index) { |
| 315 | const TextureHandle handle{read_handle(desc, index)}; | 316 | const auto handle{read_handle(desc, index)}; |
| 316 | image_view_indices[image_index++] = handle.image; | 317 | image_view_indices[image_index++] = handle.first; |
| 317 | 318 | ||
| 318 | Sampler* const sampler{texture_cache.GetGraphicsSampler(handle.sampler)}; | 319 | Sampler* const sampler{texture_cache.GetGraphicsSampler(handle.second)}; |
| 319 | samplers[sampler_index++] = sampler->Handle(); | 320 | samplers[sampler_index++] = sampler->Handle(); |
| 320 | } | 321 | } |
| 321 | } | 322 | } |
| @@ -347,15 +348,16 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) { | |||
| 347 | const auto bind_stage_info{[&](size_t stage) LAMBDA_FORCEINLINE { | 348 | const auto bind_stage_info{[&](size_t stage) LAMBDA_FORCEINLINE { |
| 348 | size_t index{}; | 349 | size_t index{}; |
| 349 | const auto add_buffer{[&](const auto& desc) { | 350 | const auto add_buffer{[&](const auto& desc) { |
| 351 | constexpr bool is_image = std::is_same_v<decltype(desc), const ImageBufferDescriptor&>; | ||
| 350 | for (u32 i = 0; i < desc.count; ++i) { | 352 | for (u32 i = 0; i < desc.count; ++i) { |
| 351 | bool is_written{false}; | 353 | bool is_written{false}; |
| 352 | if constexpr (std::is_same_v<decltype(desc), const ImageBufferDescriptor&>) { | 354 | if constexpr (is_image) { |
| 353 | is_written = desc.is_written; | 355 | is_written = desc.is_written; |
| 354 | } | 356 | } |
| 355 | ImageView& image_view{texture_cache.GetImageView(*texture_buffer_index)}; | 357 | ImageView& image_view{texture_cache.GetImageView(*texture_buffer_index)}; |
| 356 | buffer_cache.BindGraphicsTextureBuffer(stage, index, image_view.GpuAddr(), | 358 | buffer_cache.BindGraphicsTextureBuffer(stage, index, image_view.GpuAddr(), |
| 357 | image_view.BufferSize(), image_view.format, | 359 | image_view.BufferSize(), image_view.format, |
| 358 | is_written); | 360 | is_written, is_image); |
| 359 | ++index; | 361 | ++index; |
| 360 | ++texture_buffer_index; | 362 | ++texture_buffer_index; |
| 361 | } | 363 | } |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 1334882b5..30b71bdbc 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -342,28 +342,15 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline( | |||
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline() { | 344 | std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline() { |
| 345 | main_pools.ReleaseContents(); | 345 | GraphicsEnvironments environments; |
| 346 | 346 | GetGraphicsEnvironments(environments, graphics_key.unique_hashes); | |
| 347 | std::array<GraphicsEnvironment, Maxwell::MaxShaderProgram> graphics_envs; | ||
| 348 | boost::container::static_vector<Shader::Environment*, Maxwell::MaxShaderProgram> envs; | ||
| 349 | 347 | ||
| 350 | const GPUVAddr base_addr{maxwell3d.regs.code_address.CodeAddress()}; | 348 | main_pools.ReleaseContents(); |
| 351 | for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) { | 349 | auto pipeline{CreateGraphicsPipeline(main_pools, graphics_key, environments.Span(), true)}; |
| 352 | if (graphics_key.unique_hashes[index] == 0) { | ||
| 353 | continue; | ||
| 354 | } | ||
| 355 | const auto program{static_cast<Maxwell::ShaderProgram>(index)}; | ||
| 356 | auto& env{graphics_envs[index]}; | ||
| 357 | const u32 start_address{maxwell3d.regs.shader_config[index].offset}; | ||
| 358 | env = GraphicsEnvironment{maxwell3d, gpu_memory, program, base_addr, start_address}; | ||
| 359 | env.SetCachedSize(shader_infos[index]->size_bytes); | ||
| 360 | envs.push_back(&env); | ||
| 361 | } | ||
| 362 | auto pipeline{CreateGraphicsPipeline(main_pools, graphics_key, MakeSpan(envs), true)}; | ||
| 363 | if (pipeline_cache_filename.empty()) { | 350 | if (pipeline_cache_filename.empty()) { |
| 364 | return pipeline; | 351 | return pipeline; |
| 365 | } | 352 | } |
| 366 | serialization_thread.QueueWork([this, key = graphics_key, envs = std::move(graphics_envs)] { | 353 | serialization_thread.QueueWork([this, key = graphics_key, envs = std::move(environments.envs)] { |
| 367 | boost::container::static_vector<const GenericEnvironment*, Maxwell::MaxShaderProgram> | 354 | boost::container::static_vector<const GenericEnvironment*, Maxwell::MaxShaderProgram> |
| 368 | env_ptrs; | 355 | env_ptrs; |
| 369 | for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) { | 356 | for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) { |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 0f15ad2f7..ef14e91e7 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -96,17 +96,6 @@ VkRect2D GetScissorState(const Maxwell& regs, size_t index) { | |||
| 96 | return scissor; | 96 | return scissor; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | struct TextureHandle { | ||
| 100 | constexpr TextureHandle(u32 data, bool via_header_index) { | ||
| 101 | const Tegra::Texture::TextureHandle handle{data}; | ||
| 102 | image = handle.tic_id; | ||
| 103 | sampler = via_header_index ? image : handle.tsc_id.Value(); | ||
| 104 | } | ||
| 105 | |||
| 106 | u32 image; | ||
| 107 | u32 sampler; | ||
| 108 | }; | ||
| 109 | |||
| 110 | DrawParams MakeDrawParams(const Maxwell& regs, u32 num_instances, bool is_instanced, | 99 | DrawParams MakeDrawParams(const Maxwell& regs, u32 num_instances, bool is_instanced, |
| 111 | bool is_indexed) { | 100 | bool is_indexed) { |
| 112 | DrawParams params{ | 101 | DrawParams params{ |