Search Issue Tracker

By Design

Votes

0

Found in

2023.1.7f1

2023.2.0b3

Issue ID

UUM-45337

Regression

No

Shader error when using Metal Graphics API and shaders use native 16-bit precision

--

-

How to reproduce:
1. Open the attached “Shader16Bug.zip“ project
2. Open the “SampleScene“

Expected result: No errors in the Console
Actual result: “SV_Position must be a 4-component 32-bit float vector or a composite which recursively contains only such a vector at line 44“ error in the Console

Reproducible with: 2023.1.7f1, 2023.2.0b3
Can’t test with: 2021.3.29f1, 2022.3.6f1 (Unrelated to issue errors in the Console)

Reproducible on: macOS 13.4.1 (Intel)
Not reproducible on: Windows 10

  1. Resolution Note:

    The project contains a shader "Custom/HalfTextureColor" that contains the following:

    ```
    struct Varyings
    {
    min16float4 positionCS : SV_POSITION;
    min16float2 uv : TEXCOORD0;
    };
    ```

    According to the HLSL documentation, `SV_POSITION` must be declared as `float4`. Also, according to Metal Shading Language documentation, section 5.2.3.3, the vertex shader ouput position must also be `float4`. The Metal shader compiler will output errors otherwise. Therefore, Unity displays the mentioned warning "SV_Position must be a 4-component 32-bit float vector or a composite which recursively contains only such a vector at line 44".

    In addition, if the shader accesses high resolution textures (with either width or height bigger than 2048), it might be worth considering changing the type of `uv` to `float4`, as 16-bit floats start to have precision problems with values higher than 2048. For example, 16-bit floats don't have enough precision to represent the number 2049.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.