Unity-Technologies / HLSLcc

DirectX shader bytecode cross compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid cast in Metal translation

davidebarbieri opened this issue · comments

The Metal translation replaces the SV_POSITION declaration with float4 mtl_Position,
but then, it uses the replaced type (e.g. half4) instead of the new one (float4).

Input:
Shader "MyTransparent"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
}

SubShader
{
	Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }

	Blend SrcAlpha OneMinusSrcAlpha
	ZWrite off

	Pass
	{
		CGPROGRAM

#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

		struct appdata
		{
			half4 vertex : POSITION;
			half2 uv : TEXCOORD0;
		};

		struct v2f
		{
			half2 uv : TEXCOORD0;
			half4 vertex : SV_POSITION;
		};

		sampler2D _MainTex;
		half4 _MainTex_ST;
		fixed4 _Color;

		v2f vert(appdata v)
		{
			v2f o;
			o.vertex = UnityObjectToClipPos(v.vertex);
			o.uv = TRANSFORM_TEX(v.uv, _MainTex);
			return o;
		}

		fixed4 frag(v2f i) : SV_Target
		{
			fixed4 col = tex2D(_MainTex, i.uv)*_Color;
			return col;
		}
		ENDCG
	}
}

}

Output:
program_source:33:25: error: assigning to 'float4' (aka 'vector_float4') from incompatible type 'half4' (aka 'vector_half4')
output.mtl_Position = half4(u_xlat0);
^ ~

#include <metal_stdlib>
#include <metal_texture>
using namespace metal;
struct Globals_Type
{
float4 hlslcc_mtx4x4glstate_matrix_mvp[4];
half4 _MainTex_ST;
};
struct Mtl_VertexIn
{
half4 POSITION0 [[ attribute(0) ]] ;
half2 TEXCOORD0 [[ attribute(1) ]] ;
};
struct Mtl_VertexOut
{
half2 TEXCOORD0 [[ user(TEXCOORD0) ]];
float4 mtl_Position [[ position ]];
};
vertex Mtl_VertexOut xlatMtlMain(
constant Globals_Type& Globals [[ buffer(0) ]],
Mtl_VertexIn input [[ stage_in ]])
{
Mtl_VertexOut output;
float4 u_xlat0;
output.TEXCOORD0.xy = half2(input.TEXCOORD0.xy * Globals._MainTex_ST.xy + Globals._MainTex_ST.zw);
u_xlat0 = float4(input.POSITION0.yyyy) * Globals.hlslcc_mtx4x4glstate_matrix_mvp[1];
u_xlat0 = Globals.hlslcc_mtx4x4glstate_matrix_mvp[0] * float4(input.POSITION0.xxxx) + u_xlat0;
u_xlat0 = Globals.hlslcc_mtx4x4glstate_matrix_mvp[2] * float4(input.POSITION0.zzzz) + u_xlat0;
u_xlat0 = u_xlat0 + Globals.hlslcc_mtx4x4glstate_matrix_mvp[3];
output.mtl_Position = half4(u_xlat0);
return output;
}

Hi, this likely is fixed in current Unity releases, but if it's not, can you file a Unity bugreport (Fogbugz) about it so it gets properly tracked and we know which Unity release/target it concerns? Thanks