2727 GRID_SAMPLER_2D_SHADER_LANGUAGE ,
2828 GRID_SAMPLER_2D_SHADER_SOURCE ,
2929 GRID_SAMPLER_2D_VK_FORMAT ,
30- GRID_SAMPLER_2D_WORKGROUP_SIZES ,
3130)
3231
3332
@@ -45,11 +44,12 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_round_trip():
4544 interpolation_mode = 0 ,
4645 padding_mode = 2 ,
4746 align_corners = True ,
47+ output_shape = (1 , 4 , 8 , 8 ),
4848 )
4949 decoded = decode_payload (encode_payload (payload ))
5050
5151 assert decoded ["entry_point" ] == GRID_SAMPLER_2D_SHADER_ENTRY_POINT
52- assert decoded ["workgroup_sizes" ] == GRID_SAMPLER_2D_WORKGROUP_SIZES
52+ assert decoded ["workgroup_sizes" ] == [ 1 , 1 , 1 ]
5353 assert decoded ["shader_language" ] == GRID_SAMPLER_2D_SHADER_LANGUAGE
5454 assert base64 .b64decode (decoded ["shader_code" ])[:4 ] == b"\x03 \x02 \x23 \x07 "
5555 assert decoded ["input_0_type" ] == "Tensor"
@@ -58,7 +58,7 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_round_trip():
5858 assert decoded ["input_0_binding" ] == 0
5959 assert decoded ["input_1_type" ] == "Tensor"
6060 assert decoded ["input_1_vkformat" ] == GRID_SAMPLER_2D_VK_FORMAT
61- assert decoded ["input_1_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER "
61+ assert decoded ["input_1_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_TENSOR_ARM "
6262 assert decoded ["input_1_binding" ] == 1
6363 assert decoded ["output_0_type" ] == "Tensor"
6464 assert decoded ["output_0_vkformat" ] == GRID_SAMPLER_2D_VK_FORMAT
@@ -72,10 +72,12 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_uses_sampler_for_c4():
7272 padding_mode = 0 ,
7373 align_corners = False ,
7474 input_shape = (1 , 4 , 8 , 8 ),
75+ output_shape = (1 , 4 , 4 , 4 ),
7576 input_dtype = torch .float32 ,
7677 )
7778
7879 assert payload ["shader_language" ] == GRID_SAMPLER_2D_SHADER_LANGUAGE
80+ assert payload ["workgroup_sizes" ] == [1 , 1 , 1 ]
7981 assert base64 .b64decode (payload ["shader_code" ])[:4 ] == b"\x03 \x02 \x23 \x07 "
8082 assert payload ["input_0_type" ] == "Image"
8183 assert payload ["input_0_vkformat" ] == GRID_SAMPLER_2D_SAMPLER_VK_FORMAT
@@ -104,11 +106,13 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_uses_int8_sampler_for_c
104106 padding_mode = 0 ,
105107 align_corners = False ,
106108 input_shape = (1 , 4 , 8 , 8 ),
109+ output_shape = (1 , 4 , 4 , 4 ),
107110 input_dtype = torch .int8 ,
108111 output_dtype = torch .int8 ,
109112 )
110113
111114 assert payload ["shader_language" ] == GRID_SAMPLER_2D_SHADER_LANGUAGE
115+ assert payload ["workgroup_sizes" ] == [1 , 1 , 1 ]
112116 assert base64 .b64decode (payload ["shader_code" ])[:4 ] == b"\x03 \x02 \x23 \x07 "
113117 assert payload ["input_0_type" ] == "Image"
114118 assert payload ["input_0_vkformat" ] == GRID_SAMPLER_2D_SAMPLER_INT8_VK_FORMAT
@@ -130,23 +134,58 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_keeps_c3_on_buffer():
130134 padding_mode = 0 ,
131135 align_corners = False ,
132136 input_shape = (1 , 3 , 8 , 8 ),
137+ output_shape = (1 , 3 , 4 , 4 ),
133138 input_dtype = torch .float32 ,
134139 )
135140
136141 assert payload ["shader_language" ] == GRID_SAMPLER_2D_SHADER_LANGUAGE
142+ assert payload ["workgroup_sizes" ] == [1 , 1 , 1 ]
137143 assert payload ["input_0_type" ] == "Tensor"
138144 assert payload ["input_0_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER"
145+ assert payload ["input_1_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_TENSOR_ARM"
139146 assert payload ["output_0_type" ] == "Tensor"
140147 assert payload ["output_0_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER"
141148 assert "input_0_sampler" not in payload
142149
143150
151+ def test_grid_sampler_2d_custom_shader_payload_sampler_dispatch_rounds_up_output ():
152+ payload = build_grid_sampler_2d_payload (
153+ interpolation_mode = 0 ,
154+ padding_mode = 0 ,
155+ align_corners = False ,
156+ input_shape = (1 , 4 , 32 , 32 ),
157+ output_shape = (1 , 4 , 17 , 9 ),
158+ input_dtype = torch .float32 ,
159+ )
160+
161+ assert payload ["input_0_type" ] == "Image"
162+ assert payload ["output_0_type" ] == "Image"
163+ assert payload ["workgroup_sizes" ] == [2 , 3 , 1 ]
164+
165+
166+ def test_grid_sampler_2d_custom_shader_payload_buffer_dispatch_rounds_up_output ():
167+ payload = build_grid_sampler_2d_payload (
168+ interpolation_mode = 2 ,
169+ padding_mode = 0 ,
170+ align_corners = False ,
171+ input_shape = (1 , 4 , 32 , 32 ),
172+ output_shape = (1 , 4 , 17 , 9 ),
173+ input_dtype = torch .float32 ,
174+ )
175+
176+ assert payload ["input_0_type" ] == "Tensor"
177+ assert payload ["input_1_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_TENSOR_ARM"
178+ assert payload ["output_0_type" ] == "Tensor"
179+ assert payload ["workgroup_sizes" ] == [2 , 3 , 1 ]
180+
181+
144182def test_grid_sampler_2d_custom_shader_payload_no_target_align_corners_sampler ():
145183 payload = build_grid_sampler_2d_payload (
146184 interpolation_mode = 0 ,
147185 padding_mode = 0 ,
148186 align_corners = True ,
149187 input_shape = (1 , 4 , 8 , 8 ),
188+ output_shape = (1 , 4 , 8 , 8 ),
150189 input_dtype = torch .float32 ,
151190 )
152191
@@ -170,6 +209,7 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_int8_align_corners_samp
170209 padding_mode = 0 ,
171210 align_corners = True ,
172211 input_shape = (1 , 4 , 8 , 8 ),
212+ output_shape = (1 , 4 , 8 , 8 ),
173213 input_dtype = torch .int8 ,
174214 output_dtype = torch .int8 ,
175215 )
@@ -194,13 +234,15 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_bicubic_buffer():
194234 padding_mode = 0 ,
195235 align_corners = False ,
196236 input_shape = (1 , 4 , 8 , 8 ),
237+ output_shape = (1 , 4 , 8 , 8 ),
197238 input_dtype = torch .float32 ,
198239 )
199240
200241 assert payload ["input_0_type" ] == "Tensor"
201242 assert payload ["input_0_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER"
202243 assert payload ["output_0_type" ] == "Tensor"
203244 assert payload ["output_0_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER"
245+ assert payload ["input_1_vkdescriptortype" ] == "VK_DESCRIPTOR_TYPE_TENSOR_ARM"
204246 assert "input_0_sampler" not in payload
205247
206248
@@ -209,6 +251,7 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_uses_spirv():
209251 interpolation_mode = 0 ,
210252 padding_mode = 0 ,
211253 align_corners = False ,
254+ output_shape = (1 , 4 , 8 , 8 ),
212255 )
213256
214257 shader_binary = base64 .b64decode (payload ["shader_code" ])
@@ -253,11 +296,22 @@ def test_grid_sampler_2d_custom_shader_payload_no_target_rejects_bad_modes():
253296 interpolation_mode = 99 ,
254297 padding_mode = 0 ,
255298 align_corners = False ,
299+ output_shape = (1 , 4 , 8 , 8 ),
256300 )
257301
258302 with pytest .raises (ValueError , match = "Unsupported padding_mode" ):
259303 build_grid_sampler_2d_payload (
260304 interpolation_mode = 0 ,
261305 padding_mode = 99 ,
262306 align_corners = False ,
307+ output_shape = (1 , 4 , 8 , 8 ),
308+ )
309+
310+
311+ def test_grid_sampler_2d_custom_shader_payload_requires_output_shape ():
312+ with pytest .raises (ValueError , match = "requires output_shape for dispatch" ):
313+ build_grid_sampler_2d_payload (
314+ interpolation_mode = 0 ,
315+ padding_mode = 0 ,
316+ align_corners = False ,
263317 )
0 commit comments