renderer_vulkan: Disable dynamic index conditionally (#20)

This commit is contained in:
GPUCode
2024-03-07 13:12:21 +02:00
committed by PabloMK7
parent 277570f7c7
commit 7ac37da6e3
7 changed files with 68 additions and 13 deletions

View File

@@ -224,15 +224,17 @@ void RendererVulkan::LoadFBToScreenInfo(const Pica::FramebufferConfig& framebuff
}
void RendererVulkan::CompileShaders() {
vk::Device device = instance.GetDevice();
const vk::Device device = instance.GetDevice();
const std::string_view preamble =
instance.IsImageArrayDynamicIndexSupported() ? "#define ARRAY_DYNAMIC_INDEX" : "";
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[0] = Compile(HostShaders::VULKAN_PRESENT_FRAG,
vk::ShaderStageFlagBits::eFragment, device, preamble);
present_shaders[1] = Compile(HostShaders::VULKAN_PRESENT_ANAGLYPH_FRAG,
vk::ShaderStageFlagBits::eFragment, device);
vk::ShaderStageFlagBits::eFragment, device, preamble);
present_shaders[2] = Compile(HostShaders::VULKAN_PRESENT_INTERLACED_FRAG,
vk::ShaderStageFlagBits::eFragment, device);
vk::ShaderStageFlagBits::eFragment, device, preamble);
auto properties = instance.GetPhysicalDevice().getProperties();
for (std::size_t i = 0; i < present_samplers.size(); i++) {

View File

@@ -248,6 +248,11 @@ public:
return triangle_fan_supported;
}
/// Returns true if dynamic indices can be used inside shaders.
bool IsImageArrayDynamicIndexSupported() const {
return features.shaderSampledImageArrayDynamicIndexing;
}
/// Returns the minimum vertex stride alignment
u32 GetMinVertexStrideAlignment() const {
return min_vertex_stride_alignment;

View File

@@ -158,7 +158,8 @@ bool InitializeCompiler() {
}
} // Anonymous namespace
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device) {
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device,
std::string_view premable) {
if (!InitializeCompiler()) {
return {};
}
@@ -176,6 +177,7 @@ vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, v
shader->setEnvTarget(glslang::EShTargetSpv,
glslang::EShTargetLanguageVersion::EShTargetSpv_1_3);
shader->setStringsWithLengths(&pass_source_code, &pass_source_code_length, 1);
shader->setPreamble(premable.data());
glslang::TShader::ForbidIncluder includer;
if (!shader->parse(&DefaultTBuiltInResource, default_version, profile, false, true, messages,

View File

@@ -16,7 +16,8 @@ namespace Vulkan {
* @param stage The pipeline stage the shader will be used in.
* @param device The vulkan device handle.
*/
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device);
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device,
std::string_view premable = "");
/**
* @brief Creates a vulkan shader module from SPIR-V bytecode.