Skip to content

Commit fd4da16

Browse files
committed
Removed return type inference from Image API
Return types are now always `glam` vectors. This also means that `glam` is required. The "glam" feature toggle is made mandatory, we may want to support other specific vector libraries in the future.
1 parent 547309a commit fd4da16

File tree

11 files changed

+149
-119
lines changed

11 files changed

+149
-119
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
2828
-->
2929

30+
## [Unreleased]
31+
32+
### Changed 🛠
33+
- [PR#990](https://github.com/EmbarkStudios/rust-gpu/pull/990) Removed return type inference from `Image` API and made `glam` usage mandatory.
34+
3035
## [0.5.0]
3136

3237
### Added ⭐

crates/spirv-std/src/image.rs

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,11 @@ impl<
119119
/// Fetch a single texel with a sampler set at compile time
120120
#[crate::macros::gpu_only]
121121
#[doc(alias = "OpImageFetch")]
122-
pub fn fetch<V, I>(&self, coordinate: impl ImageCoordinate<I, DIM, ARRAYED>) -> V
122+
pub fn fetch<I>(&self, coordinate: impl ImageCoordinate<I, DIM, ARRAYED>) -> SampledType::Vec4
123123
where
124-
V: Vector<SampledType, 4>,
125124
I: Integer,
126125
{
127-
let mut result = V::default();
126+
let mut result = Default::default();
128127
unsafe {
129128
asm! {
130129
"%image = OpLoad _ {this}",
@@ -154,18 +153,17 @@ impl<
154153
#[crate::macros::gpu_only]
155154
#[doc(alias = "OpImageGather")]
156155
#[inline]
157-
pub fn gather<F, V>(
156+
pub fn gather<F>(
158157
&self,
159158
sampler: Sampler,
160159
coordinate: impl ImageCoordinate<F, DIM, ARRAYED>,
161160
component: u32,
162-
) -> V
161+
) -> SampledType::Vec4
163162
where
164163
Self: HasGather,
165164
F: Float,
166-
V: Vector<SampledType, 4>,
167165
{
168-
let mut result = V::default();
166+
let mut result = Default::default();
169167
unsafe {
170168
asm! {
171169
"%typeSampledImage = OpTypeSampledImage typeof*{this}",
@@ -187,10 +185,13 @@ impl<
187185

188186
/// Sample texels at `coord` from the image using `sampler`.
189187
#[crate::macros::gpu_only]
190-
pub fn sample<F, V>(&self, sampler: Sampler, coord: impl ImageCoordinate<F, DIM, ARRAYED>) -> V
188+
pub fn sample<F>(
189+
&self,
190+
sampler: Sampler,
191+
coord: impl ImageCoordinate<F, DIM, ARRAYED>,
192+
) -> SampledType::Vec4
191193
where
192194
F: Float,
193-
V: Vector<SampledType, 4>,
194195
{
195196
unsafe {
196197
let mut result = Default::default();
@@ -214,15 +215,14 @@ impl<
214215
/// Sample texels at `coord` from the image using `sampler`, after adding the input bias to the
215216
/// implicit level of detail.
216217
#[crate::macros::gpu_only]
217-
pub fn sample_bias<F, V>(
218+
pub fn sample_bias<F>(
218219
&self,
219220
sampler: Sampler,
220221
coord: impl ImageCoordinate<F, DIM, ARRAYED>,
221222
bias: f32,
222-
) -> V
223+
) -> SampledType::Vec4
223224
where
224225
F: Float,
225-
V: Vector<SampledType, 4>,
226226
{
227227
unsafe {
228228
let mut result = Default::default();
@@ -248,15 +248,14 @@ impl<
248248
#[crate::macros::gpu_only]
249249
#[doc(alias = "OpImageSampleExplicitLod")]
250250
/// Sample the image at a coordinate by a lod
251-
pub fn sample_by_lod<F, V>(
251+
pub fn sample_by_lod<F>(
252252
&self,
253253
sampler: Sampler,
254254
coordinate: impl ImageCoordinate<F, DIM, ARRAYED>,
255255
lod: f32,
256-
) -> V
256+
) -> SampledType::Vec4
257257
where
258258
F: Float,
259-
V: Vector<SampledType, 4>,
260259
{
261260
let mut result = Default::default();
262261
unsafe {
@@ -281,16 +280,15 @@ impl<
281280
#[crate::macros::gpu_only]
282281
#[doc(alias = "OpImageSampleExplicitLod")]
283282
/// 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>(
283+
pub fn sample_by_gradient<F>(
285284
&self,
286285
sampler: Sampler,
287286
coordinate: impl ImageCoordinate<F, DIM, ARRAYED>,
288287
gradient_dx: impl ImageCoordinate<F, DIM, { Arrayed::False as u32 }>,
289288
gradient_dy: impl ImageCoordinate<F, DIM, { Arrayed::False as u32 }>,
290-
) -> V
289+
) -> SampledType::Vec4
291290
where
292291
F: Float,
293-
V: Vector<SampledType, 4>,
294292
{
295293
let mut result = Default::default();
296294
unsafe {
@@ -441,14 +439,13 @@ impl<
441439
/// Sample the image with a project coordinate
442440
#[crate::macros::gpu_only]
443441
#[doc(alias = "OpImageSampleProjImplicitLod")]
444-
pub fn sample_with_project_coordinate<F, V>(
442+
pub fn sample_with_project_coordinate<F>(
445443
&self,
446444
sampler: Sampler,
447445
project_coordinate: impl ImageCoordinate<F, DIM, { Arrayed::True as u32 }>,
448-
) -> V
446+
) -> SampledType::Vec4
449447
where
450448
F: Float,
451-
V: Vector<SampledType, 4>,
452449
{
453450
unsafe {
454451
let mut result = Default::default();
@@ -471,15 +468,14 @@ impl<
471468
#[crate::macros::gpu_only]
472469
#[doc(alias = "OpImageSampleProjExplicitLod")]
473470
/// Sample the image with a project coordinate by a lod
474-
pub fn sample_with_project_coordinate_by_lod<F, V>(
471+
pub fn sample_with_project_coordinate_by_lod<F>(
475472
&self,
476473
sampler: Sampler,
477474
project_coordinate: impl ImageCoordinate<F, DIM, { Arrayed::True as u32 }>,
478475
lod: f32,
479-
) -> V
476+
) -> SampledType::Vec4
480477
where
481478
F: Float,
482-
V: Vector<SampledType, 4>,
483479
{
484480
let mut result = Default::default();
485481
unsafe {
@@ -504,16 +500,15 @@ impl<
504500
#[crate::macros::gpu_only]
505501
#[doc(alias = "OpImageSampleProjExplicitLod")]
506502
/// 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>(
503+
pub fn sample_with_project_coordinate_by_gradient<F>(
508504
&self,
509505
sampler: Sampler,
510506
project_coordinate: impl ImageCoordinate<F, DIM, { Arrayed::True as u32 }>,
511507
gradient_dx: impl ImageCoordinate<F, DIM, { Arrayed::False as u32 }>,
512508
gradient_dy: impl ImageCoordinate<F, DIM, { Arrayed::False as u32 }>,
513-
) -> V
509+
) -> SampledType::Vec4
514510
where
515511
F: Float,
516-
V: Vector<SampledType, 4>,
517512
{
518513
let mut result = Default::default();
519514
unsafe {
@@ -656,12 +651,11 @@ impl<
656651
/// Read a texel from an image without a sampler.
657652
#[crate::macros::gpu_only]
658653
#[doc(alias = "OpImageRead")]
659-
pub fn read<I, V, const N: usize>(&self, coordinate: impl ImageCoordinate<I, DIM, ARRAYED>) -> V
654+
pub fn read<I>(&self, coordinate: impl ImageCoordinate<I, DIM, ARRAYED>) -> SampledType::Vec4
660655
where
661656
I: Integer,
662-
V: Vector<SampledType, N>,
663657
{
664-
let mut result = V::default();
658+
let mut result = Default::default();
665659

666660
unsafe {
667661
asm! {
@@ -712,12 +706,11 @@ impl<
712706
/// Read a texel from an image without a sampler.
713707
#[crate::macros::gpu_only]
714708
#[doc(alias = "OpImageRead")]
715-
pub fn read<I, V, const N: usize>(&self, coordinate: impl ImageCoordinate<I, DIM, ARRAYED>) -> V
709+
pub fn read<I>(&self, coordinate: impl ImageCoordinate<I, DIM, ARRAYED>) -> SampledType::Vec4
716710
where
717711
I: Integer,
718-
V: Vector<SampledType, N>,
719712
{
720-
let mut result = V::default();
713+
let mut result = Default::default();
721714

722715
unsafe {
723716
asm! {
@@ -777,15 +770,14 @@ impl<
777770
/// Note: Vulkan only allows the read if the first two components of the coordinate are zero.
778771
#[crate::macros::gpu_only]
779772
#[doc(alias = "OpImageRead")]
780-
pub fn read_subpass<I, V, const N: usize>(
773+
pub fn read_subpass<I>(
781774
&self,
782775
coordinate: impl ImageCoordinateSubpassData<I, ARRAYED>,
783-
) -> V
776+
) -> SampledType::Vec4
784777
where
785778
I: Integer,
786-
V: Vector<SampledType, N>,
787779
{
788-
let mut result = V::default();
780+
let mut result = Default::default();
789781

790782
unsafe {
791783
asm! {
@@ -838,11 +830,11 @@ impl<
838830
/// detail relative to the base level.
839831
#[crate::macros::gpu_only]
840832
#[doc(alias = "OpImageQueryLod")]
841-
pub fn query_lod<V: Vector<f32, 2>>(
833+
pub fn query_lod(
842834
&self,
843835
sampler: Sampler,
844836
coord: impl ImageCoordinate<f32, DIM, { Arrayed::False as u32 }>,
845-
) -> V
837+
) -> SampledType::Vec2
846838
where
847839
Self: HasQueryLevels,
848840
{
@@ -988,10 +980,12 @@ impl<
988980
/// Sampling with a type (`S`) that doesn't match the image's image format
989981
/// will result in undefined behaviour.
990982
#[crate::macros::gpu_only]
991-
pub unsafe fn sample<F, V>(&self, coord: impl ImageCoordinate<F, DIM, ARRAYED>) -> V
983+
pub unsafe fn sample<F>(
984+
&self,
985+
coord: impl ImageCoordinate<F, DIM, ARRAYED>,
986+
) -> SampledType::Vec4
992987
where
993988
F: Float,
994-
V: Vector<SampledType, 4>,
995989
{
996990
let mut result = Default::default();
997991
asm!(
@@ -1012,14 +1006,13 @@ impl<
10121006
/// Sampling with a type (`S`) that doesn't match the image's image format
10131007
/// will result in undefined behaviour.
10141008
#[crate::macros::gpu_only]
1015-
pub unsafe fn sample_by_lod<F, V>(
1009+
pub unsafe fn sample_by_lod<F>(
10161010
&self,
10171011
coord: impl ImageCoordinate<F, DIM, ARRAYED>,
10181012
lod: f32,
1019-
) -> V
1013+
) -> SampledType::Vec4
10201014
where
10211015
F: Float,
1022-
V: Vector<SampledType, 4>,
10231016
{
10241017
let mut result = Default::default();
10251018
asm!(

0 commit comments

Comments
 (0)