Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common image type aliases #662

Merged
merged 3 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions crates/spirv-std/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,40 @@ use quote::ToTokens;
///
/// The grammar for the macro is as follows:
///
/// ```no_compile
/// ```rust,no_compile
/// Image!(
/// <dimensionality>,
/// <type|format>,
/// <type=...|format=...>,
/// [sampled[=<true|false>],]
/// [multisampled[=<true|false>],]
/// [arrayed[=<true|false>],]
/// [depth[=<true|false>],]
/// )
/// ```
///
/// `=true` can be omitted as shorthand - e.g. `sampled` is short for `sampled=true`.
///
/// A basic example looks like this:
/// ```no_compile
/// ```rust,no_compile
/// #[spirv(vertex)]
/// fn main(#[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled)) {}
/// ```
///
/// ## Arguments
///
/// - `dimensionality` — Dimensionality of an image. Accepted values: `1D`,
/// `2D`, `3D`, `rect`, `cube`, `subpass`.
/// - `dimensionality` — Dimensionality of an image.
/// Accepted values: `1D`, `2D`, `3D`, `rect`, `cube`, `subpass`.
/// - `type` — The sampled type of an image, mutually exclusive with `format`,
/// when set the image format is unknown. Accepted values: `f32`, `f64`,
/// `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64`.
/// when set the image format is unknown.
/// Accepted values: `f32`, `f64`, `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64`.
/// - `format` — The image format of the image, mutually exclusive with `type`.
/// Accepted values: Camel case versions of [`ImageFormat`].
/// - `sampled` — Whether it is known that the image will be used with a sampler
/// at compile time. Accepted values: `true` or `false`. Default: `unknown`.
/// - `multisampled` — Whether the image contains multisampled content. Accepted
/// values: `true` or `false`. Default: `false`.
/// - `arrayed` — Whether the image contains arrayed content. Accepted
/// values: `true` or `false`. Default: `false`.
/// Accepted values: Snake case versions of [`ImageFormat`].
/// - `sampled` — Whether it is known that the image will be used with a sampler.
/// Accepted values: `true` or `false`. Default: `unknown`.
/// - `multisampled` — Whether the image contains multisampled content.
/// Accepted values: `true` or `false`. Default: `false`.
/// - `arrayed` — Whether the image contains arrayed content.
/// Accepted values: `true` or `false`. Default: `false`.
/// - `depth` — Whether it is known that the image is a depth image.
/// Accepted values: `true` or `false`. Default: `unknown`.
///
Expand Down
29 changes: 28 additions & 1 deletion crates/spirv-std/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,37 @@ pub mod __private {
pub use {f32, f64, i16, i32, i64, i8, u16, u32, u64, u8};
}

pub type Image1d = crate::Image!(1D, type=f32, sampled, __crate_root=crate);
pub type Image2d = crate::Image!(2D, type=f32, sampled, __crate_root=crate);
pub type Cubemap = crate::Image!(cube, type=f32, sampled, __crate_root=crate);
pub type Image3d = crate::Image!(3D, type=f32, sampled, __crate_root=crate);
pub type Image1dU = crate::Image!(1D, type=u32, sampled, __crate_root=crate);
pub type Image2dU = crate::Image!(2D, type=u32, sampled, __crate_root=crate);
pub type Image3dU = crate::Image!(3D, type=u32, sampled, __crate_root=crate);
pub type Image1dI = crate::Image!(1D, type=i32, sampled, __crate_root=crate);
pub type Image2dI = crate::Image!(2D, type=i32, sampled, __crate_root=crate);
pub type Image3dI = crate::Image!(3D, type=i32, sampled, __crate_root=crate);

pub type Image1dArray = crate::Image!(1D, type=f32, sampled, arrayed, __crate_root=crate);
pub type Image2dArray = crate::Image!(2D, type=f32, sampled, arrayed, __crate_root=crate);
pub type Image3dArray = crate::Image!(3D, type=f32, sampled, arrayed, __crate_root=crate);
pub type Image1dUArray = crate::Image!(1D, type=u32, sampled, arrayed, __crate_root=crate);
pub type Image2dUArray = crate::Image!(2D, type=u32, sampled, arrayed, __crate_root=crate);
pub type Image3dUArray = crate::Image!(3D, type=u32, sampled, arrayed, __crate_root=crate);
pub type Image1dIArray = crate::Image!(1D, type=i32, sampled, arrayed, __crate_root=crate);
pub type Image2dIArray = crate::Image!(2D, type=i32, sampled, arrayed, __crate_root=crate);
pub type Image3dIArray = crate::Image!(3D, type=i32, sampled, arrayed, __crate_root=crate);

