blob: 20144602f37cb43c8142de76ae17e58352d21e79 [file] [log] [blame]
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +00001uint2 tint_ftou(float2 v) {
2 return ((v < (4294967040.0f).xx) ? ((v < (0.0f).xx) ? (0u).xx : uint2(v)) : (4294967295u).xx);
3}
4
Brandon Jones41cbf022022-04-29 21:00:14 +00005struct GammaTransferParams {
6 float G;
7 float A;
8 float B;
9 float C;
10 float D;
11 float E;
12 float F;
13 uint padding;
14};
Antonio Maioranoa730eb72022-04-06 13:57:54 +000015struct ExternalTextureParams {
16 uint numPlanes;
jchen10ef62b582022-06-22 03:14:26 +000017 uint doYuvToRgbConversionOnly;
Brandon Jones6cb57a92022-04-21 16:02:36 +000018 float3x4 yuvToRgbConversionMatrix;
Brandon Jones41cbf022022-04-29 21:00:14 +000019 GammaTransferParams gammaDecodeParams;
20 GammaTransferParams gammaEncodeParams;
21 float3x3 gamutConversionMatrix;
Ben Claytonbe367b72023-01-04 12:29:56 +000022 float3x2 coordTransformationMatrix;
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +000023 float3x2 loadTransformationMatrix;
24 float2 samplePlane0RectMin;
25 float2 samplePlane0RectMax;
26 float2 samplePlane1RectMin;
27 float2 samplePlane1RectMax;
28 uint2 displayVisibleRectMax;
29 float2 plane1CoordFactor;
Antonio Maioranoa730eb72022-04-06 13:57:54 +000030};
31
32Texture2D<float4> ext_tex_plane_1 : register(t1, space1);
33cbuffer cbuffer_ext_tex_params : register(b2, space1) {
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +000034 uint4 ext_tex_params[17];
Antonio Maioranoa730eb72022-04-06 13:57:54 +000035};
36Texture2D<float4> arg_0 : register(t0, space1);
37
Brandon Jones41cbf022022-04-29 21:00:14 +000038float3 gammaCorrection(float3 v, GammaTransferParams params) {
Antonio Maiorano144ebed2024-01-30 16:30:15 +000039 bool3 cond = (abs(v) < float3((params.D).xxx));
40 float3 t = (float3(sign(v)) * ((params.C * abs(v)) + params.F));
41 float3 f = (float3(sign(v)) * (pow(((params.A * abs(v)) + params.B), float3((params.G).xxx)) + params.E));
Brandon Jones41cbf022022-04-29 21:00:14 +000042 return (cond ? t : f);
43}
44
Antonio Maioranoa730eb72022-04-06 13:57:54 +000045float4 textureLoadExternal(Texture2D<float4> plane0, Texture2D<float4> plane1, int2 coord, ExternalTextureParams params) {
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +000046 uint2 clampedCoords = min(uint2(coord), params.displayVisibleRectMax);
47 uint2 plane0_clamped = tint_ftou(round(mul(float3(float2(clampedCoords), 1.0f), params.loadTransformationMatrix)));
Brandon Jones71913372023-08-12 00:11:07 +000048 float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
Antonio Maioranoa730eb72022-04-06 13:57:54 +000049 if ((params.numPlanes == 1u)) {
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +000050 color = plane0.Load(uint3(plane0_clamped, uint(0))).rgba;
Brandon Jones6cb57a92022-04-21 16:02:36 +000051 } else {
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +000052 uint2 plane1_clamped = tint_ftou((float2(plane0_clamped) * params.plane1CoordFactor));
53 color = float4(mul(params.yuvToRgbConversionMatrix, float4(plane0.Load(uint3(plane0_clamped, uint(0))).r, plane1.Load(uint3(plane1_clamped, uint(0))).rg, 1.0f)), 1.0f);
Antonio Maioranoa730eb72022-04-06 13:57:54 +000054 }
jchen10ef62b582022-06-22 03:14:26 +000055 if ((params.doYuvToRgbConversionOnly == 0u)) {
Brandon Jones71913372023-08-12 00:11:07 +000056 color = float4(gammaCorrection(color.rgb, params.gammaDecodeParams), color.a);
57 color = float4(mul(color.rgb, params.gamutConversionMatrix), color.a);
58 color = float4(gammaCorrection(color.rgb, params.gammaEncodeParams), color.a);
jchen10ef62b582022-06-22 03:14:26 +000059 }
Brandon Jones71913372023-08-12 00:11:07 +000060 return color;
Antonio Maioranoa730eb72022-04-06 13:57:54 +000061}
62
63float4 textureLoad2d(Texture2D<float4> tint_symbol, Texture2D<float4> ext_tex_plane_1_1, ExternalTextureParams ext_tex_params_1, int2 coords) {
64 return textureLoadExternal(tint_symbol, ext_tex_plane_1_1, coords, ext_tex_params_1);
65}
66
Ben Clayton1a1b5272023-02-24 17:16:55 +000067float3x4 ext_tex_params_load_2(uint offset) {
Antonio Maioranoa730eb72022-04-06 13:57:54 +000068 const uint scalar_offset = ((offset + 0u)) / 4;
Brandon Jones6cb57a92022-04-21 16:02:36 +000069 const uint scalar_offset_1 = ((offset + 16u)) / 4;
70 const uint scalar_offset_2 = ((offset + 32u)) / 4;
Ben Clayton1a1b5272023-02-24 17:16:55 +000071 return float3x4(asfloat(ext_tex_params[scalar_offset / 4]), asfloat(ext_tex_params[scalar_offset_1 / 4]), asfloat(ext_tex_params[scalar_offset_2 / 4]));
Brandon Jones6cb57a92022-04-21 16:02:36 +000072}
73
Ben Clayton1a1b5272023-02-24 17:16:55 +000074GammaTransferParams ext_tex_params_load_4(uint offset) {
Brandon Jones6cb57a92022-04-21 16:02:36 +000075 const uint scalar_offset_3 = ((offset + 0u)) / 4;
Brandon Jones41cbf022022-04-29 21:00:14 +000076 const uint scalar_offset_4 = ((offset + 4u)) / 4;
77 const uint scalar_offset_5 = ((offset + 8u)) / 4;
78 const uint scalar_offset_6 = ((offset + 12u)) / 4;
79 const uint scalar_offset_7 = ((offset + 16u)) / 4;
80 const uint scalar_offset_8 = ((offset + 20u)) / 4;
81 const uint scalar_offset_9 = ((offset + 24u)) / 4;
82 const uint scalar_offset_10 = ((offset + 28u)) / 4;
Antonio Maiorano144ebed2024-01-30 16:30:15 +000083 GammaTransferParams tint_symbol_2 = {asfloat(ext_tex_params[scalar_offset_3 / 4][scalar_offset_3 % 4]), asfloat(ext_tex_params[scalar_offset_4 / 4][scalar_offset_4 % 4]), asfloat(ext_tex_params[scalar_offset_5 / 4][scalar_offset_5 % 4]), asfloat(ext_tex_params[scalar_offset_6 / 4][scalar_offset_6 % 4]), asfloat(ext_tex_params[scalar_offset_7 / 4][scalar_offset_7 % 4]), asfloat(ext_tex_params[scalar_offset_8 / 4][scalar_offset_8 % 4]), asfloat(ext_tex_params[scalar_offset_9 / 4][scalar_offset_9 % 4]), ext_tex_params[scalar_offset_10 / 4][scalar_offset_10 % 4]};
Ben Clayton1a1b5272023-02-24 17:16:55 +000084 return tint_symbol_2;
Brandon Jones41cbf022022-04-29 21:00:14 +000085}
86
Ben Clayton1a1b5272023-02-24 17:16:55 +000087float3x3 ext_tex_params_load_6(uint offset) {
Brandon Jones41cbf022022-04-29 21:00:14 +000088 const uint scalar_offset_11 = ((offset + 0u)) / 4;
89 const uint scalar_offset_12 = ((offset + 16u)) / 4;
90 const uint scalar_offset_13 = ((offset + 32u)) / 4;
Ben Clayton1a1b5272023-02-24 17:16:55 +000091 return float3x3(asfloat(ext_tex_params[scalar_offset_11 / 4].xyz), asfloat(ext_tex_params[scalar_offset_12 / 4].xyz), asfloat(ext_tex_params[scalar_offset_13 / 4].xyz));
Brandon Jones41cbf022022-04-29 21:00:14 +000092}
93
Ben Clayton1a1b5272023-02-24 17:16:55 +000094float3x2 ext_tex_params_load_8(uint offset) {
Brandon Jones41cbf022022-04-29 21:00:14 +000095 const uint scalar_offset_14 = ((offset + 0u)) / 4;
Ben Clayton1a1b5272023-02-24 17:16:55 +000096 uint4 ubo_load = ext_tex_params[scalar_offset_14 / 4];
Ben Claytonbe367b72023-01-04 12:29:56 +000097 const uint scalar_offset_15 = ((offset + 8u)) / 4;
Ben Clayton1a1b5272023-02-24 17:16:55 +000098 uint4 ubo_load_1 = ext_tex_params[scalar_offset_15 / 4];
Ben Claytonbe367b72023-01-04 12:29:56 +000099 const uint scalar_offset_16 = ((offset + 16u)) / 4;
Ben Clayton1a1b5272023-02-24 17:16:55 +0000100 uint4 ubo_load_2 = ext_tex_params[scalar_offset_16 / 4];
Ben Claytonbe367b72023-01-04 12:29:56 +0000101 return float3x2(asfloat(((scalar_offset_14 & 2) ? ubo_load.zw : ubo_load.xy)), asfloat(((scalar_offset_15 & 2) ? ubo_load_1.zw : ubo_load_1.xy)), asfloat(((scalar_offset_16 & 2) ? ubo_load_2.zw : ubo_load_2.xy)));
Brandon Jones85ceb082022-11-30 21:32:26 +0000102}
103
Ben Clayton1a1b5272023-02-24 17:16:55 +0000104ExternalTextureParams ext_tex_params_load(uint offset) {
Ben Claytonbe367b72023-01-04 12:29:56 +0000105 const uint scalar_offset_17 = ((offset + 0u)) / 4;
106 const uint scalar_offset_18 = ((offset + 4u)) / 4;
Yan,Shaobod3bebe6c2024-05-06 03:57:27 +0000107 const uint scalar_offset_19 = ((offset + 224u)) / 4;
108 uint4 ubo_load_3 = ext_tex_params[scalar_offset_19 / 4];
109 const uint scalar_offset_20 = ((offset + 232u)) / 4;
110 uint4 ubo_load_4 = ext_tex_params[scalar_offset_20 / 4];
111 const uint scalar_offset_21 = ((offset + 240u)) / 4;
112 uint4 ubo_load_5 = ext_tex_params[scalar_offset_21 / 4];
113 const uint scalar_offset_22 = ((offset + 248u)) / 4;
114 uint4 ubo_load_6 = ext_tex_params[scalar_offset_22 / 4];
115 const uint scalar_offset_23 = ((offset + 256u)) / 4;
116 uint4 ubo_load_7 = ext_tex_params[scalar_offset_23 / 4];
117 const uint scalar_offset_24 = ((offset + 264u)) / 4;
118 uint4 ubo_load_8 = ext_tex_params[scalar_offset_24 / 4];
119 ExternalTextureParams tint_symbol_3 = {ext_tex_params[scalar_offset_17 / 4][scalar_offset_17 % 4], ext_tex_params[scalar_offset_18 / 4][scalar_offset_18 % 4], ext_tex_params_load_2((offset + 16u)), ext_tex_params_load_4((offset + 64u)), ext_tex_params_load_4((offset + 96u)), ext_tex_params_load_6((offset + 128u)), ext_tex_params_load_8((offset + 176u)), ext_tex_params_load_8((offset + 200u)), asfloat(((scalar_offset_19 & 2) ? ubo_load_3.zw : ubo_load_3.xy)), asfloat(((scalar_offset_20 & 2) ? ubo_load_4.zw : ubo_load_4.xy)), asfloat(((scalar_offset_21 & 2) ? ubo_load_5.zw : ubo_load_5.xy)), asfloat(((scalar_offset_22 & 2) ? ubo_load_6.zw : ubo_load_6.xy)), ((scalar_offset_23 & 2) ? ubo_load_7.zw : ubo_load_7.xy), asfloat(((scalar_offset_24 & 2) ? ubo_load_8.zw : ubo_load_8.xy))};
Ben Clayton1a1b5272023-02-24 17:16:55 +0000120 return tint_symbol_3;
Antonio Maioranoa730eb72022-04-06 13:57:54 +0000121}
122
123void doTextureLoad() {
Ben Clayton1a1b5272023-02-24 17:16:55 +0000124 float4 res = textureLoad2d(arg_0, ext_tex_plane_1, ext_tex_params_load(0u), (0).xx);
Antonio Maioranoa730eb72022-04-06 13:57:54 +0000125}
126
127struct tint_symbol_1 {
128 float4 value : SV_Position;
129};
130
131float4 vertex_main_inner() {
132 doTextureLoad();
Ben Claytone9f8b092022-06-01 13:14:39 +0000133 return (0.0f).xxxx;
Antonio Maioranoa730eb72022-04-06 13:57:54 +0000134}
135
136tint_symbol_1 vertex_main() {
Antonio Maiorano144ebed2024-01-30 16:30:15 +0000137 float4 inner_result = vertex_main_inner();
Antonio Maioranoa730eb72022-04-06 13:57:54 +0000138 tint_symbol_1 wrapper_result = (tint_symbol_1)0;
139 wrapper_result.value = inner_result;
140 return wrapper_result;
141}
142
143void fragment_main() {
144 doTextureLoad();
145 return;
146}
147
148[numthreads(1, 1, 1)]
149void compute_main() {
150 doTextureLoad();
151 return;
152}