[remote-types] make BindGroupLayoutEntry FFI safe

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev authored and mergify[bot] committed 2026-09-17 10:18:50 +00:00
1 parent cdf689ca0c
commit 4689fa4ccb
4 files changed
+44 -62

No files matched your search

+19 -47
View File
@@ -71,6 +71,7 @@ pub struct BindGroupDescriptor<'a> {
///
/// Corresponds to [WebGPU `GPUBufferBindingLayout`](
/// https://gpuweb.github.io/gpuweb/#dictdef-gpubufferbindinglayout).
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct BufferBindingLayout {
/// Sub-type of the buffer binding.
@@ -108,6 +109,8 @@ pub struct BufferBindingLayout {
pub min_binding_size: Option<wgt::BufferSize>,
}
assert_ffi_safe!(BufferBindingLayout);
/// A sampler that can be used to sample a texture.
///
/// Example WGSL syntax:
@@ -124,12 +127,15 @@ pub struct BufferBindingLayout {
///
/// Corresponds to [WebGPU `GPUSamplerBindingLayout`](
/// https://gpuweb.github.io/gpuweb/#dictdef-gpusamplerbindinglayout).
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct SamplerBindingLayout {
/// Type of a sampler binding.
pub ty: wgt::SamplerBindingType,
}
assert_ffi_safe!(SamplerBindingLayout);
/// A texture binding.
///
/// Example WGSL syntax:
@@ -146,6 +152,7 @@ pub struct SamplerBindingLayout {
///
/// Corresponds to [WebGPU `GPUTextureBindingLayout`](
/// https://gpuweb.github.io/gpuweb/#dictdef-gputexturebindinglayout).
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct TextureBindingLayout {
/// Sample type of the texture binding.
@@ -158,6 +165,8 @@ pub struct TextureBindingLayout {
pub multisampled: bool,
}
assert_ffi_safe!(TextureBindingLayout);
/// A storage texture.
///
/// Example WGSL syntax:
@@ -176,6 +185,7 @@ pub struct TextureBindingLayout {
///
/// Corresponds to [WebGPU `GPUStorageTextureBindingLayout`](
/// https://gpuweb.github.io/gpuweb/#dictdef-gpustoragetexturebindinglayout).
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct StorageTextureBindingLayout {
/// Allowed access to this texture.
@@ -186,53 +196,13 @@ pub struct StorageTextureBindingLayout {
pub view_dimension: wgt::TextureViewDimension,
}
/// A ray-tracing acceleration structure binding.
///
/// Example WGSL syntax:
/// ```rust,ignore
/// @group(0) @binding(0)
/// var as: acceleration_structure;
/// ```
///
/// or with vertex return enabled
/// ```rust,ignore
/// @group(0) @binding(0)
/// var as: acceleration_structure<vertex_return>;
/// ```
///
/// Example GLSL syntax:
/// ```cpp,ignore
/// layout(binding = 0)
/// uniform accelerationStructureEXT as;
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct AccelerationStructureBindingLayout {
/// Whether this acceleration structure can be used to
/// create a ray query that has flag vertex return in the shader
///
/// If enabled requires [`Features::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN`]
pub vertex_return: bool,
}
/// An external texture binding.
///
/// Example WGSL syntax:
/// ```rust,ignore
/// @group(0) @binding(0)
/// var t: texture_external;
/// ```
///
/// Corresponds to [WebGPU `GPUExternalTextureBindingLayout`](
/// https://gpuweb.github.io/gpuweb/#dictdef-gpuexternaltexturebindinglayout).
///
/// Requires [`Features::EXTERNAL_TEXTURE`]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct ExternalTextureBindingLayout;
assert_ffi_safe!(StorageTextureBindingLayout);
/// Describes a single binding inside a bind group.
///
/// Corresponds to [WebGPU `GPUBindGroupLayoutEntry`](
/// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry).
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct BindGroupLayoutEntry {
/// Binding index. Must match shader index and be unique inside a `BindGroupLayout`. A binding
@@ -241,13 +211,15 @@ pub struct BindGroupLayoutEntry {
/// Which shader stages can see this binding.
pub visibility: wgt::ShaderStagesWebGPU,
// The type of the binding
pub buffer: Option<BufferBindingLayout>,
pub sampler: Option<SamplerBindingLayout>,
pub texture: Option<TextureBindingLayout>,
pub storage_texture: Option<StorageTextureBindingLayout>,
pub external_texture: Option<ExternalTextureBindingLayout>,
pub buffer: FfiOption<BufferBindingLayout>,
pub sampler: FfiOption<SamplerBindingLayout>,
pub texture: FfiOption<TextureBindingLayout>,
pub storage_texture: FfiOption<StorageTextureBindingLayout>,
pub external_texture: bool,
}
assert_ffi_safe!(BindGroupLayoutEntry);
/// Corresponds to [`GPUBindGroupLayoutDescriptor`](https://www.w3.org/TR/webgpu/#dictdef-gpubindgrouplayoutdescriptor).
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BindGroupLayoutDescriptor<'a> {
+22 -15
View File
@@ -515,7 +515,7 @@ impl Global {
ty,
has_dynamic_offset,
min_binding_size,
}) = buffer
}) = buffer.to_std()
{
binding_ty = Some(wgt::BindingType::Buffer {
ty,
@@ -523,7 +523,7 @@ impl Global {
min_binding_size,
});
}
if let Some(SamplerBindingLayout { ty }) = sampler {
if let Some(SamplerBindingLayout { ty }) = sampler.to_std() {
if binding_ty.is_some() {
return Err(binding_model::CreateBindGroupLayoutError::Entry {
binding,
@@ -536,7 +536,7 @@ impl Global {
sample_type,
view_dimension,
multisampled,
}) = texture
}) = texture.to_std()
{
if binding_ty.is_some() {
return Err(binding_model::CreateBindGroupLayoutError::Entry {
@@ -554,7 +554,7 @@ impl Global {
access,
format,
view_dimension,
}) = storage_texture
}) = storage_texture.to_std()
{
if binding_ty.is_some() {
return Err(binding_model::CreateBindGroupLayoutError::Entry {
@@ -568,7 +568,7 @@ impl Global {
view_dimension,
})
}
if let Some(ExternalTextureBindingLayout {}) = external_texture {
if external_texture {
if binding_ty.is_some() {
return Err(binding_model::CreateBindGroupLayoutError::Entry {
binding,
@@ -609,26 +609,33 @@ impl Global {
visibility,
wgt::ShaderStagesWGPU::empty(),
),
buffer: buffer.map(|b| binding_model::BufferBindingLayout {
buffer: buffer.to_std().map(|b| binding_model::BufferBindingLayout {
ty: b.ty,
has_dynamic_offset: b.has_dynamic_offset,
min_binding_size: b.min_binding_size,
}),
sampler: sampler.map(|s| binding_model::SamplerBindingLayout { ty: s.ty }),
texture: texture.map(|t| binding_model::TextureBindingLayout {
sample_type: t.sample_type,
view_dimension: t.view_dimension,
multisampled: t.multisampled,
}),
storage_texture: storage_texture.map(|s| {
sampler: sampler
.to_std()
.map(|s| binding_model::SamplerBindingLayout { ty: s.ty }),
texture: texture
.to_std()
.map(|t| binding_model::TextureBindingLayout {
sample_type: t.sample_type,
view_dimension: t.view_dimension,
multisampled: t.multisampled,
}),
storage_texture: storage_texture.to_std().map(|s| {
binding_model::StorageTextureBindingLayout {
access: s.access,
format: s.format,
view_dimension: s.view_dimension,
}
}),
external_texture: external_texture
.map(|_| binding_model::ExternalTextureBindingLayout {}),
external_texture: if external_texture {
Some(binding_model::ExternalTextureBindingLayout {})
} else {
None
},
acceleration_structure: None,
count: None,
}
+1
View File
@@ -254,6 +254,7 @@ crate::bitflags_array! {
///
/// Corresponds to [WebGPU `GPUBufferBindingType`](
/// https://gpuweb.github.io/gpuweb/#enumdef-gpubufferbindingtype).
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum BufferBindingType {
+2
View File
@@ -301,6 +301,7 @@ pub struct TextureSelector {
///
/// Corresponds to [WebGPU `GPUTextureSampleType`](
/// https://gpuweb.github.io/gpuweb/#enumdef-gputexturesampletype).
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TextureSampleType {
@@ -383,6 +384,7 @@ impl Default for TextureSampleType {
///
/// Corresponds to [WebGPU `GPUStorageTextureAccess`](
/// https://gpuweb.github.io/gpuweb/#enumdef-gpustoragetextureaccess).
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]