mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-09 04:49:39 -10:00
* GLES Shaders and Vulkan Clip fallback * clip fallback: change defined name, set from engine side and invert usage * Proposed changes and fixes Fixed: -The OpenGL ES option stays on when OpenGL is off (issue #7984) -Missing precision in copy-f, volumetric-f and smaa-resolve-f -msaa-f including z-compress before precision quantification -missing float literals in volumetric-f -Fixed decals blending -Restored glBindFragDataLocation() for use in legacy external shaders -Enabled GL_ARB_explicit_attrib_location ext for GLSL version below 330 in GL -Guarded enabling/disabling of GL_CLIP_DISTANCE0_EXT and GL_DEPTH_CLAMP -Restored PI in lighting.sdr -removed "External shaders only" indication from cmakelists.txt
76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "globalincs/pstypes.h"
|
|
#include "graphics/2d.h"
|
|
|
|
#include <vulkan/vulkan.hpp>
|
|
|
|
#include <memory>
|
|
|
|
namespace graphics::vulkan {
|
|
|
|
class VulkanShadercLibrary;
|
|
|
|
/**
|
|
* @brief Runtime GLSL->SPIR-V compiler using shaderc
|
|
*
|
|
* Replaces build-time glslc compilation. Compiles GLSL to SPIR-V at runtime
|
|
* with disk caching, #define variant injection, and include resolution.
|
|
* The shaderc library is loaded dynamically.
|
|
*/
|
|
class VulkanShaderCompiler {
|
|
public:
|
|
VulkanShaderCompiler();
|
|
~VulkanShaderCompiler();
|
|
|
|
bool init(bool hwClipDistance);
|
|
void shutdown();
|
|
|
|
/**
|
|
* @brief Check if the shaderc library was loaded successfully
|
|
*/
|
|
bool isAvailable() const;
|
|
|
|
/**
|
|
* @brief Compile GLSL to SPIR-V with disk caching
|
|
*
|
|
* @param filename GLSL source filename, e.g. "main.frag"
|
|
* @param stage Vertex or fragment
|
|
* @param sdrType Shader type (for variant flag lookup)
|
|
* @param flags SDR_FLAG_* bitmask — matching flags injected as #defines
|
|
* @param requiresRaytracing Whether this (sdrType, flags) combination uses
|
|
* GL_EXT_ray_query (see shader_variant_requires_raytracing()) and
|
|
* therefore needs a SPIR-V target-env new enough to support it.
|
|
* Left false for all other shaders so they keep targeting the
|
|
* lowest common Vulkan version.
|
|
* @return SPIR-V words, or empty vector on failure
|
|
*/
|
|
SCP_vector<uint32_t> compile(const SCP_string& filename,
|
|
vk::ShaderStageFlagBits stage,
|
|
shader_type sdrType,
|
|
unsigned int flags,
|
|
bool requiresRaytracing = false);
|
|
|
|
/**
|
|
* @brief Delete stale cache files older than ~2 months
|
|
*/
|
|
static void purgeOldCache();
|
|
|
|
private:
|
|
/**
|
|
* @brief Build the GLSL header with #defines for variant flags
|
|
*/
|
|
SCP_string buildHeader(vk::ShaderStageFlagBits stage, shader_type sdrType, unsigned int flags) const;
|
|
|
|
/**
|
|
* @brief Compute an MD5 hash of the header + source + version tag for disk caching
|
|
*/
|
|
static SCP_string computeSourceHash(const SCP_string& header, const SCP_string& source);
|
|
|
|
std::unique_ptr<VulkanShadercLibrary> m_shaderc;
|
|
bool m_initialized = false;
|
|
bool m_hwClipDistance = false;
|
|
};
|
|
|
|
} // namespace graphics::vulkan
|