@@ -14,7 +14,12 @@ pub use spirv_std_types::image_params::{
14
14
AccessQualifier , Arrayed , Dimensionality , ImageDepth , ImageFormat , Multisampled , Sampled ,
15
15
} ;
16
16
17
- use crate :: { float:: Float , integer:: Integer , vector:: Vector , Sampler } ;
17
+ use crate :: {
18
+ float:: Float ,
19
+ integer:: Integer ,
20
+ vector:: { Vector , VectorTypeRef } ,
21
+ Sampler ,
22
+ } ;
18
23
19
24
/// Re-export of primitive types to ensure the `Image` proc macro always points
20
25
/// to the right type.
@@ -119,12 +124,16 @@ impl<
119
124
/// Fetch a single texel with a sampler set at compile time
120
125
#[ crate :: macros:: gpu_only]
121
126
#[ doc( alias = "OpImageFetch" ) ]
122
- pub fn fetch < V , I > ( & self , coordinate : impl ImageCoordinate < I , DIM , ARRAYED > ) -> V
127
+ pub fn fetch < I , C , const N : usize > (
128
+ & self ,
129
+ coordinate : C ,
130
+ ) -> <<C >:: VectorTypeLib as VectorTypeRef < SampledType , 4 > >:: Vector
123
131
where
124
- V : Vector < SampledType , 4 > ,
125
132
I : Integer ,
133
+ C : ImageCoordinate < I , DIM , ARRAYED > + Vector < I , N > ,
134
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
126
135
{
127
- let mut result = V :: default ( ) ;
136
+ let mut result = Default :: default ( ) ;
128
137
unsafe {
129
138
asm ! {
130
139
"%image = OpLoad _ {this}" ,
@@ -154,18 +163,19 @@ impl<
154
163
#[ crate :: macros:: gpu_only]
155
164
#[ doc( alias = "OpImageGather" ) ]
156
165
#[ inline]
157
- pub fn gather < F , V > (
166
+ pub fn gather < F , C , const N : usize > (
158
167
& self ,
159
168
sampler : Sampler ,
160
- coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
169
+ coordinate : C ,
161
170
component : u32 ,
162
- ) -> V
171
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
163
172
where
164
173
Self : HasGather ,
165
174
F : Float ,
166
- V : Vector < SampledType , 4 > ,
175
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
176
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
167
177
{
168
- let mut result = V :: default ( ) ;
178
+ let mut result = Default :: default ( ) ;
169
179
unsafe {
170
180
asm ! {
171
181
"%typeSampledImage = OpTypeSampledImage typeof*{this}" ,
@@ -187,10 +197,15 @@ impl<
187
197
188
198
/// Sample texels at `coord` from the image using `sampler`.
189
199
#[ crate :: macros:: gpu_only]
190
- pub fn sample < F , V > ( & self , sampler : Sampler , coord : impl ImageCoordinate < F , DIM , ARRAYED > ) -> V
200
+ pub fn sample < F , C , const N : usize > (
201
+ & self ,
202
+ sampler : Sampler ,
203
+ coord : C ,
204
+ ) -> <C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > >:: Vector
191
205
where
192
206
F : Float ,
193
- V : Vector < SampledType , 4 > ,
207
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
208
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
194
209
{
195
210
unsafe {
196
211
let mut result = Default :: default ( ) ;
@@ -214,15 +229,16 @@ impl<
214
229
/// Sample texels at `coord` from the image using `sampler`, after adding the input bias to the
215
230
/// implicit level of detail.
216
231
#[ crate :: macros:: gpu_only]
217
- pub fn sample_bias < F , V > (
232
+ pub fn sample_bias < F , C , const N : usize > (
218
233
& self ,
219
234
sampler : Sampler ,
220
- coord : impl ImageCoordinate < F , DIM , ARRAYED > ,
235
+ coord : C ,
221
236
bias : f32 ,
222
- ) -> V
237
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
223
238
where
224
239
F : Float ,
225
- V : Vector < SampledType , 4 > ,
240
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
241
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
226
242
{
227
243
unsafe {
228
244
let mut result = Default :: default ( ) ;
@@ -248,15 +264,16 @@ impl<
248
264
#[ crate :: macros:: gpu_only]
249
265
#[ doc( alias = "OpImageSampleExplicitLod" ) ]
250
266
/// Sample the image at a coordinate by a lod
251
- pub fn sample_by_lod < F , V > (
267
+ pub fn sample_by_lod < F , C , const N : usize > (
252
268
& self ,
253
269
sampler : Sampler ,
254
- coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
270
+ coordinate : C ,
255
271
lod : f32 ,
256
- ) -> V
272
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
257
273
where
258
274
F : Float ,
259
- V : Vector < SampledType , 4 > ,
275
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
276
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
260
277
{
261
278
let mut result = Default :: default ( ) ;
262
279
unsafe {
@@ -281,16 +298,17 @@ impl<
281
298
#[ crate :: macros:: gpu_only]
282
299
#[ doc( alias = "OpImageSampleExplicitLod" ) ]
283
300
/// Sample the image based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy])
284
- pub fn sample_by_gradient < F , V > (
301
+ pub fn sample_by_gradient < F , C , const N : usize > (
285
302
& self ,
286
303
sampler : Sampler ,
287
- coordinate : impl ImageCoordinate < F , DIM , ARRAYED > ,
304
+ coordinate : C ,
288
305
gradient_dx : impl ImageCoordinate < F , DIM , { Arrayed :: False as u32 } > ,
289
306
gradient_dy : impl ImageCoordinate < F , DIM , { Arrayed :: False as u32 } > ,
290
- ) -> V
307
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
291
308
where
292
309
F : Float ,
293
- V : Vector < SampledType , 4 > ,
310
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
311
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
294
312
{
295
313
let mut result = Default :: default ( ) ;
296
314
unsafe {
@@ -441,14 +459,15 @@ impl<
441
459
/// Sample the image with a project coordinate
442
460
#[ crate :: macros:: gpu_only]
443
461
#[ doc( alias = "OpImageSampleProjImplicitLod" ) ]
444
- pub fn sample_with_project_coordinate < F , V > (
462
+ pub fn sample_with_project_coordinate < F , C , const N : usize > (
445
463
& self ,
446
464
sampler : Sampler ,
447
- project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
448
- ) -> V
465
+ project_coordinate : C ,
466
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
449
467
where
450
468
F : Float ,
451
- V : Vector < SampledType , 4 > ,
469
+ C : ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > + Vector < F , N > ,
470
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
452
471
{
453
472
unsafe {
454
473
let mut result = Default :: default ( ) ;
@@ -471,15 +490,16 @@ impl<
471
490
#[ crate :: macros:: gpu_only]
472
491
#[ doc( alias = "OpImageSampleProjExplicitLod" ) ]
473
492
/// Sample the image with a project coordinate by a lod
474
- pub fn sample_with_project_coordinate_by_lod < F , V > (
493
+ pub fn sample_with_project_coordinate_by_lod < F , C , const N : usize > (
475
494
& self ,
476
495
sampler : Sampler ,
477
- project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
496
+ project_coordinate : C ,
478
497
lod : f32 ,
479
- ) -> V
498
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
480
499
where
481
500
F : Float ,
482
- V : Vector < SampledType , 4 > ,
501
+ C : ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > + Vector < F , N > ,
502
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
483
503
{
484
504
let mut result = Default :: default ( ) ;
485
505
unsafe {
@@ -504,16 +524,17 @@ impl<
504
524
#[ crate :: macros:: gpu_only]
505
525
#[ doc( alias = "OpImageSampleProjExplicitLod" ) ]
506
526
/// Sample the image with a project coordinate based on a gradient formed by (dx, dy). Specifically, ([du/dx, dv/dx], [du/dy, dv/dy])
507
- pub fn sample_with_project_coordinate_by_gradient < F , V > (
527
+ pub fn sample_with_project_coordinate_by_gradient < F , C , const N : usize > (
508
528
& self ,
509
529
sampler : Sampler ,
510
- project_coordinate : impl ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > ,
530
+ project_coordinate : C ,
511
531
gradient_dx : impl ImageCoordinate < F , DIM , { Arrayed :: False as u32 } > ,
512
532
gradient_dy : impl ImageCoordinate < F , DIM , { Arrayed :: False as u32 } > ,
513
- ) -> V
533
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
514
534
where
515
535
F : Float ,
516
- V : Vector < SampledType , 4 > ,
536
+ C : ImageCoordinate < F , DIM , { Arrayed :: True as u32 } > + Vector < F , N > ,
537
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
517
538
{
518
539
let mut result = Default :: default ( ) ;
519
540
unsafe {
@@ -656,12 +677,16 @@ impl<
656
677
/// Read a texel from an image without a sampler.
657
678
#[ crate :: macros:: gpu_only]
658
679
#[ doc( alias = "OpImageRead" ) ]
659
- pub fn read < I , V , const N : usize > ( & self , coordinate : impl ImageCoordinate < I , DIM , ARRAYED > ) -> V
680
+ pub fn read < I , C , const N : usize > (
681
+ & self ,
682
+ coordinate : C ,
683
+ ) -> <C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > >:: Vector
660
684
where
661
685
I : Integer ,
662
- V : Vector < SampledType , N > ,
686
+ C : ImageCoordinate < I , DIM , ARRAYED > + Vector < I , N > ,
687
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
663
688
{
664
- let mut result = V :: default ( ) ;
689
+ let mut result = Default :: default ( ) ;
665
690
666
691
unsafe {
667
692
asm ! {
@@ -712,12 +737,16 @@ impl<
712
737
/// Read a texel from an image without a sampler.
713
738
#[ crate :: macros:: gpu_only]
714
739
#[ doc( alias = "OpImageRead" ) ]
715
- pub fn read < I , V , const N : usize > ( & self , coordinate : impl ImageCoordinate < I , DIM , ARRAYED > ) -> V
740
+ pub fn read < I , C , const N : usize > (
741
+ & self ,
742
+ coordinate : C ,
743
+ ) -> <C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > >:: Vector
716
744
where
717
745
I : Integer ,
718
- V : Vector < SampledType , N > ,
746
+ C : ImageCoordinate < I , DIM , ARRAYED > + Vector < I , N > ,
747
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
719
748
{
720
- let mut result = V :: default ( ) ;
749
+ let mut result = Default :: default ( ) ;
721
750
722
751
unsafe {
723
752
asm ! {
@@ -777,15 +806,16 @@ impl<
777
806
/// Note: Vulkan only allows the read if the first two components of the coordinate are zero.
778
807
#[ crate :: macros:: gpu_only]
779
808
#[ doc( alias = "OpImageRead" ) ]
780
- pub fn read_subpass < I , V , const N : usize > (
809
+ pub fn read_subpass < I , C , const N : usize > (
781
810
& self ,
782
- coordinate : impl ImageCoordinateSubpassData < I , ARRAYED > ,
783
- ) -> V
811
+ coordinate : C ,
812
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
784
813
where
785
814
I : Integer ,
786
- V : Vector < SampledType , N > ,
815
+ C : ImageCoordinateSubpassData < I , ARRAYED > + Vector < I , N > ,
816
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
787
817
{
788
- let mut result = V :: default ( ) ;
818
+ let mut result = Default :: default ( ) ;
789
819
790
820
unsafe {
791
821
asm ! {
@@ -838,13 +868,15 @@ impl<
838
868
/// detail relative to the base level.
839
869
#[ crate :: macros:: gpu_only]
840
870
#[ doc( alias = "OpImageQueryLod" ) ]
841
- pub fn query_lod < V : Vector < f32 , 2 > > (
871
+ pub fn query_lod < C , const N : usize > (
842
872
& self ,
843
873
sampler : Sampler ,
844
- coord : impl ImageCoordinate < f32 , DIM , { Arrayed :: False as u32 } > ,
845
- ) -> V
874
+ coord : C ,
875
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 2 > > :: Vector
846
876
where
847
877
Self : HasQueryLevels ,
878
+ C : ImageCoordinate < f32 , DIM , { Arrayed :: False as u32 } > + Vector < f32 , N > ,
879
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 2 > ,
848
880
{
849
881
// Note: Arrayed::False isn't a typo in the ImageCoordinate, the spec states:
850
882
// Coordinate must be a scalar or vector of floating-point type or integer type. It
@@ -988,10 +1020,14 @@ impl<
988
1020
/// Sampling with a type (`S`) that doesn't match the image's image format
989
1021
/// will result in undefined behaviour.
990
1022
#[ crate :: macros:: gpu_only]
991
- pub unsafe fn sample < F , V > ( & self , coord : impl ImageCoordinate < F , DIM , ARRAYED > ) -> V
1023
+ pub unsafe fn sample < F , C , const N : usize > (
1024
+ & self ,
1025
+ coord : C ,
1026
+ ) -> <C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > >:: Vector
992
1027
where
993
1028
F : Float ,
994
- V : Vector < SampledType , 4 > ,
1029
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
1030
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
995
1031
{
996
1032
let mut result = Default :: default ( ) ;
997
1033
asm ! (
@@ -1012,14 +1048,15 @@ impl<
1012
1048
/// Sampling with a type (`S`) that doesn't match the image's image format
1013
1049
/// will result in undefined behaviour.
1014
1050
#[ crate :: macros:: gpu_only]
1015
- pub unsafe fn sample_by_lod < F , V > (
1051
+ pub unsafe fn sample_by_lod < F , C , const N : usize > (
1016
1052
& self ,
1017
- coord : impl ImageCoordinate < F , DIM , ARRAYED > ,
1053
+ coord : C ,
1018
1054
lod : f32 ,
1019
- ) -> V
1055
+ ) -> < C :: VectorTypeLib as VectorTypeRef < SampledType , 4 > > :: Vector
1020
1056
where
1021
1057
F : Float ,
1022
- V : Vector < SampledType , 4 > ,
1058
+ C : ImageCoordinate < F , DIM , ARRAYED > + Vector < F , N > ,
1059
+ C :: VectorTypeLib : VectorTypeRef < SampledType , 4 > ,
1023
1060
{
1024
1061
let mut result = Default :: default ( ) ;
1025
1062
asm ! (
0 commit comments