Merge pull request #2235 from ReinUsesLisp/spirv-decompiler
vk_shader_decompiler: Implement a SPIR-V decompiler
This commit is contained in:
		
						commit
						ea80e2bc57
					
				
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							@ -43,3 +43,6 @@
 | 
				
			|||||||
[submodule "externals/zstd"]
 | 
					[submodule "externals/zstd"]
 | 
				
			||||||
    path = externals/zstd
 | 
					    path = externals/zstd
 | 
				
			||||||
    url = https://github.com/facebook/zstd
 | 
					    url = https://github.com/facebook/zstd
 | 
				
			||||||
 | 
					[submodule "sirit"]
 | 
				
			||||||
 | 
					    path = externals/sirit
 | 
				
			||||||
 | 
					    url = https://github.com/ReinUsesLisp/sirit
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								externals/CMakeLists.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								externals/CMakeLists.txt
									
									
									
									
										vendored
									
									
								
							@ -72,6 +72,11 @@ if (USE_DISCORD_PRESENCE)
 | 
				
			|||||||
    target_include_directories(discord-rpc INTERFACE ./discord-rpc/include)
 | 
					    target_include_directories(discord-rpc INTERFACE ./discord-rpc/include)
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Sirit
 | 
				
			||||||
 | 
					if (ENABLE_VULKAN)
 | 
				
			||||||
 | 
					    add_subdirectory(sirit)
 | 
				
			||||||
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (ENABLE_WEB_SERVICE)
 | 
					if (ENABLE_WEB_SERVICE)
 | 
				
			||||||
    # LibreSSL
 | 
					    # LibreSSL
 | 
				
			||||||
    set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "")
 | 
					    set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "")
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								externals/sirit
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										1
									
								
								externals/sirit
									
									
									
									
										vendored
									
									
										Submodule
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					Subproject commit f7c4b07a7e14edb1dcd93bc9879c823423705c2e
 | 
				
			||||||
@ -129,12 +129,14 @@ if (ENABLE_VULKAN)
 | 
				
			|||||||
        renderer_vulkan/vk_sampler_cache.h
 | 
					        renderer_vulkan/vk_sampler_cache.h
 | 
				
			||||||
        renderer_vulkan/vk_scheduler.cpp
 | 
					        renderer_vulkan/vk_scheduler.cpp
 | 
				
			||||||
        renderer_vulkan/vk_scheduler.h
 | 
					        renderer_vulkan/vk_scheduler.h
 | 
				
			||||||
 | 
					        renderer_vulkan/vk_shader_decompiler.cpp
 | 
				
			||||||
 | 
					        renderer_vulkan/vk_shader_decompiler.h
 | 
				
			||||||
        renderer_vulkan/vk_stream_buffer.cpp
 | 
					        renderer_vulkan/vk_stream_buffer.cpp
 | 
				
			||||||
        renderer_vulkan/vk_stream_buffer.h
 | 
					        renderer_vulkan/vk_stream_buffer.h
 | 
				
			||||||
        renderer_vulkan/vk_swapchain.cpp
 | 
					        renderer_vulkan/vk_swapchain.cpp
 | 
				
			||||||
        renderer_vulkan/vk_swapchain.h)
 | 
					        renderer_vulkan/vk_swapchain.h)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    target_include_directories(video_core PRIVATE ../../externals/Vulkan-Headers/include)
 | 
					    target_include_directories(video_core PRIVATE sirit ../../externals/Vulkan-Headers/include)
 | 
				
			||||||
    target_compile_definitions(video_core PRIVATE HAS_VULKAN)
 | 
					    target_compile_definitions(video_core PRIVATE HAS_VULKAN)
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -142,3 +144,6 @@ create_target_directory_groups(video_core)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
target_link_libraries(video_core PUBLIC common core)
 | 
					target_link_libraries(video_core PUBLIC common core)
 | 
				
			||||||
target_link_libraries(video_core PRIVATE glad)
 | 
					target_link_libraries(video_core PRIVATE glad)
 | 
				
			||||||
 | 
					if (ENABLE_VULKAN)
 | 
				
			||||||
 | 
					    target_link_libraries(video_core PRIVATE sirit)
 | 
				
			||||||
 | 
					endif()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1379
									
								
								src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1379
									
								
								src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										80
									
								
								src/video_core/renderer_vulkan/vk_shader_decompiler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								src/video_core/renderer_vulkan/vk_shader_decompiler.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,80 @@
 | 
				
			|||||||
 | 
					// Copyright 2019 yuzu Emulator Project
 | 
				
			||||||
 | 
					// Licensed under GPLv2 or any later version
 | 
				
			||||||
 | 
					// Refer to the license.txt file included.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <array>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <set>
 | 
				
			||||||
 | 
					#include <utility>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sirit/sirit.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "common/common_types.h"
 | 
				
			||||||
 | 
					#include "video_core/engines/maxwell_3d.h"
 | 
				
			||||||
 | 
					#include "video_core/shader/shader_ir.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace VideoCommon::Shader {
 | 
				
			||||||
 | 
					class ShaderIR;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Vulkan::VKShader {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using Maxwell = Tegra::Engines::Maxwell3D::Regs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using SamplerEntry = VideoCommon::Shader::Sampler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					constexpr u32 DESCRIPTOR_SET = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer {
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    explicit constexpr ConstBufferEntry(const VideoCommon::Shader::ConstBuffer& entry, u32 index)
 | 
				
			||||||
 | 
					        : VideoCommon::Shader::ConstBuffer{entry}, index{index} {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    constexpr u32 GetIndex() const {
 | 
				
			||||||
 | 
					        return index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    u32 index{};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class GlobalBufferEntry {
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    explicit GlobalBufferEntry(u32 cbuf_index, u32 cbuf_offset)
 | 
				
			||||||
 | 
					        : cbuf_index{cbuf_index}, cbuf_offset{cbuf_offset} {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    u32 GetCbufIndex() const {
 | 
				
			||||||
 | 
					        return cbuf_index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    u32 GetCbufOffset() const {
 | 
				
			||||||
 | 
					        return cbuf_offset;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    u32 cbuf_index{};
 | 
				
			||||||
 | 
					    u32 cbuf_offset{};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ShaderEntries {
 | 
				
			||||||
 | 
					    u32 const_buffers_base_binding{};
 | 
				
			||||||
 | 
					    u32 global_buffers_base_binding{};
 | 
				
			||||||
 | 
					    u32 samplers_base_binding{};
 | 
				
			||||||
 | 
					    std::vector<ConstBufferEntry> const_buffers;
 | 
				
			||||||
 | 
					    std::vector<GlobalBufferEntry> global_buffers;
 | 
				
			||||||
 | 
					    std::vector<SamplerEntry> samplers;
 | 
				
			||||||
 | 
					    std::set<u32> attributes;
 | 
				
			||||||
 | 
					    std::array<bool, Maxwell::NumClipDistances> clip_distances{};
 | 
				
			||||||
 | 
					    std::size_t shader_length{};
 | 
				
			||||||
 | 
					    Sirit::Id entry_function{};
 | 
				
			||||||
 | 
					    std::vector<Sirit::Id> interfaces;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using DecompilerResult = std::pair<std::unique_ptr<Sirit::Module>, ShaderEntries>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DecompilerResult Decompile(const VideoCommon::Shader::ShaderIR& ir, Maxwell::ShaderStage stage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Vulkan::VKShader
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user