From ad5c7fe50e751ed5764e531fa1c5d7962ce94c4f Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sat, 27 Jul 2024 18:16:41 +0200 Subject: [PATCH] DynDevice create/destroy ShaderModule --- wgpu-hal/src/dynamic/device.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dynamic/device.rs b/wgpu-hal/src/dynamic/device.rs index 788c6dc17..0e1327385 100644 --- a/wgpu-hal/src/dynamic/device.rs +++ b/wgpu-hal/src/dynamic/device.rs @@ -4,12 +4,14 @@ use crate::{ Api, BindGroupDescriptor, BindGroupLayoutDescriptor, BufferDescriptor, BufferMapping, CommandEncoderDescriptor, Device, DeviceError, DynBuffer, DynResource, MemoryRange, - PipelineLayoutDescriptor, SamplerDescriptor, TextureDescriptor, TextureViewDescriptor, + PipelineLayoutDescriptor, SamplerDescriptor, ShaderError, ShaderInput, ShaderModuleDescriptor, + TextureDescriptor, TextureViewDescriptor, }; use super::{ DynAccelerationStructure, DynBindGroup, DynBindGroupLayout, DynCommandEncoder, - DynPipelineLayout, DynQueue, DynResourceExt as _, DynSampler, DynTexture, DynTextureView, + DynPipelineLayout, DynQueue, DynResourceExt as _, DynSampler, DynShaderModule, DynTexture, + DynTextureView, }; pub trait DynDevice: DynResource { @@ -77,6 +79,13 @@ pub trait DynDevice: DynResource { >, ) -> Result, DeviceError>; unsafe fn destroy_bind_group(&self, group: Box); + + unsafe fn create_shader_module( + &self, + desc: &ShaderModuleDescriptor, + shader: ShaderInput, + ) -> Result, ShaderError>; + unsafe fn destroy_shader_module(&self, module: Box); } impl DynDevice for D { @@ -261,4 +270,17 @@ impl DynDevice for D { unsafe fn destroy_bind_group(&self, group: Box) { unsafe { D::destroy_bind_group(self, group.unbox()) }; } + + unsafe fn create_shader_module( + &self, + desc: &ShaderModuleDescriptor, + shader: ShaderInput, + ) -> Result, ShaderError> { + unsafe { D::create_shader_module(self, desc, shader) } + .map(|b| Box::new(b) as Box) + } + + unsafe fn destroy_shader_module(&self, module: Box) { + unsafe { D::destroy_shader_module(self, module.unbox()) }; + } }