diff --git a/CHANGELOG.md b/CHANGELOG.md index eb121071..6d42faa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/ - `WGPUNativeLimits::maxBindingArraySamplerElementsPerShaderStage` @lisyarus - `WGPUNativeLimits::maxMultiviewViewCount` @lisyarus - `WGPUNativeFeature_StorageTextureArrayNonUniformIndexing`, `WGPUNativeFeature_Multiview`, `WGPUNativeFeature_ShaderFloat32Atomic`, `WGPUNativeFeature_TextureAtomic`, `WGPUNativeFeature_TextureFormatP010`, `WGPUNativeFeature_PipelineCache`, `WGPUNativeFeature_ShaderInt64AtomicMinMax`, `WGPUNativeFeature_ShaderInt64AtomicAllOps`, `WGPUNativeFeature_TextureInt64Atomic`, `WGPUNativeFeature_ShaderBarycentrics`, `WGPUNativeFeature_SelectiveMultiview`, `WGPUNativeFeature_MultisampleArray`, `WGPUNativeFeature_CooperativeMatrix`, `WGPUNativeFeature_ShaderPerVertex`, `WGPUNativeFeature_ShaderDrawIndex`, `WGPUNativeFeature_AccelerationStructureBindingArray`, `WGPUNativeFeature_MemoryDecorationCoherent`, `WGPUNativeFeature_MemoryDecorationVolatile` @lisyarus +- `wgpuCommandEncoderClearTexture` @lisyarus ### Removed diff --git a/ffi/wgpu.h b/ffi/wgpu.h index e370ea4e..aea7b896 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -379,8 +379,15 @@ typedef enum WGPUNativeFeature * This is a native only feature. */ WGPUNativeFeature_ConservativeRasterization = 0x00030015, - // TODO: requires wgpu.h api change - // WGPUNativeFeature_ClearTexture = 0x00030016, + /** + * Enables clear to zero for textures. + * + * Supported platforms: + * - All + * + * This is a native only feature. + */ + WGPUNativeFeature_ClearTexture = 0x00030016, /** * Enables multiview render passes and `builtin(view_index)` in vertex/mesh shaders. * @@ -1456,6 +1463,14 @@ typedef enum WGPUNativeTextureFormat WGPUNativeTextureFormat_P010 = 0x00030008, } WGPUNativeTextureFormat; +typedef struct WGPUImageSubresourceRange { + WGPUTextureAspect aspect; + uint32_t baseMipLevel; + uint32_t mipLevelCount; + uint32_t baseArrayLayer; + uint32_t arrayLayerCount; +} WGPUImageSubresourceRange WGPU_STRUCTURE_ATTRIBUTE; + #ifdef __cplusplus extern "C" { @@ -1526,6 +1541,8 @@ extern "C" WGPUBool wgpuDeviceStartGraphicsDebuggerCapture(WGPUDevice device); void wgpuDeviceStopGraphicsDebuggerCapture(WGPUDevice device); + void wgpuCommandEncoderClearTexture(WGPUCommandEncoder commandEncoder, WGPUTexture texture, WGPUImageSubresourceRange const * range); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/conv.rs b/src/conv.rs index 2a241d9f..3411c537 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -1302,10 +1302,9 @@ pub fn features_to_native(features: wgt::Features) -> Vec Option { native::WGPUNativeFeature_PolygonModePoint => Some(Features::POLYGON_MODE_POINT), native::WGPUNativeFeature_ConservativeRasterization => Some(Features::CONSERVATIVE_RASTERIZATION), // TODO: requires wgpu.h api change - // native::WGPUNativeFeature_ClearTexture => Some(Features::CLEAR_TEXTURE), + native::WGPUNativeFeature_ClearTexture => Some(Features::CLEAR_TEXTURE), native::WGPUNativeFeature_Multiview => Some(Features::MULTIVIEW), native::WGPUNativeFeature_VertexAttribute64bit => Some(Features::VERTEX_ATTRIBUTE_64BIT), native::WGPUNativeFeature_TextureFormatNv12 => Some(Features::TEXTURE_FORMAT_NV12), diff --git a/src/lib.rs b/src/lib.rs index 7488e584..7a349c62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1300,6 +1300,48 @@ pub unsafe extern "C" fn wgpuCommandEncoderClearBuffer( } } +#[no_mangle] +pub unsafe extern "C" fn wgpuCommandEncoderClearTexture( + command_encoder: native::WGPUCommandEncoder, + texture: native::WGPUTexture, + range: Option<&native::WGPUImageSubresourceRange>, +) { + let (command_encoder_id, context, error_sink) = { + let command_encoder = command_encoder.as_ref().expect("invalid command encoder"); + ( + command_encoder.id, + &command_encoder.context, + &command_encoder.error_sink, + ) + }; + let texture_id = texture.as_ref().expect("invalid texture").id; + + let subresource_range = match range { + Some(range) => wgt::ImageSubresourceRange { + aspect: conv::map_texture_aspect(range.aspect).unwrap_or(wgt::TextureAspect::All), + base_mip_level: range.baseMipLevel, + mip_level_count: match range.mipLevelCount { + 0 => panic!("invalid mipLevelCount"), + native::WGPU_MIP_LEVEL_COUNT_UNDEFINED => None, + _ => Some(range.mipLevelCount), + }, + base_array_layer: range.baseArrayLayer, + array_layer_count: match range.arrayLayerCount { + 0 => panic!("invalid arrayLayerCount"), + native::WGPU_ARRAY_LAYER_COUNT_UNDEFINED => None, + _ => Some(range.arrayLayerCount), + }, + }, + None => wgt::ImageSubresourceRange::default(), + }; + + if let Err(cause) = + context.command_encoder_clear_texture(command_encoder_id, texture_id, &subresource_range) + { + handle_error(error_sink, cause, None, "wgpuCommandEncoderClearTexture"); + } +} + #[no_mangle] pub unsafe extern "C" fn wgpuCommandEncoderCopyBufferToBuffer( command_encoder: native::WGPUCommandEncoder,