From f4768cd26c4fb41663f914f23220d933df35212f Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Mon, 26 Feb 2024 10:26:44 -0800 Subject: [PATCH] video_core: Remove pre-compilation of Vulkan host-shaders. (#7461) --- .github/workflows/build.yml | 17 ++--- src/video_core/host_shaders/CMakeLists.txt | 72 ++++--------------- .../format_reinterpreter/fullscreen_quad.vert | 4 ++ .../host_shaders/full_screen_triangle.vert | 1 + .../texture_filtering/tex_coord.vert | 4 ++ .../renderer_vulkan/renderer_vulkan.cpp | 20 +++--- .../renderer_vulkan/vk_blit_helper.cpp | 20 +++--- 7 files changed, 50 insertions(+), 88 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b848e93d5b..e828152504 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,7 +81,7 @@ jobs: restore-keys: | ${{ runner.os }}-${{ matrix.target }}- - name: Install tools - run: brew install ccache glslang ninja + run: brew install ccache ninja - name: Build run: ./.ci/macos.sh - name: Prepare outputs for caching @@ -153,13 +153,6 @@ jobs: - name: Install extra tools (MSVC) run: choco install ccache ninja wget if: ${{ matrix.target == 'msvc' }} - - name: Set up Vulkan SDK (MSVC) - uses: humbletim/setup-vulkan-sdk@v1.2.0 - if: ${{ matrix.target == 'msvc' }} - with: - vulkan-query-version: latest - vulkan-components: SPIRV-Tools, Glslang - vulkan-use-cache: true - name: Set up MSYS2 uses: msys2/setup-msys2@v2 if: ${{ matrix.target == 'msys2' }} @@ -168,10 +161,8 @@ jobs: update: true install: git make p7zip pacboy: >- - toolchain:p ccache:p cmake:p ninja:p glslang:p + toolchain:p ccache:p cmake:p ninja:p qt6-base:p qt6-multimedia:p qt6-multimedia-wmf:p qt6-tools:p qt6-translations:p - - name: Test glslang - run: glslang --version || glslangValidator --version - name: Disable line ending translation run: git config --global core.autocrlf input - name: Build @@ -215,7 +206,7 @@ jobs: run: | sudo add-apt-repository -y ppa:theofficialgman/gpu-tools sudo apt-get update -y - sudo apt-get install ccache glslang-dev glslang-tools apksigner -y + sudo apt-get install ccache apksigner -y - name: Build run: JAVA_HOME=$JAVA_HOME_17_X64 ./.ci/android.sh env: @@ -253,7 +244,7 @@ jobs: restore-keys: | ${{ runner.os }}-ios- - name: Install tools - run: brew install ccache glslang ninja + run: brew install ccache ninja - name: Build run: ./.ci/ios.sh release: diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index 27b4668765..9a514fecf2 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt @@ -26,17 +26,6 @@ set(SHADER_FILES vulkan_blit_depth_stencil.frag ) -find_program(GLSLANG "glslang") -if ("${GLSLANG}" STREQUAL "GLSLANG-NOTFOUND") - find_program(GLSLANG "glslangValidator") - if ("${GLSLANG}" STREQUAL "GLSLANG-NOTFOUND") - message(FATAL_ERROR "Required program `glslang` (or `glslangValidator`) not found.") - endif() -endif() - -set(MACROS "-Dgl_VertexID=gl_VertexIndex") -set(QUIET_FLAG "--quiet") - set(SHADER_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include) set(SHADER_DIR ${SHADER_INCLUDE}/video_core/host_shaders) set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE) @@ -44,57 +33,22 @@ set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE) set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/source_shader.h.in) set(HEADER_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/StringShaderHeader.cmake) -# Check if `--quiet` is available on host's glslang version -# glslang prints to STDERR iff an unrecognized flag is passed to it -execute_process( - COMMAND - ${GLSLANG} ${QUIET_FLAG} - ERROR_VARIABLE - GLSLANG_ERROR - # STDOUT variable defined to silence unnecessary output during CMake configuration - OUTPUT_VARIABLE - GLSLANG_OUTPUT -) - -if (NOT GLSLANG_ERROR STREQUAL "") - message(WARNING "Refusing to use unavailable flag `${QUIET_FLAG}` on `${GLSLANG}`") - set(QUIET_FLAG "") -endif() - foreach(FILENAME IN ITEMS ${SHADER_FILES}) string(REPLACE "." "_" SHADER_NAME ${FILENAME}) set(SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}) - # Skip generating source headers on Vulkan exclusive files - if (NOT ${FILENAME} MATCHES "vulkan.*") - set(SOURCE_HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h) - add_custom_command( - OUTPUT - ${SOURCE_HEADER_FILE} - COMMAND - ${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${SOURCE_HEADER_FILE} ${INPUT_FILE} - MAIN_DEPENDENCY - ${SOURCE_FILE} - DEPENDS - ${INPUT_FILE} - # HEADER_GENERATOR should be included here but msbuild seems to assume it's always modified - ) - set(SHADER_HEADERS ${SHADER_HEADERS} ${SOURCE_HEADER_FILE}) - endif() - # Skip compiling to SPIR-V OpenGL exclusive files - if (NOT ${FILENAME} MATCHES "opengl.*") - get_filename_component(FILE_NAME ${SHADER_NAME} NAME) - string(TOUPPER ${FILE_NAME}_SPV SPIRV_VARIABLE_NAME) - set(SPIRV_HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}_spv.h) - add_custom_command( - OUTPUT - ${SPIRV_HEADER_FILE} - COMMAND - ${GLSLANG} --target-env vulkan1.1 --glsl-version 450 ${QUIET_FLAG} ${MACROS} --variable-name ${SPIRV_VARIABLE_NAME} -o ${SPIRV_HEADER_FILE} ${SOURCE_FILE} - MAIN_DEPENDENCY - ${SOURCE_FILE} - ) - set(SHADER_HEADERS ${SHADER_HEADERS} ${SPIRV_HEADER_FILE}) - endif() + set(SOURCE_HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h) + add_custom_command( + OUTPUT + ${SOURCE_HEADER_FILE} + COMMAND + ${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${SOURCE_HEADER_FILE} ${INPUT_FILE} + MAIN_DEPENDENCY + ${SOURCE_FILE} + DEPENDS + ${INPUT_FILE} + # HEADER_GENERATOR should be included here but msbuild seems to assume it's always modified + ) + set(SHADER_HEADERS ${SHADER_HEADERS} ${SOURCE_HEADER_FILE}) endforeach() set(SHADER_SOURCES ${SHADER_FILES}) diff --git a/src/video_core/host_shaders/format_reinterpreter/fullscreen_quad.vert b/src/video_core/host_shaders/format_reinterpreter/fullscreen_quad.vert index 3c5e771bc1..fcd42d4003 100644 --- a/src/video_core/host_shaders/format_reinterpreter/fullscreen_quad.vert +++ b/src/video_core/host_shaders/format_reinterpreter/fullscreen_quad.vert @@ -8,6 +8,10 @@ layout(location = 0) out vec2 dst_coord; layout(location = 0) uniform mediump ivec2 dst_size; +#ifdef VULKAN +#define gl_VertexID gl_VertexIndex +#endif + const vec2 vertices[4] = vec2[4](vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0), vec2(1.0, 1.0)); diff --git a/src/video_core/host_shaders/full_screen_triangle.vert b/src/video_core/host_shaders/full_screen_triangle.vert index 7f3459f462..5abc2b0d7a 100644 --- a/src/video_core/host_shaders/full_screen_triangle.vert +++ b/src/video_core/host_shaders/full_screen_triangle.vert @@ -10,6 +10,7 @@ out gl_PerVertex { layout(location = 0) out vec2 texcoord; #ifdef VULKAN +#define gl_VertexID gl_VertexIndex #define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants { #define END_PUSH_CONSTANTS }; #define UNIFORM(n) diff --git a/src/video_core/host_shaders/texture_filtering/tex_coord.vert b/src/video_core/host_shaders/texture_filtering/tex_coord.vert index b711e69061..9525fabb63 100644 --- a/src/video_core/host_shaders/texture_filtering/tex_coord.vert +++ b/src/video_core/host_shaders/texture_filtering/tex_coord.vert @@ -5,6 +5,10 @@ //? #version 430 core layout(location = 0) out vec2 tex_coord; +#ifdef VULKAN +#define gl_VertexID gl_VertexIndex +#endif + const vec2 vertices[4] = vec2[4](vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0), vec2(1.0, 1.0)); diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 74a231bff7..5a18b305d1 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -15,10 +15,10 @@ #include "video_core/renderer_vulkan/vk_memory_util.h" #include "video_core/renderer_vulkan/vk_shader_util.h" -#include "video_core/host_shaders/vulkan_present_anaglyph_frag_spv.h" -#include "video_core/host_shaders/vulkan_present_frag_spv.h" -#include "video_core/host_shaders/vulkan_present_interlaced_frag_spv.h" -#include "video_core/host_shaders/vulkan_present_vert_spv.h" +#include "video_core/host_shaders/vulkan_present_anaglyph_frag.h" +#include "video_core/host_shaders/vulkan_present_frag.h" +#include "video_core/host_shaders/vulkan_present_interlaced_frag.h" +#include "video_core/host_shaders/vulkan_present_vert.h" #include @@ -225,10 +225,14 @@ void RendererVulkan::LoadFBToScreenInfo(const Pica::FramebufferConfig& framebuff void RendererVulkan::CompileShaders() { vk::Device device = instance.GetDevice(); - present_vertex_shader = CompileSPV(VULKAN_PRESENT_VERT_SPV, device); - present_shaders[0] = CompileSPV(VULKAN_PRESENT_FRAG_SPV, device); - present_shaders[1] = CompileSPV(VULKAN_PRESENT_ANAGLYPH_FRAG_SPV, device); - present_shaders[2] = CompileSPV(VULKAN_PRESENT_INTERLACED_FRAG_SPV, device); + present_vertex_shader = + Compile(HostShaders::VULKAN_PRESENT_VERT, vk::ShaderStageFlagBits::eVertex, device); + present_shaders[0] = + Compile(HostShaders::VULKAN_PRESENT_FRAG, vk::ShaderStageFlagBits::eFragment, device); + present_shaders[1] = Compile(HostShaders::VULKAN_PRESENT_ANAGLYPH_FRAG, + vk::ShaderStageFlagBits::eFragment, device); + present_shaders[2] = Compile(HostShaders::VULKAN_PRESENT_INTERLACED_FRAG, + vk::ShaderStageFlagBits::eFragment, device); auto properties = instance.GetPhysicalDevice().getProperties(); for (std::size_t i = 0; i < present_samplers.size(); i++) { diff --git a/src/video_core/renderer_vulkan/vk_blit_helper.cpp b/src/video_core/renderer_vulkan/vk_blit_helper.cpp index 4af2f0accd..3f50cb044e 100644 --- a/src/video_core/renderer_vulkan/vk_blit_helper.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_helper.cpp @@ -10,10 +10,10 @@ #include "video_core/renderer_vulkan/vk_shader_util.h" #include "video_core/renderer_vulkan/vk_texture_runtime.h" -#include "video_core/host_shaders/format_reinterpreter/vulkan_d24s8_to_rgba8_comp_spv.h" -#include "video_core/host_shaders/full_screen_triangle_vert_spv.h" -#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h" -#include "video_core/host_shaders/vulkan_depth_to_buffer_comp_spv.h" +#include "video_core/host_shaders/format_reinterpreter/vulkan_d24s8_to_rgba8_comp.h" +#include "video_core/host_shaders/full_screen_triangle_vert.h" +#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag.h" +#include "video_core/host_shaders/vulkan_depth_to_buffer_comp.h" namespace Vulkan { @@ -189,10 +189,14 @@ BlitHelper::BlitHelper(const Instance& instance_, Scheduler& scheduler_, Descrip PipelineLayoutCreateInfo(&compute_buffer_provider.Layout(), true))}, two_textures_pipeline_layout{ device.createPipelineLayout(PipelineLayoutCreateInfo(&two_textures_provider.Layout()))}, - full_screen_vert{CompileSPV(FULL_SCREEN_TRIANGLE_VERT_SPV, device)}, - d24s8_to_rgba8_comp{CompileSPV(VULKAN_D24S8_TO_RGBA8_COMP_SPV, device)}, - depth_to_buffer_comp{CompileSPV(VULKAN_DEPTH_TO_BUFFER_COMP_SPV, device)}, - blit_depth_stencil_frag{CompileSPV(VULKAN_BLIT_DEPTH_STENCIL_FRAG_SPV, device)}, + full_screen_vert{Compile(HostShaders::FULL_SCREEN_TRIANGLE_VERT, + vk::ShaderStageFlagBits::eVertex, device)}, + d24s8_to_rgba8_comp{Compile(HostShaders::VULKAN_D24S8_TO_RGBA8_COMP, + vk::ShaderStageFlagBits::eCompute, device)}, + depth_to_buffer_comp{Compile(HostShaders::VULKAN_DEPTH_TO_BUFFER_COMP, + vk::ShaderStageFlagBits::eCompute, device)}, + blit_depth_stencil_frag{Compile(HostShaders::VULKAN_BLIT_DEPTH_STENCIL_FRAG, + vk::ShaderStageFlagBits::eFragment, device)}, d24s8_to_rgba8_pipeline{MakeComputePipeline(d24s8_to_rgba8_comp, compute_pipeline_layout)}, depth_to_buffer_pipeline{ MakeComputePipeline(depth_to_buffer_comp, compute_buffer_pipeline_layout)},