diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index 8276c1681..9dcb2dcc9 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -3061,6 +3061,49 @@ device.pushError(err); } + /** + * @param {GPUBuffer} destination + * @param {GPUSize64} destinationOffset + * @param {GPUSize64} size + */ + fillBuffer(destination, destinationOffset, size) { + webidl.assertBranded(this, GPUCommandEncoder); + const prefix = + "Failed to execute 'fillBuffer' on 'GPUCommandEncoder'"; + webidl.requiredArguments(arguments.length, 3, { prefix }); + destination = webidl.converters.GPUBuffer(destination, { + prefix, + context: "Argument 1", + }); + destinationOffset = webidl.converters.GPUSize64(destinationOffset, { + prefix, + context: "Argument 2", + }); + size = webidl.converters.GPUSize64(size, { + prefix, + context: "Argument 3", + }); + const device = assertDevice(this, { prefix, context: "this" }); + const commandEncoderRid = assertResource(this, { + prefix, + context: "this", + }); + const destinationRid = assertResource(destination, { + prefix, + context: "Argument 1", + }); + const { err } = core.opSync( + "op_webgpu_command_encoder_fill_buffer", + { + commandEncoderRid, + destinationRid, + destinationOffset, + size, + }, + ); + device.pushError(err); + } + /** * @param {string} groupLabel */ @@ -3204,7 +3247,7 @@ prefix, context: "Argument 3", }); - destination = webidl.converters.GPUQuerySet(destination, { + destination = webidl.converters.GPUBuffer(destination, { prefix, context: "Argument 4", }); diff --git a/deno_webgpu/02_idl_types.js b/deno_webgpu/02_idl_types.js index e1fc700bd..0dcf84903 100644 --- a/deno_webgpu/02_idl_types.js +++ b/deno_webgpu/02_idl_types.js @@ -1176,7 +1176,7 @@ defaultValue: "none", }, { - key: "clampDepth", + key: "unclippedDepth", converter: webidl.converters["boolean"], defaultValue: false, }, diff --git a/deno_webgpu/src/command_encoder.rs b/deno_webgpu/src/command_encoder.rs index bc3310a8b..466efe6ea 100644 --- a/deno_webgpu/src/command_encoder.rs +++ b/deno_webgpu/src/command_encoder.rs @@ -429,6 +429,37 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture( )) } +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CommandEncoderFillBufferArgs { + command_encoder_rid: u32, + destination_rid: u32, + destination_offset: u64, + size: u64, +} + +pub fn op_webgpu_command_encoder_fill_buffer( + state: &mut OpState, + args: CommandEncoderFillBufferArgs, + _: (), +) -> Result { + let instance = state.borrow::(); + let command_encoder_resource = state + .resource_table + .get::(args.command_encoder_rid)?; + let command_encoder = command_encoder_resource.0; + let destination_resource = state + .resource_table + .get::(args.destination_rid)?; + + gfx_ok!(command_encoder => instance.command_encoder_fill_buffer( + command_encoder, + destination_resource.0, + args.destination_offset, + std::num::NonZeroU64::new(args.size) + )) +} + #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct CommandEncoderPushDebugGroupArgs { diff --git a/deno_webgpu/src/error.rs b/deno_webgpu/src/error.rs index 9d19b4331..26d7f7b24 100644 --- a/deno_webgpu/src/error.rs +++ b/deno_webgpu/src/error.rs @@ -8,6 +8,7 @@ use wgpu_core::binding_model::CreateBindGroupError; use wgpu_core::binding_model::CreateBindGroupLayoutError; use wgpu_core::binding_model::CreatePipelineLayoutError; use wgpu_core::binding_model::GetBindGroupLayoutError; +use wgpu_core::command::ClearError; use wgpu_core::command::CommandEncoderError; use wgpu_core::command::ComputePassError; use wgpu_core::command::CopyError; @@ -255,6 +256,12 @@ impl From for WebGpuError { } } +impl From for WebGpuError { + fn from(err: ClearError) -> Self { + WebGpuError::Validation(err.to_string()) + } +} + #[derive(Debug)] pub struct DomExceptionOperationError { pub msg: String, diff --git a/deno_webgpu/src/lib.rs b/deno_webgpu/src/lib.rs index 7fb54ff90..c601e6e4c 100644 --- a/deno_webgpu/src/lib.rs +++ b/deno_webgpu/src/lib.rs @@ -246,7 +246,11 @@ pub async fn op_webgpu_request_adapter( ) -> Result { let mut state = state.borrow_mut(); check_unstable(&state, "navigator.gpu.requestAdapter"); - let backends = std::env::var("DENO_WEBGPU_BACKEND").ok().map_or_else(wgpu_types::Backends::all, |s| wgpu_core::instance::parse_backends_from_comma_list(&s)); + let backends = std::env::var("DENO_WEBGPU_BACKEND") + .ok() + .map_or_else(wgpu_types::Backends::all, |s| { + wgpu_core::instance::parse_backends_from_comma_list(&s) + }); let instance = if let Some(instance) = state.try_borrow::() { instance } else { @@ -268,9 +272,7 @@ pub async fn op_webgpu_request_adapter( }; let res = instance.request_adapter( &descriptor, - wgpu_core::instance::AdapterInputs::Mask(backends, |_| { - std::marker::PhantomData - }), + wgpu_core::instance::AdapterInputs::Mask(backends, |_| std::marker::PhantomData), ); let adapter = match res { @@ -312,51 +314,120 @@ pub struct GpuRequiredFeatures(HashSet); impl From for wgpu_types::Features { fn from(required_features: GpuRequiredFeatures) -> wgpu_types::Features { let mut features: wgpu_types::Features = wgpu_types::Features::empty(); - features.set(wgpu_types::Features::DEPTH_CLIP_CONTROL, required_features.0.contains("depth-clip-control")); - features.set(wgpu_types::Features::PIPELINE_STATISTICS_QUERY, required_features.0.contains("pipeline-statistics-query")); - features.set(wgpu_types::Features::TEXTURE_COMPRESSION_BC, required_features.0.contains("texture-compression-bc")); - features.set(wgpu_types::Features::TEXTURE_COMPRESSION_ETC2, required_features.0.contains("texture-compression-etc2")); - features.set(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC_LDR, required_features.0.contains("texture-compression-astc")); - features.set(wgpu_types::Features::TIMESTAMP_QUERY, required_features.0.contains("timestamp-query")); - features.set(wgpu_types::Features::INDIRECT_FIRST_INSTANCE, required_features.0.contains("indirect-first-instance")); + features.set( + wgpu_types::Features::DEPTH_CLIP_CONTROL, + required_features.0.contains("depth-clip-control"), + ); + features.set( + wgpu_types::Features::PIPELINE_STATISTICS_QUERY, + required_features.0.contains("pipeline-statistics-query"), + ); + features.set( + wgpu_types::Features::TEXTURE_COMPRESSION_BC, + required_features.0.contains("texture-compression-bc"), + ); + features.set( + wgpu_types::Features::TEXTURE_COMPRESSION_ETC2, + required_features.0.contains("texture-compression-etc2"), + ); + features.set( + wgpu_types::Features::TEXTURE_COMPRESSION_ASTC_LDR, + required_features.0.contains("texture-compression-astc"), + ); + features.set( + wgpu_types::Features::TIMESTAMP_QUERY, + required_features.0.contains("timestamp-query"), + ); + features.set( + wgpu_types::Features::INDIRECT_FIRST_INSTANCE, + required_features.0.contains("indirect-first-instance"), + ); // extended from spec - features.set(wgpu_types::Features::MAPPABLE_PRIMARY_BUFFERS, required_features.0.contains("mappable-primary-buffers")); - features.set(wgpu_types::Features::TEXTURE_BINDING_ARRAY, required_features.0.contains("texture-binding-array")); - features.set(wgpu_types::Features::BUFFER_BINDING_ARRAY, required_features.0.contains("buffer-binding-array")); - features.set(wgpu_types::Features::STORAGE_RESOURCE_BINDING_ARRAY, required_features - .0 - .contains("storage-resource-binding-array")); - features.set( - wgpu_types::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, - required_features - .0 - .contains("sampled-texture-and-storage-buffer-array-non-uniform-indexing"), - ); - features.set( - wgpu_types::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, - required_features - .0 - .contains("uniform-buffer-and-storage-buffer-texture-non-uniform-indexing"), - ); - features.set(wgpu_types::Features::UNSIZED_BINDING_ARRAY, required_features.0.contains("unsized-binding-array")); - features.set(wgpu_types::Features::MULTI_DRAW_INDIRECT, required_features.0.contains("multi-draw-indirect")); - features.set(wgpu_types::Features::MULTI_DRAW_INDIRECT_COUNT, required_features.0.contains("multi-draw-indirect-count")); - features.set(wgpu_types::Features::PUSH_CONSTANTS, required_features.0.contains("push-constants")); - features.set(wgpu_types::Features::ADDRESS_MODE_CLAMP_TO_BORDER, required_features.0.contains("address-mode-clamp-to-border")); - features.set( - wgpu_types::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, - required_features - .0 - .contains("texture-adapter-specific-format-features"), - ); - features.set(wgpu_types::Features::SHADER_FLOAT64, required_features.0.contains("shader-float64")); - features.set(wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT, required_features.0.contains("vertex-attribute-64bit")); - features.set(wgpu_types::Features::CONSERVATIVE_RASTERIZATION, required_features.0.contains("conservative-rasterization")); - features.set(wgpu_types::Features::VERTEX_WRITABLE_STORAGE, required_features.0.contains("vertex-writable-storage")); - features.set(wgpu_types::Features::CLEAR_COMMANDS, required_features.0.contains("clear-commands")); - features.set(wgpu_types::Features::SPIRV_SHADER_PASSTHROUGH, required_features.0.contains("spirv-shader-passthrough")); - features.set(wgpu_types::Features::SHADER_PRIMITIVE_INDEX, required_features.0.contains("shader-primitive-index")); + features.set( + wgpu_types::Features::MAPPABLE_PRIMARY_BUFFERS, + required_features.0.contains("mappable-primary-buffers"), + ); + features.set( + wgpu_types::Features::TEXTURE_BINDING_ARRAY, + required_features.0.contains("texture-binding-array"), + ); + features.set( + wgpu_types::Features::BUFFER_BINDING_ARRAY, + required_features.0.contains("buffer-binding-array"), + ); + features.set( + wgpu_types::Features::STORAGE_RESOURCE_BINDING_ARRAY, + required_features + .0 + .contains("storage-resource-binding-array"), + ); + features.set( + wgpu_types::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, + required_features + .0 + .contains("sampled-texture-and-storage-buffer-array-non-uniform-indexing"), + ); + features.set( + wgpu_types::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, + required_features + .0 + .contains("uniform-buffer-and-storage-buffer-texture-non-uniform-indexing"), + ); + features.set( + wgpu_types::Features::UNSIZED_BINDING_ARRAY, + required_features.0.contains("unsized-binding-array"), + ); + features.set( + wgpu_types::Features::MULTI_DRAW_INDIRECT, + required_features.0.contains("multi-draw-indirect"), + ); + features.set( + wgpu_types::Features::MULTI_DRAW_INDIRECT_COUNT, + required_features.0.contains("multi-draw-indirect-count"), + ); + features.set( + wgpu_types::Features::PUSH_CONSTANTS, + required_features.0.contains("push-constants"), + ); + features.set( + wgpu_types::Features::ADDRESS_MODE_CLAMP_TO_BORDER, + required_features.0.contains("address-mode-clamp-to-border"), + ); + features.set( + wgpu_types::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, + required_features + .0 + .contains("texture-adapter-specific-format-features"), + ); + features.set( + wgpu_types::Features::SHADER_FLOAT64, + required_features.0.contains("shader-float64"), + ); + features.set( + wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT, + required_features.0.contains("vertex-attribute-64bit"), + ); + features.set( + wgpu_types::Features::CONSERVATIVE_RASTERIZATION, + required_features.0.contains("conservative-rasterization"), + ); + features.set( + wgpu_types::Features::VERTEX_WRITABLE_STORAGE, + required_features.0.contains("vertex-writable-storage"), + ); + features.set( + wgpu_types::Features::CLEAR_COMMANDS, + required_features.0.contains("clear-commands"), + ); + features.set( + wgpu_types::Features::SPIRV_SHADER_PASSTHROUGH, + required_features.0.contains("spirv-shader-passthrough"), + ); + features.set( + wgpu_types::Features::SHADER_PRIMITIVE_INDEX, + required_features.0.contains("shader-primitive-index"), + ); features } @@ -592,6 +663,10 @@ fn declare_webgpu_ops() -> Vec<(&'static str, Box)> { "op_webgpu_command_encoder_copy_texture_to_texture", op_sync(command_encoder::op_webgpu_command_encoder_copy_texture_to_texture), ), + ( + "op_webgpu_command_encoder_fill_buffer", + op_sync(command_encoder::op_webgpu_command_encoder_fill_buffer), + ), ( "op_webgpu_command_encoder_push_debug_group", op_sync(command_encoder::op_webgpu_command_encoder_push_debug_group), @@ -712,15 +787,11 @@ fn declare_webgpu_ops() -> Vec<(&'static str, Box)> { ), ( "op_webgpu_compute_pass_begin_pipeline_statistics_query", - op_sync( - compute_pass::op_webgpu_compute_pass_begin_pipeline_statistics_query, - ), + op_sync(compute_pass::op_webgpu_compute_pass_begin_pipeline_statistics_query), ), ( "op_webgpu_compute_pass_end_pipeline_statistics_query", - op_sync( - compute_pass::op_webgpu_compute_pass_end_pipeline_statistics_query, - ), + op_sync(compute_pass::op_webgpu_compute_pass_end_pipeline_statistics_query), ), ( "op_webgpu_compute_pass_write_timestamp", diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index 97fa77586..5567f97b9 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -82,7 +82,7 @@ dictionary GPUDeviceDescriptor : GPUObjectDescriptorBase { }; enum GPUFeatureName { - "depth-clamping", + "depth-clip-control", "depth24unorm-stencil8", "depth32float-stencil8", "pipeline-statistics-query", @@ -90,6 +90,7 @@ enum GPUFeatureName { "texture-compression-etc2", "texture-compression-astc", "timestamp-query", + "indirect-first-instance", }; [Exposed=(Window, DedicatedWorker), SecureContext] @@ -577,8 +578,8 @@ dictionary GPUPrimitiveState { GPUFrontFace frontFace = "ccw"; GPUCullMode cullMode = "none"; - // Enable depth clamping (requires "depth-clamping" feature) - boolean clampDepth = false; + // Requires "depth-clip-control" feature. + boolean unclippedDepth = false; }; enum GPUFrontFace { @@ -784,6 +785,11 @@ interface GPUCommandEncoder { GPUImageCopyTexture destination, GPUExtent3D copySize); + undefined fillBuffer( + GPUBuffer destination, + GPUSize64 destinationOffset, + GPUSize64 size); + undefined pushDebugGroup(USVString groupLabel); undefined popDebugGroup(); undefined insertDebugMarker(USVString markerLabel); diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index d12d2af54..7c36a3301 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -10,6 +10,7 @@ mod transfer; pub use self::bundle::*; pub(crate) use self::clear::collect_zero_buffer_copies_for_clear_texture; +pub use self::clear::ClearError; pub use self::compute::*; pub use self::draw::*; use self::memory_init::CommandBufferTextureMemoryActions;