@@ -526,5 +526,89 @@ def test_texture_return_value_str(
526526 texture_return_value_impl (device_type , texel_name , dims , channels , "texture" )
527527
528528
529+ @pytest .mark .parametrize ("device_type" , helpers .DEFAULT_DEVICE_TYPES )
530+ def test_texture_1d_broadcast (device_type : DeviceType ):
531+ if device_type == DeviceType .cuda :
532+ pytest .skip ("1D texture read returns zero on CUDA backend" )
533+ module = load_test_module (device_type )
534+
535+ # Non-square: width=8, sample at position 2
536+ tex_data = np .zeros ((8 , 1 ), dtype = np .float32 )
537+ tex_data [2 , 0 ] = 5.5 # Value at x=2
538+ tex = module .device .create_texture (
539+ type = TextureType .texture_1d ,
540+ width = 8 ,
541+ usage = TextureUsage .shader_resource | TextureUsage .unordered_access ,
542+ format = Format .r32_float ,
543+ data = tex_data ,
544+ )
545+
546+ result = module .sample_texture_1d_broadcast (tex )
547+ assert result == pytest .approx (5.5 )
548+
549+
550+ @pytest .mark .parametrize ("device_type" , helpers .DEFAULT_DEVICE_TYPES )
551+ def test_texture_2d_broadcast (device_type : DeviceType ):
552+ module = load_test_module (device_type )
553+
554+ # Non-square: width=8, height=4, sample at position (3, 1)
555+ tex_data = np .zeros ((4 , 8 , 1 ), dtype = np .float32 )
556+ tex_data [1 , 3 , 0 ] = 7.25 # Value at x=3, y=1 -> numpy[y, x, channel]
557+ tex = module .device .create_texture (
558+ type = TextureType .texture_2d ,
559+ width = 8 ,
560+ height = 4 ,
561+ usage = TextureUsage .shader_resource | TextureUsage .unordered_access ,
562+ format = Format .r32_float ,
563+ data = tex_data ,
564+ )
565+
566+ result = module .sample_texture_2d_broadcast (tex )
567+ assert result == pytest .approx (7.25 )
568+
569+
570+ @pytest .mark .parametrize ("device_type" , helpers .DEFAULT_DEVICE_TYPES )
571+ def test_texture_3d_broadcast (device_type : DeviceType ):
572+ module = load_test_module (device_type )
573+
574+ # Non-square: width=8, height=6, depth=4, sample at position (2, 1, 3)
575+ tex_data = np .zeros ((4 , 6 , 8 , 1 ), dtype = np .float32 )
576+ tex_data [3 , 1 , 2 , 0 ] = 3.14 # Value at x=2, y=1, z=3 -> numpy[z, y, x, channel]
577+ tex = module .device .create_texture (
578+ type = TextureType .texture_3d ,
579+ width = 8 ,
580+ height = 6 ,
581+ depth = 4 ,
582+ usage = TextureUsage .shader_resource | TextureUsage .unordered_access ,
583+ format = Format .r32_float ,
584+ data = tex_data ,
585+ )
586+
587+ result = module .sample_texture_3d_broadcast (tex )
588+ assert result == pytest .approx (3.14 )
589+
590+
591+ @pytest .mark .parametrize ("device_type" , helpers .DEFAULT_DEVICE_TYPES )
592+ def test_texture_3d_broadcast_with_scalar (device_type : DeviceType ):
593+ module = load_test_module (device_type )
594+
595+ # Non-square: width=8, height=6, depth=4, sample at position (2, 1, 3)
596+ tex_data = np .zeros ((4 , 6 , 8 , 1 ), dtype = np .float32 )
597+ tex_data [3 , 1 , 2 , 0 ] = 2.0 # Value at x=2, y=1, z=3 -> numpy[z, y, x, channel]
598+ tex = module .device .create_texture (
599+ type = TextureType .texture_3d ,
600+ width = 8 ,
601+ height = 6 ,
602+ depth = 4 ,
603+ usage = TextureUsage .shader_resource | TextureUsage .unordered_access ,
604+ format = Format .r32_float ,
605+ data = tex_data ,
606+ )
607+
608+ # tex[2,1,3] = 2.0, value = 3.0, so result should be 6.0
609+ result = module .sample_texture_3d_with_scalar (3.0 , tex )
610+ assert result == pytest .approx (6.0 )
611+
612+
529613if __name__ == "__main__" :
530614 pytest .main ([__file__ , "-v" , "-s" ])
0 commit comments