TsundereStation/data/shaders/vulkan/screen_quad.vert.glsl

24 lines
981 B
Text
Raw Normal View History

common/vulkan, core: pre-bake screen-quad VS, no glslang at runtime This is the probe patch in a series that eliminates dep/glslang from the libretro core build. It establishes the infrastructure - the GLSL source tree, the embedded-SPIR-V loader, the regeneration tool, and the build wiring - by converting exactly one call site so the pattern can be smoke-tested in isolation before the rest of Bucket A and then Bucket B follow in subsequent patches. glslang stays in the tree until the final patch in the series, which removes dep/glslang and the surrounding shader_compiler.cpp. What this patch does: - Adds data/shaders/vulkan/screen_quad.vert.glsl - the GLSL source for the screen-quad VS, kept in the tree for human readability. The build does NOT see this file; it is consumed only by the offline regen tool. - Adds src/common/vulkan/embedded_spirv/screen_quad_vs.inc - the pre-compiled SPIR-V blob as a 'const uint32_t[]' (367 words, 1.4 KiB), generated offline from the .glsl by glslangValidator targeting vulkan1.0. The .inc is checked in and #include'd by embedded_shaders.cpp inside namespace Vulkan::EmbeddedShaders. spirv-val confirms the blob is valid Vulkan 1.0 SPIR-V (magic 0x07230203, version 1.0). - Adds src/common/vulkan/embedded_shaders.{h,cpp}. The header exposes a pair of extern declarations per blob and a single CreateShaderModule(const uint32_t*, size_t) loader. The loader intentionally bypasses Vulkan::ShaderCache - pre-baked SPIR-V is already final, so there is nothing to compile and nothing worth caching on disk. Just a sized-and-checked vkCreateShaderModule call. - Adds tools/regen_vulkan_spirv.py - the offline workflow for contributors who edit shader .glsl sources. It invokes glslangValidator on each .glsl under data/shaders/vulkan/ and rewrites the matching .inc. CRITICAL: this tool is NEVER invoked by Make or CMake. The build sees only .h/.cpp/.inc files and has no shader- compiler dependency. Contributors run the script manually after editing .glsl, commit both files together. - Adds data/shaders/vulkan/README.md documenting the workflow and the invariant that the build must never invoke an external shader compiler. - Switches GPU_HW_Vulkan::GetFullscreenQuadVertexShader() (in src/core/gpu_hw_vulkan.cpp) from g_vulkan_shader_cache->GetVertexShader(m_shadergen->Generate...) to Vulkan::EmbeddedShaders::CreateShaderModule(k_screen_quad_vs, ...). The m_shadergen null-check is removed since the embedded path has no such ordering dependency. The function's contract (lazy creation, stored in m_fullscreen_quad_vertex_shader, returned to multiple pipeline builders) is unchanged. - Registers src/common/vulkan/embedded_shaders.cpp in both Makefile.libretro (alphabetical order in the vulkan/ SOURCES_CXX block) and src/common/CMakeLists.txt (alphabetical order in the common target's source list). Neither change adds any build-tool dependency; the new .cpp compiles like any other. What this patch does NOT do: - It does not remove dep/glslang or the SOURCES_CXX entries that pull in its 99 translation units. glslang is still needed for every shader generator that has not yet been converted - in particular all of GPU_HW_ShaderGen, plus the remaining utility shaders (UV quad VS, VRAM read/copy/write/fill/update-depth FS, display FS, adaptive downsample mip/blur/composite FS, box-sample downsample FS). Subsequent patches in this series convert those one bucket at a time. The final patch removes dep/glslang, src/common/vulkan/shader_compiler.{h,cpp}, the glslang link line in CMake, and the Makefile entries. - It does not touch the disk-backed Vulkan::ShaderCache. That cache still serves the runtime-glslang path for remaining shaders. Smoke tests performed in isolation: - glslangValidator --target-env vulkan1.0 succeeds on the .glsl source, producing 367 32-bit words of SPIR-V. - spirv-val --target-env vulkan1.0 reports VALID on the blob. - spirv-dis confirms the entry point, VertexData block, and Position/ VertexIndex built-ins are correctly emitted. - A standalone harness including the .inc inside the Vulkan::EmbeddedShaders namespace and calling CreateShaderModule through a stubbed vkCreateShaderModule reads back the correct magic word and size. - g++ -fsyntax-only on embedded_shaders.cpp against the real headers in the tree (excluding only the platform-specific X11 surface define not used by this TU) is clean. Smoke tests that require the user's setup: - Real build on Windows (RTX 5090) and macOS. - Vulkan core boots, RetroArch's pipeline cache populates, and at least one game renders past the first frame using the screen-quad pipeline (VRAM ops, display, downsample - all of which call GetFullscreenQuadVertexShader internally).
2026-05-17 17:49:19 +00:00
// Pre-baked Vulkan source for ShaderGen::GenerateScreenQuadVertexShader().
//
// This file is the source of truth for the screen quad vertex shader used by
// the Vulkan backend. The runtime equivalent of this shader is generated by
// ShaderGen::GenerateScreenQuadVertexShader() in src/core/shadergen.cpp; that
// function is still used by the OpenGL, OpenGL ES, D3D11 and D3D12 backends.
// For Vulkan we ship a pre-compiled SPIR-V blob in
// src/common/vulkan/embedded_spirv/screen_quad_vs.inc
// generated from this file by tools/regen_vulkan_spirv.py. The build itself
// has no glslangValidator dependency.
#version 450 core
layout(location = 0) out VertexData {
vec2 v_tex0;
};
void main()
{
v_tex0 = vec2(float((uint(gl_VertexIndex) << 1) & 2u), float(uint(gl_VertexIndex) & 2u));
gl_Position = vec4(v_tex0 * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0);
// Flip Y to match the convention of ShaderGen output for Vulkan.
gl_Position.y = -gl_Position.y;
}