google / google/shaderc

glslc not setting VULKAN = 120, and not compiling to half

Open
#1,177 35 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
445
Avg merge
11h 6m
Merged PRs (30d)
6

Description

How do you

1. Get glslc to set VULKAN define to anything other than 100. I'm requesting 1.2?
2. Get float16_t and f16vec2/3/4 and f16mat2/3/4 to be honored as types?
3. Get functions like clamp(), sign(), abs() to splice in the half version so I don't get a type mismatch error.

Here's the command line to compile. I don't see any other args related to half for the command line. Is no one using half with Vulkan GLSL shaders? I found the following in-depth talk about getting HLSL to generate half, and zero literature on doing the same with GLSL.

And I don't want to use "mediump float" since that often gets mapped to float, and so I need something more explicit. The spirv flags like "--convert-relaxed-to-half " just end up adding a ton of conversions to half with little in the way of perf benefits. If Vulkan really is a mobile API, then half needs to be better supported on iOS and Android and even some consoles.

https://therealmjp.github.io/posts/shader-fp16/

glslc --target-env=vulkan1.2 -fentry-point=main -fauto-bind-uniforms -fauto-map-locations -std=310es testShader.frag -o testShader.spv

```
#version 310 es

//#define VULKAN 120

//#if VULKAN >= 120
// blarg120
//#elseif VULKAN > 110
// blarg110
//#else
// blarg100
//#endif

#if VULKAN >= 120
#extension VK_KHR_shader_float16_int8 : enable
#else
#extension GL_AMD_gpu_shader_half_float: enable
#extension GL_AMD_gpu_shader_half_float_fetch: enable
#endif

#if defined(GL_ES)
precision highp float;
precision highp int;
#endif

// Types defined to closer match Metal and force 16bit ALU
#define half float16_t

half saturate(half x)
{
return clamp(x, half(0.0), half(1.0));
}

layout(location = 0) out vec4 fragColor;

void main()
{
fragColor = vec4(saturate(half(2)));
}
```

Output:
testShader.frag:30: error: 'clamp' : no matching overloaded function found
testShader.frag:30: error: 'return' : type does not match, or is not convertible to, the function's return type

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.