KhronosGroup / KhronosGroup/SPIRV-Tools
spirv-opt: Replace float type with half for texture samples, function parameters, struct members and uniforms
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 709
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 28
Description
As far as I know, spirv-opt can mark all float op with RelaxPrecision decoration by --relax-float-ops option and it can further convert these float ops to half ops by --convert-relaxed-to-half option.
However, I found no way to replace the type of texture samples, function parameters, struct members and uniforms.
For example, I compiled the following very-simple-HLSL to SPIRV and saved it for further converting it to metal or glsl:
> struct vertdata
> {
> float2 uv;
> };
>
> Texture2D\ mainTex;
> SamplerState mainSampler;
>
> void frag(int vertdata data, out float4 outcolor : SV_Target0)
> {
> outcolor = mainTex.Sample(mainSampler, data.uv);
> }
And one day I may want to change the type of mainTex from Texture2D\ to Texture2D\ for saving some bandwidth, and after the change the coresponding HLSL should look like this:
> Texture2D\ mainTex;
> SamplerState mainSampler;
> void frag(in vertdata data, out float4 outcolor : SV_Target0)
> {
> outcolor = float4(mainTex.Sample(mainSampler, data.uv));
> }
I would prefer using spirv-opt on the SPIRV to rewriting HLSL sources by hand because it would be far more convenient for large amount of shaders. But for now there seems no way.
Would this be a new feature or did I miss something?
Contributor guide
Assessment
This issue has not been assessed yet.