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

Implement Unorm10_10_10_2 VertexFormat #5477

Merged
merged 9 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Bottom level categories:

#### General

- Implemented the `Unorm10_10_10_2` VertexFormat.
- Many numeric built-ins have had a constant evaluation implementation added for them, which allows them to be used in a `const` context:
- [#4879](https://github.com/gfx-rs/wgpu/pull/4879) by @ErichDonGubler:
- `abs`
Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6391,6 +6391,7 @@ webidl.converters["GPUVertexFormat"] = webidl.createEnumConverter(
"sint32x2",
"sint32x3",
"sint32x4",
"unorm10-10-10-2",
],
);

Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/webgpu.idl
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ enum GPUVertexFormat {
"sint32x2",
"sint32x3",
"sint32x4",
"unorm10-10-10-2",
};

enum GPUVertexStepMode {
Expand Down
3 changes: 2 additions & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ impl NumericType {
| Vf::Unorm16x4
| Vf::Snorm16x4
| Vf::Float16x4
| Vf::Float32x4 => (NumericDimension::Vector(Vs::Quad), Scalar::F32),
| Vf::Float32x4
| Vf::Unorm10_10_10_2 => (NumericDimension::Vector(Vs::Quad), Scalar::F32),
Vf::Float64 => (NumericDimension::Scalar, Scalar::F64),
Vf::Float64x2 => (NumericDimension::Vector(Vs::Bi), Scalar::F64),
Vf::Float64x3 => (NumericDimension::Vector(Vs::Tri), Scalar::F64),
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/auxil/dxgi/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ pub fn map_vertex_format(format: wgt::VertexFormat) -> dxgiformat::DXGI_FORMAT {
Vf::Uint32x4 => DXGI_FORMAT_R32G32B32A32_UINT,
Vf::Sint32x4 => DXGI_FORMAT_R32G32B32A32_SINT,
Vf::Float32x4 => DXGI_FORMAT_R32G32B32A32_FLOAT,
Vf::Unorm10_10_10_2 => DXGI_FORMAT_R10G10B10A2_UNORM,
Vf::Float64 | Vf::Float64x2 | Vf::Float64x3 | Vf::Float64x4 => unimplemented!(),
}
}
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub(super) fn describe_vertex_format(vertex_format: wgt::VertexFormat) -> super:
Vf::Uint32x4 => (4, glow::UNSIGNED_INT, Vak::Integer),
Vf::Sint32x4 => (4, glow::INT, Vak::Integer),
Vf::Float32x4 => (4, glow::FLOAT, Vak::Float),
Vf::Unorm10_10_10_2 => (4, glow::UNSIGNED_INT_10_10_10_2, Vak::Float),
Vf::Float64 | Vf::Float64x2 | Vf::Float64x3 | Vf::Float64x4 => unimplemented!(),
};

Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub fn map_vertex_format(format: wgt::VertexFormat) -> metal::MTLVertexFormat {
Vf::Uint32x4 => UInt4,
Vf::Sint32x4 => Int4,
Vf::Float32x4 => Float4,
Vf::Unorm10_10_10_2 => UInt1010102Normalized,
Vf::Float64 | Vf::Float64x2 | Vf::Float64x3 | Vf::Float64x4 => unimplemented!(),
}
}
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/vulkan/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ pub fn map_vertex_format(vertex_format: wgt::VertexFormat) -> vk::Format {
Vf::Float64x2 => vk::Format::R64G64_SFLOAT,
Vf::Float64x3 => vk::Format::R64G64B64_SFLOAT,
Vf::Float64x4 => vk::Format::R64G64B64A64_SFLOAT,
Vf::Unorm10_10_10_2 => vk::Format::A2B10G10R10_UNORM_PACK32,
}
}

