use wgpu;
#[derive(Clone, Debug)]
pub struct GpuBuffer {
inner: GpuBufferInner,
}
#[derive(Clone, Debug)]
enum GpuBufferInner {
Real(wgpu::Buffer),
#[cfg(feature = "mock")]
Mock {
id: usize,
size: u64,
},
}
impl GpuBuffer {
pub fn from_wgpu(buffer: wgpu::Buffer) -> Self {
Self {
inner: GpuBufferInner::Real(buffer),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize, size: u64) -> Self {
Self {
inner: GpuBufferInner::Mock { id, size },
}
}
pub fn as_wgpu(&self) -> &wgpu::Buffer {
match &self.inner {
GpuBufferInner::Real(buffer) => buffer,
#[cfg(feature = "mock")]
GpuBufferInner::Mock { .. } => {
panic!(
"Attempted to get wgpu::Buffer from mock buffer - this is a test-only buffer"
)
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuBufferInner::Mock { .. })
}
#[cfg(feature = "mock")]
pub fn mock_id(&self) -> Option<usize> {
match &self.inner {
GpuBufferInner::Mock { id, .. } => Some(*id),
_ => None,
}
}
}
#[derive(Clone, Debug)]
pub struct GpuTexture {
inner: GpuTextureInner,
}
#[derive(Clone, Debug)]
enum GpuTextureInner {
Real(wgpu::Texture),
#[cfg(feature = "mock")]
Mock {
id: usize,
width: u32,
height: u32,
format: wgpu::TextureFormat,
},
}
impl GpuTexture {
pub fn from_wgpu(texture: wgpu::Texture) -> Self {
Self {
inner: GpuTextureInner::Real(texture),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize, width: u32, height: u32, format: wgpu::TextureFormat) -> Self {
Self {
inner: GpuTextureInner::Mock {
id,
width,
height,
format,
},
}
}
pub fn as_wgpu(&self) -> &wgpu::Texture {
match &self.inner {
GpuTextureInner::Real(texture) => texture,
#[cfg(feature = "mock")]
GpuTextureInner::Mock { .. } => {
panic!("Attempted to get wgpu::Texture from mock texture")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuTextureInner::Mock { .. })
}
#[cfg(feature = "mock")]
pub fn mock_id(&self) -> Option<usize> {
match &self.inner {
GpuTextureInner::Mock { id, .. } => Some(*id),
_ => None,
}
}
}
#[derive(Clone, Debug)]
pub struct GpuShaderModule {
inner: GpuShaderModuleInner,
}
#[derive(Clone, Debug)]
enum GpuShaderModuleInner {
Real(wgpu::ShaderModule),
#[cfg(feature = "mock")]
Mock {
id: usize,
},
}
impl GpuShaderModule {
pub fn from_wgpu(module: wgpu::ShaderModule) -> Self {
Self {
inner: GpuShaderModuleInner::Real(module),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize) -> Self {
Self {
inner: GpuShaderModuleInner::Mock { id },
}
}
pub fn as_wgpu(&self) -> &wgpu::ShaderModule {
match &self.inner {
GpuShaderModuleInner::Real(module) => module,
#[cfg(feature = "mock")]
GpuShaderModuleInner::Mock { .. } => {
panic!("Attempted to get wgpu::ShaderModule from mock")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuShaderModuleInner::Mock { .. })
}
}
#[derive(Clone, Debug)]
pub struct GpuRenderPipeline {
inner: GpuRenderPipelineInner,
}
#[derive(Clone, Debug)]
enum GpuRenderPipelineInner {
Real(wgpu::RenderPipeline),
#[cfg(feature = "mock")]
Mock {
id: usize,
},
}
impl GpuRenderPipeline {
pub fn from_wgpu(pipeline: wgpu::RenderPipeline) -> Self {
Self {
inner: GpuRenderPipelineInner::Real(pipeline),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize) -> Self {
Self {
inner: GpuRenderPipelineInner::Mock { id },
}
}
pub fn as_wgpu(&self) -> &wgpu::RenderPipeline {
match &self.inner {
GpuRenderPipelineInner::Real(pipeline) => pipeline,
#[cfg(feature = "mock")]
GpuRenderPipelineInner::Mock { .. } => {
panic!("Attempted to get wgpu::RenderPipeline from mock")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuRenderPipelineInner::Mock { .. })
}
}
#[derive(Clone, Debug)]
pub struct GpuComputePipeline {
inner: GpuComputePipelineInner,
}
#[derive(Clone, Debug)]
enum GpuComputePipelineInner {
Real(wgpu::ComputePipeline),
#[cfg(feature = "mock")]
Mock {
id: usize,
},
}
impl GpuComputePipeline {
pub fn from_wgpu(pipeline: wgpu::ComputePipeline) -> Self {
Self {
inner: GpuComputePipelineInner::Real(pipeline),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize) -> Self {
Self {
inner: GpuComputePipelineInner::Mock { id },
}
}
pub fn as_wgpu(&self) -> &wgpu::ComputePipeline {
match &self.inner {
GpuComputePipelineInner::Real(pipeline) => pipeline,
#[cfg(feature = "mock")]
GpuComputePipelineInner::Mock { .. } => {
panic!("Attempted to get wgpu::ComputePipeline from mock")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuComputePipelineInner::Mock { .. })
}
}
#[derive(Clone, Debug)]
pub struct GpuBindGroupLayout {
inner: GpuBindGroupLayoutInner,
}
#[derive(Clone, Debug)]
enum GpuBindGroupLayoutInner {
Real(wgpu::BindGroupLayout),
#[cfg(feature = "mock")]
Mock {
id: usize,
},
}
impl GpuBindGroupLayout {
pub fn from_wgpu(layout: wgpu::BindGroupLayout) -> Self {
Self {
inner: GpuBindGroupLayoutInner::Real(layout),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize) -> Self {
Self {
inner: GpuBindGroupLayoutInner::Mock { id },
}
}
pub fn as_wgpu(&self) -> &wgpu::BindGroupLayout {
match &self.inner {
GpuBindGroupLayoutInner::Real(layout) => layout,
#[cfg(feature = "mock")]
GpuBindGroupLayoutInner::Mock { .. } => {
panic!("Attempted to get wgpu::BindGroupLayout from mock")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuBindGroupLayoutInner::Mock { .. })
}
}
#[derive(Clone, Debug)]
pub struct GpuBindGroup {
inner: GpuBindGroupInner,
}
#[derive(Clone, Debug)]
enum GpuBindGroupInner {
Real(wgpu::BindGroup),
#[cfg(feature = "mock")]
Mock {
id: usize,
},
}
impl GpuBindGroup {
pub fn from_wgpu(bind_group: wgpu::BindGroup) -> Self {
Self {
inner: GpuBindGroupInner::Real(bind_group),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize) -> Self {
Self {
inner: GpuBindGroupInner::Mock { id },
}
}
pub fn as_wgpu(&self) -> &wgpu::BindGroup {
match &self.inner {
GpuBindGroupInner::Real(bind_group) => bind_group,
#[cfg(feature = "mock")]
GpuBindGroupInner::Mock { .. } => {
panic!("Attempted to get wgpu::BindGroup from mock")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuBindGroupInner::Mock { .. })
}
}
#[derive(Clone, Debug)]
pub struct GpuSampler {
inner: GpuSamplerInner,
}
#[derive(Clone, Debug)]
enum GpuSamplerInner {
Real(wgpu::Sampler),
#[cfg(feature = "mock")]
Mock {
id: usize,
},
}
impl GpuSampler {
pub fn from_wgpu(sampler: wgpu::Sampler) -> Self {
Self {
inner: GpuSamplerInner::Real(sampler),
}
}
#[cfg(feature = "mock")]
pub fn mock(id: usize) -> Self {
Self {
inner: GpuSamplerInner::Mock { id },
}
}
pub fn as_wgpu(&self) -> &wgpu::Sampler {
match &self.inner {
GpuSamplerInner::Real(sampler) => sampler,
#[cfg(feature = "mock")]
GpuSamplerInner::Mock { .. } => {
panic!("Attempted to get wgpu::Sampler from mock")
}
}
}
#[cfg(feature = "mock")]
pub fn is_mock(&self) -> bool {
matches!(self.inner, GpuSamplerInner::Mock { .. })
}
}