diff options
| author | 2019-03-14 02:19:02 -0300 | |
|---|---|---|
| committer | 2019-04-10 14:20:25 -0300 | |
| commit | ad53b233c58fdf90da0e05283eb8146acb50fad3 (patch) | |
| tree | d717684c4a3b324142e1532c30e7d1b9fbddd23b /src | |
| parent | video_core: Add sirit as optional dependency with Vulkan (diff) | |
| download | yuzu-ad53b233c58fdf90da0e05283eb8146acb50fad3.tar.gz yuzu-ad53b233c58fdf90da0e05283eb8146acb50fad3.tar.xz yuzu-ad53b233c58fdf90da0e05283eb8146acb50fad3.zip | |
vk_shader_decompiler: Declare and stub interface for a SPIR-V decompiler
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | 45 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_decompiler.h | 80 |
3 files changed, 127 insertions, 0 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index fe6b6ef7d..21e52db61 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -127,6 +127,8 @@ if (ENABLE_VULKAN) | |||
| 127 | renderer_vulkan/vk_sampler_cache.h | 127 | renderer_vulkan/vk_sampler_cache.h |
| 128 | renderer_vulkan/vk_scheduler.cpp | 128 | renderer_vulkan/vk_scheduler.cpp |
| 129 | renderer_vulkan/vk_scheduler.h | 129 | renderer_vulkan/vk_scheduler.h |
| 130 | renderer_vulkan/vk_shader_decompiler.cpp | ||
| 131 | renderer_vulkan/vk_shader_decompiler.h | ||
| 130 | renderer_vulkan/vk_stream_buffer.cpp | 132 | renderer_vulkan/vk_stream_buffer.cpp |
| 131 | renderer_vulkan/vk_stream_buffer.h | 133 | renderer_vulkan/vk_stream_buffer.h |
| 132 | renderer_vulkan/vk_swapchain.cpp | 134 | renderer_vulkan/vk_swapchain.cpp |
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp new file mode 100644 index 000000000..3b8793840 --- /dev/null +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <sirit/sirit.h> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "video_core/engines/maxwell_3d.h" | ||
| 9 | #include "video_core/engines/shader_header.h" | ||
| 10 | #include "video_core/renderer_vulkan/vk_shader_decompiler.h" | ||
| 11 | #include "video_core/shader/shader_ir.h" | ||
| 12 | |||
| 13 | namespace Vulkan::VKShader { | ||
| 14 | |||
| 15 | using namespace VideoCommon::Shader; | ||
| 16 | |||
| 17 | using ShaderStage = Tegra::Engines::Maxwell3D::Regs::ShaderStage; | ||
| 18 | |||
| 19 | class SPIRVDecompiler : public Sirit::Module { | ||
| 20 | public: | ||
| 21 | explicit SPIRVDecompiler(const ShaderIR& ir, ShaderStage stage) | ||
| 22 | : Module(0x00010300), ir{ir}, stage{stage}, header{ir.GetHeader()} {} | ||
| 23 | |||
| 24 | void Decompile() { | ||
| 25 | UNIMPLEMENTED(); | ||
| 26 | } | ||
| 27 | |||
| 28 | ShaderEntries GetShaderEntries() const { | ||
| 29 | UNIMPLEMENTED(); | ||
| 30 | return {}; | ||
| 31 | } | ||
| 32 | |||
| 33 | private: | ||
| 34 | const ShaderIR& ir; | ||
| 35 | const ShaderStage stage; | ||
| 36 | const Tegra::Shader::Header header; | ||
| 37 | }; | ||
| 38 | |||
| 39 | DecompilerResult Decompile(const VideoCommon::Shader::ShaderIR& ir, Maxwell::ShaderStage stage) { | ||
| 40 | auto decompiler = std::make_unique<SPIRVDecompiler>(ir, stage); | ||
| 41 | decompiler->Decompile(); | ||
| 42 | return {std::move(decompiler), decompiler->GetShaderEntries()}; | ||
| 43 | } | ||
| 44 | |||
| 45 | } // namespace Vulkan::VKShader | ||
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.h b/src/video_core/renderer_vulkan/vk_shader_decompiler.h new file mode 100644 index 000000000..329d8fa38 --- /dev/null +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.h | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <memory> | ||
| 9 | #include <set> | ||
| 10 | #include <utility> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | #include <sirit/sirit.h> | ||
| 14 | |||
| 15 | #include "common/common_types.h" | ||
| 16 | #include "video_core/engines/maxwell_3d.h" | ||
| 17 | #include "video_core/shader/shader_ir.h" | ||
| 18 | |||
| 19 | namespace VideoCommon::Shader { | ||
| 20 | class ShaderIR; | ||
| 21 | } | ||
| 22 | |||
| 23 | namespace Vulkan::VKShader { | ||
| 24 | |||
| 25 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; | ||
| 26 | |||
| 27 | using SamplerEntry = VideoCommon::Shader::Sampler; | ||
| 28 | |||
| 29 | constexpr u32 DESCRIPTOR_SET = 0; | ||
| 30 | |||
| 31 | class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer { | ||
| 32 | public: | ||
| 33 | explicit constexpr ConstBufferEntry(const VideoCommon::Shader::ConstBuffer& entry, u32 index) | ||
| 34 | : VideoCommon::Shader::ConstBuffer{entry}, index{index} {} | ||
| 35 | |||
| 36 | constexpr u32 GetIndex() const { | ||
| 37 | return index; | ||
| 38 | } | ||
| 39 | |||
| 40 | private: | ||
| 41 | u32 index{}; | ||
| 42 | }; | ||
| 43 | |||
| 44 | class GlobalBufferEntry { | ||
| 45 | public: | ||
| 46 | explicit GlobalBufferEntry(u32 cbuf_index, u32 cbuf_offset) | ||
| 47 | : cbuf_index{cbuf_index}, cbuf_offset{cbuf_offset} {} | ||
| 48 | |||
| 49 | u32 GetCbufIndex() const { | ||
| 50 | return cbuf_index; | ||
| 51 | } | ||
| 52 | |||
| 53 | u32 GetCbufOffset() const { | ||
| 54 | return cbuf_offset; | ||
| 55 | } | ||
| 56 | |||
| 57 | private: | ||
| 58 | u32 cbuf_index{}; | ||
| 59 | u32 cbuf_offset{}; | ||
| 60 | }; | ||
| 61 | |||
| 62 | struct ShaderEntries { | ||
| 63 | u32 const_buffers_base_binding{}; | ||
| 64 | u32 global_buffers_base_binding{}; | ||
| 65 | u32 samplers_base_binding{}; | ||
| 66 | std::vector<ConstBufferEntry> const_buffers; | ||
| 67 | std::vector<GlobalBufferEntry> global_buffers; | ||
| 68 | std::vector<SamplerEntry> samplers; | ||
| 69 | std::set<u32> attributes; | ||
| 70 | std::array<bool, Maxwell::NumClipDistances> clip_distances{}; | ||
| 71 | std::size_t shader_length{}; | ||
| 72 | Sirit::Id entry_function{}; | ||
| 73 | std::vector<Sirit::Id> interfaces; | ||
| 74 | }; | ||
| 75 | |||
| 76 | using DecompilerResult = std::pair<std::unique_ptr<Sirit::Module>, ShaderEntries>; | ||
| 77 | |||
| 78 | DecompilerResult Decompile(const VideoCommon::Shader::ShaderIR& ir, Maxwell::ShaderStage stage); | ||
| 79 | |||
| 80 | } // namespace Vulkan::VKShader | ||