Expand Down
5 changes: 4 additions & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4942,6 +4942,8 @@ pub enum VertexFormat {
Float64x3 = 32,
/// Four double-precision floats (f64). `vec4<f32>` in shaders. Requires [`Features::VERTEX_ATTRIBUTE_64BIT`].
Float64x4 = 33,
/// Three unsigned 10-bit integers and one 2-bit integer, packed into a 32-bit integer (u32). [0, 1024] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm10_10_10_2 = 34,
McMackety marked this conversation as resolved.
Show resolved Hide resolved
}

impl VertexFormat {
Expand All @@ -4960,7 +4962,8 @@ impl VertexFormat {
| Self::Float16x2
| Self::Float32
| Self::Uint32
| Self::Sint32 => 4,
| Self::Sint32
| Self::Unorm10_10_10_2 => 4,
Self::Uint16x4
| Self::Sint16x4
| Self::Unorm16x4
Expand Down
8 changes: 7 additions & 1 deletion wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ fn map_stencil_state_face(desc: &wgt::StencilFaceState) -> webgpu_sys::GpuStenci
mapped
}


McMackety marked this conversation as resolved.
Show resolved Hide resolved
fn map_depth_stencil_state(desc: &wgt::DepthStencilState) -> webgpu_sys::GpuDepthStencilState {
let mut mapped = webgpu_sys::GpuDepthStencilState::new(map_texture_format(desc.format));
mapped.depth_compare(map_compare_function(desc.depth_compare));
Expand Down Expand Up @@ -480,6 +481,7 @@ fn map_vertex_format(format: wgt::VertexFormat) -> webgpu_sys::GpuVertexFormat {
VertexFormat::Sint32x2 => vf::Sint32x2,
VertexFormat::Sint32x3 => vf::Sint32x3,
VertexFormat::Sint32x4 => vf::Sint32x4,
VertexFormat::Unorm10_10_10_2 => vf::Unorm1010102,
VertexFormat::Float64
| VertexFormat::Float64x2
| VertexFormat::Float64x3
Expand Down Expand Up @@ -1695,6 +1697,7 @@ impl crate::context::Context for ContextWebGpu {
) -> (Self::RenderPipelineId, Self::RenderPipelineData) {
let module: &<ContextWebGpu as crate::Context>::ShaderModuleData =
downcast_ref(desc.vertex.module.data.as_ref());

let mut mapped_vertex_state = webgpu_sys::GpuVertexState::new(&module.0);
mapped_vertex_state.entry_point(desc.vertex.entry_point);

Expand Down Expand Up @@ -1770,7 +1773,9 @@ impl crate::context::Context for ContextWebGpu {
.collect::<js_sys::Array>();
let module: &<ContextWebGpu as crate::Context>::ShaderModuleData =
downcast_ref(frag.module.data.as_ref());

let mut mapped_fragment_desc = webgpu_sys::GpuFragmentState::new(&module.0, &targets);

mapped_fragment_desc.entry_point(frag.entry_point);
mapped_desc.fragment(&mapped_fragment_desc);
}
Expand All @@ -1795,10 +1800,12 @@ impl crate::context::Context for ContextWebGpu {
) -> (Self::ComputePipelineId, Self::ComputePipelineData) {
let shader_module: &<ContextWebGpu as crate::Context>::ShaderModuleData =
downcast_ref(desc.module.data.as_ref());

let mut mapped_compute_stage = webgpu_sys::GpuProgrammableStage::new(&shader_module.0);
mapped_compute_stage.entry_point(desc.entry_point);
let auto_layout = wasm_bindgen::JsValue::from(webgpu_sys::GpuAutoLayoutMode::Auto);
let mut mapped_desc = webgpu_sys::GpuComputePipelineDescriptor::new(

&match desc.layout {
Some(layout) => {
let layout: &<ContextWebGpu as crate::Context>::PipelineLayoutData =
Expand Down Expand Up @@ -2517,7 +2524,6 @@ impl crate::context::Context for ContextWebGpu {
// Not available in gecko yet
// encoder.pop_debug_group();
}

fn command_encoder_write_timestamp(
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
&self,
_encoder: &Self::CommandEncoderId,
Expand Down
Loading