From ae859934cafffb1050b3230002df324c5a02e859 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 23 Aug 2018 15:37:09 +0200 Subject: [PATCH] Use GL_NV_gpu_shader5 as a fallback for AMD_gpu_shader_half_float. --- .../shaders/desktop-only/frag/fp16.desktop.frag | 6 ++++++ .../shaders/desktop-only/frag/fp16.desktop.frag | 6 ++++++ spirv_glsl.cpp | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/reference/opt/shaders/desktop-only/frag/fp16.desktop.frag b/reference/opt/shaders/desktop-only/frag/fp16.desktop.frag index 1761424e..4586a8ec 100644 --- a/reference/opt/shaders/desktop-only/frag/fp16.desktop.frag +++ b/reference/opt/shaders/desktop-only/frag/fp16.desktop.frag @@ -1,5 +1,11 @@ #version 450 +#if defined(GL_AMD_gpu_shader_half_float) #extension GL_AMD_gpu_shader_half_float : require +#elif defined(GL_NV_gpu_shader5) +#extension GL_NV_gpu_shader5 : require +#else +#error No extension available for FP16. +#endif layout(location = 3) in f16vec4 v4; diff --git a/reference/shaders/desktop-only/frag/fp16.desktop.frag b/reference/shaders/desktop-only/frag/fp16.desktop.frag index 0c5203a1..e1fc045c 100644 --- a/reference/shaders/desktop-only/frag/fp16.desktop.frag +++ b/reference/shaders/desktop-only/frag/fp16.desktop.frag @@ -1,5 +1,11 @@ #version 450 +#if defined(GL_AMD_gpu_shader_half_float) #extension GL_AMD_gpu_shader_half_float : require +#elif defined(GL_NV_gpu_shader5) +#extension GL_NV_gpu_shader5 : require +#else +#error No extension available for FP16. +#endif struct ResType { diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 542ec733..78cce962 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -479,7 +479,22 @@ void CompilerGLSL::emit_header() } for (auto &ext : forced_extensions) - statement("#extension ", ext, " : require"); + { + if (ext == "GL_AMD_gpu_shader_half_float" && !options.vulkan_semantics) + { + // Special case, this extension has a potential fallback to another vendor extension in normal GLSL. + // GL_AMD_gpu_shader_half_float is a superset, so try that first. + statement("#if defined(GL_AMD_gpu_shader_half_float)"); + statement("#extension GL_AMD_gpu_shader_half_float : require"); + statement("#elif defined(GL_NV_gpu_shader5)"); + statement("#extension GL_NV_gpu_shader5 : require"); + statement("#else"); + statement("#error No extension available for FP16."); + statement("#endif"); + } + else + statement("#extension ", ext, " : require"); + } for (auto &header : header_lines) statement(header);