From fff2b9bce144820fe142e2a0c781da6c53abeb61 Mon Sep 17 00:00:00 2001 From: Ashley Hauck Date: Tue, 15 Jun 2021 09:19:40 +0200 Subject: [PATCH] Add common image type aliases (#662) --- crates/spirv-std/macros/src/lib.rs | 30 ++++++++++--------- crates/spirv-std/src/image.rs | 29 +++++++++++++++++- tests/ui/image/query/query_levels_err.stderr | 14 ++++----- tests/ui/image/query/query_lod_err.stderr | 14 ++++----- tests/ui/image/query/query_size_err.stderr | 16 +++++----- .../ui/image/query/query_size_lod_err.stderr | 14 ++++----- 6 files changed, 73 insertions(+), 44 deletions(-) diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index fa97266e0f..75f1ef3b59 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -67,10 +67,10 @@ use quote::ToTokens; /// /// The grammar for the macro is as follows: /// -/// ```no_compile +/// ```rust,no_compile /// Image!( /// , -/// , +/// , /// [sampled[=],] /// [multisampled[=],] /// [arrayed[=],] @@ -78,27 +78,29 @@ use quote::ToTokens; /// ) /// ``` /// +/// `=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`. /// diff --git a/crates/spirv-std/src/image.rs b/crates/spirv-std/src/image.rs index 49ae96d5d4..4e6155c141 100644 --- a/crates/spirv-std/src/image.rs +++ b/crates/spirv-std/src/image.rs @@ -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)] diff --git a/tests/ui/image/query/query_levels_err.stderr b/tests/ui/image/query/query_levels_err.stderr index 4472efa8f8..d42b3374f7 100644 --- a/tests/ui/image/query/query_levels_err.stderr +++ b/tests/ui/image/query/query_levels_err.stderr @@ -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 diff --git a/tests/ui/image/query/query_lod_err.stderr b/tests/ui/image/query/query_lod_err.stderr index db310c8456..cee115d1bd 100644 --- a/tests/ui/image/query/query_lod_err.stderr +++ b/tests/ui/image/query/query_lod_err.stderr @@ -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 diff --git a/tests/ui/image/query/query_size_err.stderr b/tests/ui/image/query/query_size_err.stderr index 6d16ef8f57..fa2d4e8b58 100644 --- a/tests/ui/image/query/query_size_err.stderr +++ b/tests/ui/image/query/query_size_err.stderr @@ -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 diff --git a/tests/ui/image/query/query_size_lod_err.stderr b/tests/ui/image/query/query_size_lod_err.stderr index f50604a384..514e7b3fe3 100644 --- a/tests/ui/image/query/query_size_lod_err.stderr +++ b/tests/ui/image/query/query_size_lod_err.stderr @@ -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.