Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 1 | uint2 tint_ftou(float2 v) { |
| 2 | return ((v < (4294967040.0f).xx) ? ((v < (0.0f).xx) ? (0u).xx : uint2(v)) : (4294967295u).xx); |
| 3 | } |
| 4 | |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 5 | struct 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 Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 15 | struct ExternalTextureParams { |
| 16 | uint numPlanes; |
jchen10 | ef62b58 | 2022-06-22 03:14:26 +0000 | [diff] [blame] | 17 | uint doYuvToRgbConversionOnly; |
Brandon Jones | 6cb57a9 | 2022-04-21 16:02:36 +0000 | [diff] [blame] | 18 | float3x4 yuvToRgbConversionMatrix; |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 19 | GammaTransferParams gammaDecodeParams; |
| 20 | GammaTransferParams gammaEncodeParams; |
| 21 | float3x3 gamutConversionMatrix; |
Ben Clayton | be367b7 | 2023-01-04 12:29:56 +0000 | [diff] [blame] | 22 | float3x2 coordTransformationMatrix; |
Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 23 | float3x2 loadTransformationMatrix; |
| 24 | float2 samplePlane0RectMin; |
| 25 | float2 samplePlane0RectMax; |
| 26 | float2 samplePlane1RectMin; |
| 27 | float2 samplePlane1RectMax; |
| 28 | uint2 displayVisibleRectMax; |
| 29 | float2 plane1CoordFactor; |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | Texture2D<float4> ext_tex_plane_1 : register(t1, space1); |
| 33 | cbuffer cbuffer_ext_tex_params : register(b2, space1) { |
Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 34 | uint4 ext_tex_params[17]; |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 35 | }; |
| 36 | Texture2D<float4> arg_0 : register(t0, space1); |
| 37 | |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 38 | float3 gammaCorrection(float3 v, GammaTransferParams params) { |
Antonio Maiorano | 144ebed | 2024-01-30 16:30:15 +0000 | [diff] [blame] | 39 | 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 Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 42 | return (cond ? t : f); |
| 43 | } |
| 44 | |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 45 | float4 textureLoadExternal(Texture2D<float4> plane0, Texture2D<float4> plane1, int2 coord, ExternalTextureParams params) { |
Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 46 | uint2 clampedCoords = min(uint2(coord), params.displayVisibleRectMax); |
| 47 | uint2 plane0_clamped = tint_ftou(round(mul(float3(float2(clampedCoords), 1.0f), params.loadTransformationMatrix))); |
Brandon Jones | 7191337 | 2023-08-12 00:11:07 +0000 | [diff] [blame] | 48 | float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f); |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 49 | if ((params.numPlanes == 1u)) { |
Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 50 | color = plane0.Load(uint3(plane0_clamped, uint(0))).rgba; |
Brandon Jones | 6cb57a9 | 2022-04-21 16:02:36 +0000 | [diff] [blame] | 51 | } else { |
Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 52 | 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 Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 54 | } |
jchen10 | ef62b58 | 2022-06-22 03:14:26 +0000 | [diff] [blame] | 55 | if ((params.doYuvToRgbConversionOnly == 0u)) { |
Brandon Jones | 7191337 | 2023-08-12 00:11:07 +0000 | [diff] [blame] | 56 | 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); |
jchen10 | ef62b58 | 2022-06-22 03:14:26 +0000 | [diff] [blame] | 59 | } |
Brandon Jones | 7191337 | 2023-08-12 00:11:07 +0000 | [diff] [blame] | 60 | return color; |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | float4 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 Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 67 | float3x4 ext_tex_params_load_2(uint offset) { |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 68 | const uint scalar_offset = ((offset + 0u)) / 4; |
Brandon Jones | 6cb57a9 | 2022-04-21 16:02:36 +0000 | [diff] [blame] | 69 | const uint scalar_offset_1 = ((offset + 16u)) / 4; |
| 70 | const uint scalar_offset_2 = ((offset + 32u)) / 4; |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 71 | 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 Jones | 6cb57a9 | 2022-04-21 16:02:36 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 74 | GammaTransferParams ext_tex_params_load_4(uint offset) { |
Brandon Jones | 6cb57a9 | 2022-04-21 16:02:36 +0000 | [diff] [blame] | 75 | const uint scalar_offset_3 = ((offset + 0u)) / 4; |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 76 | 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 Maiorano | 144ebed | 2024-01-30 16:30:15 +0000 | [diff] [blame] | 83 | 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 Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 84 | return tint_symbol_2; |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 87 | float3x3 ext_tex_params_load_6(uint offset) { |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 88 | 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 Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 91 | 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 Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 94 | float3x2 ext_tex_params_load_8(uint offset) { |
Brandon Jones | 41cbf02 | 2022-04-29 21:00:14 +0000 | [diff] [blame] | 95 | const uint scalar_offset_14 = ((offset + 0u)) / 4; |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 96 | uint4 ubo_load = ext_tex_params[scalar_offset_14 / 4]; |
Ben Clayton | be367b7 | 2023-01-04 12:29:56 +0000 | [diff] [blame] | 97 | const uint scalar_offset_15 = ((offset + 8u)) / 4; |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 98 | uint4 ubo_load_1 = ext_tex_params[scalar_offset_15 / 4]; |
Ben Clayton | be367b7 | 2023-01-04 12:29:56 +0000 | [diff] [blame] | 99 | const uint scalar_offset_16 = ((offset + 16u)) / 4; |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 100 | uint4 ubo_load_2 = ext_tex_params[scalar_offset_16 / 4]; |
Ben Clayton | be367b7 | 2023-01-04 12:29:56 +0000 | [diff] [blame] | 101 | 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 Jones | 85ceb08 | 2022-11-30 21:32:26 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 104 | ExternalTextureParams ext_tex_params_load(uint offset) { |
Ben Clayton | be367b7 | 2023-01-04 12:29:56 +0000 | [diff] [blame] | 105 | const uint scalar_offset_17 = ((offset + 0u)) / 4; |
| 106 | const uint scalar_offset_18 = ((offset + 4u)) / 4; |
Yan,Shaobo | d3bebe6c | 2024-05-06 03:57:27 +0000 | [diff] [blame] | 107 | 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 Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 120 | return tint_symbol_3; |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void doTextureLoad() { |
Ben Clayton | 1a1b527 | 2023-02-24 17:16:55 +0000 | [diff] [blame] | 124 | float4 res = textureLoad2d(arg_0, ext_tex_plane_1, ext_tex_params_load(0u), (0).xx); |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | struct tint_symbol_1 { |
| 128 | float4 value : SV_Position; |
| 129 | }; |
| 130 | |
| 131 | float4 vertex_main_inner() { |
| 132 | doTextureLoad(); |
Ben Clayton | e9f8b09 | 2022-06-01 13:14:39 +0000 | [diff] [blame] | 133 | return (0.0f).xxxx; |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | tint_symbol_1 vertex_main() { |
Antonio Maiorano | 144ebed | 2024-01-30 16:30:15 +0000 | [diff] [blame] | 137 | float4 inner_result = vertex_main_inner(); |
Antonio Maiorano | a730eb7 | 2022-04-06 13:57:54 +0000 | [diff] [blame] | 138 | tint_symbol_1 wrapper_result = (tint_symbol_1)0; |
| 139 | wrapper_result.value = inner_result; |
| 140 | return wrapper_result; |
| 141 | } |
| 142 | |
| 143 | void fragment_main() { |
| 144 | doTextureLoad(); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | [numthreads(1, 1, 1)] |
| 149 | void compute_main() { |
| 150 | doTextureLoad(); |
| 151 | return; |
| 152 | } |