pub type StorageImage1d = crate::Image!(1D, type=f32, sampled=false, __crate_root=crate);
pub type StorageImage2d = crate::Image!(2D, type=f32, sampled=false, __crate_root=crate);
pub type StorageImage3d = crate::Image!(3D, type=f32, sampled=false, __crate_root=crate);
pub type StorageImage1dU = crate::Image!(1D, type=u32, sampled=false, __crate_root=crate);
pub type StorageImage2dU = crate::Image!(2D, type=u32, sampled=false, __crate_root=crate);
pub type StorageImage3dU = crate::Image!(3D, type=u32, sampled=false, __crate_root=crate);
pub type StorageImage1dI = crate::Image!(1D, type=i32, sampled=false, __crate_root=crate);
pub type StorageImage2dI = crate::Image!(2D, type=i32, sampled=false, __crate_root=crate);
pub type StorageImage3dI = crate::Image!(3D, type=i32, sampled=false, __crate_root=crate);

pub type Cubemap = crate::Image!(cube, type=f32, sampled, __crate_root=crate);

/// An opaque image type. Corresponds to `OpTypeImage`.
#[spirv(generic_image_type)]
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/image/query/query_levels_err.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: OpImageQueryLevels's image has a dimension of DimRect
--> $SPIRV_STD_SRC/image.rs:733:13
--> $SPIRV_STD_SRC/image.rs:760:13
|
733 | / asm! {
734 | | "%image = OpLoad _ {this}",
735 | | "{result} = OpImageQueryLevels typeof{result} %image",
736 | | this = in(reg) self,
737 | | result = out(reg) result,
738 | | }
760 | / asm! {
761 | | "%image = OpLoad _ {this}",
762 | | "{result} = OpImageQueryLevels typeof{result} %image",
763 | | this = in(reg) self,
764 | | result = out(reg) result,
765 | | }
| |_____________^
|
= note: Allowed dimensions are 1D, 2D, 3D, and Cube
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/image/query/query_lod_err.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: OpImageQueryLod's image has a dimension of DimRect
--> $SPIRV_STD_SRC/image.rs:766:13
--> $SPIRV_STD_SRC/image.rs:793:13
|
766 | / asm! {
767 | | "%typeSampledImage = OpTypeSampledImage typeof*{this}",
768 | | "%image = OpLoad _ {this}",
769 | | "%sampler = OpLoad _ {sampler}",
793 | / asm! {
794 | | "%typeSampledImage = OpTypeSampledImage typeof*{this}",
795 | | "%image = OpLoad _ {this}",
796 | | "%sampler = OpLoad _ {sampler}",
... |
777 | | coord = in(reg) &coord
778 | | }
804 | | coord = in(reg) &coord
805 | | }
| |_____________^
|
= note: Allowed dimensions are 1D, 2D, 3D, and Cube
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/image/query/query_size_err.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: OpImageQuerySize is invalid for this image type
--> $SPIRV_STD_SRC/image.rs:795:13
--> $SPIRV_STD_SRC/image.rs:822:13
|
795 | / asm! {
796 | | "%image = OpLoad _ {this}",
797 | | "%result = OpImageQuerySize typeof*{result} %image",
798 | | "OpStore {result} %result",
799 | | this = in(reg) self,
800 | | result = in(reg) &mut result,
801 | | }
822 | / asm! {
823 | | "%image = OpLoad _ {this}",
824 | | "%result = OpImageQuerySize typeof*{result} %image",
825 | | "OpStore {result} %result",
826 | | this = in(reg) self,
827 | | result = in(reg) &mut result,
828 | | }
| |_____________^
|
= note: allowed dimensions are 1D, 2D, 3D, Buffer, Rect, or Cube. if dimension is 1D, 2D, 3D, or Cube, it must have either multisampled be true, *or* sampled of Unknown or No
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/image/query/query_size_lod_err.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: OpImageQuerySizeLod is invalid for this image type
--> $SPIRV_STD_SRC/image.rs:841:13
--> $SPIRV_STD_SRC/image.rs:868:13
|
841 | / asm! {
842 | | "%image = OpLoad _ {this}",
843 | | "%result = OpImageQuerySizeLod typeof*{result} %image {lod}",
844 | | "OpStore {result} %result",
868 | / asm! {
869 | | "%image = OpLoad _ {this}",
870 | | "%result = OpImageQuerySizeLod typeof*{result} %image {lod}",
871 | | "OpStore {result} %result",
... |
847 | | result = in(reg) &mut result,
848 | | }
874 | | result = in(reg) &mut result,
875 | | }
| |_____________^
|
= note: The image's dimension must be 1D, 2D, 3D, or Cube. Multisampled must be false.
Expand Down