mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add GPUSampler and GPUTextureView to BindingResource
Add validation for BindGroups
This commit is contained in:
parent
abc3ed40c9
commit
00b3f785c4
12 changed files with 591 additions and 123 deletions
|
@ -3,11 +3,12 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUObjectBaseBinding::GPUObjectDescriptorBase;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUTextureBinding::{
|
||||
GPUExtent3DDict, GPUTextureDimension, GPUTextureFormat, GPUTextureMethods,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::{
|
||||
GPUTextureAspect, GPUTextureViewDescriptor,
|
||||
GPUTextureAspect, GPUTextureViewDescriptor, GPUTextureViewDimension,
|
||||
};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
|
@ -107,6 +108,14 @@ impl GPUTexture {
|
|||
pub fn id(&self) -> WebGPUTexture {
|
||||
self.texture
|
||||
}
|
||||
|
||||
pub fn sample_count(&self) -> u32 {
|
||||
self.sample_count
|
||||
}
|
||||
|
||||
pub fn usage(&self) -> u32 {
|
||||
self.texture_usage
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUTextureMethods for GPUTexture {
|
||||
|
@ -122,23 +131,28 @@ impl GPUTextureMethods for GPUTexture {
|
|||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gputexture-createview
|
||||
fn CreateView(&self, descriptor: &GPUTextureViewDescriptor) -> DomRoot<GPUTextureView> {
|
||||
let dimension = if let Some(d) = descriptor.dimension {
|
||||
d
|
||||
} else {
|
||||
match self.dimension {
|
||||
GPUTextureDimension::_1d => GPUTextureViewDimension::_1d,
|
||||
GPUTextureDimension::_2d => {
|
||||
if self.texture_size.depth > 1 && descriptor.arrayLayerCount == 0 {
|
||||
GPUTextureViewDimension::_2d_array
|
||||
} else {
|
||||
GPUTextureViewDimension::_2d
|
||||
}
|
||||
},
|
||||
GPUTextureDimension::_3d => GPUTextureViewDimension::_3d,
|
||||
}
|
||||
};
|
||||
|
||||
let format = descriptor.format.unwrap_or(self.format);
|
||||
|
||||
let desc = wgt::TextureViewDescriptor {
|
||||
label: Default::default(),
|
||||
format: convert_texture_format(descriptor.format.unwrap_or(self.format)),
|
||||
dimension: match descriptor.dimension {
|
||||
Some(d) => convert_texture_view_dimension(d),
|
||||
None => match self.dimension {
|
||||
GPUTextureDimension::_1d => wgt::TextureViewDimension::D1,
|
||||
GPUTextureDimension::_2d => {
|
||||
if self.texture_size.depth > 1 && descriptor.arrayLayerCount == 0 {
|
||||
wgt::TextureViewDimension::D2Array
|
||||
} else {
|
||||
wgt::TextureViewDimension::D2
|
||||
}
|
||||
},
|
||||
GPUTextureDimension::_3d => wgt::TextureViewDimension::D3,
|
||||
},
|
||||
},
|
||||
format: convert_texture_format(format),
|
||||
dimension: convert_texture_view_dimension(dimension),
|
||||
aspect: match descriptor.aspect {
|
||||
GPUTextureAspect::All => wgt::TextureAspect::All,
|
||||
GPUTextureAspect::Stencil_only => wgt::TextureAspect::StencilOnly,
|
||||
|
@ -175,7 +189,32 @@ impl GPUTextureMethods for GPUTexture {
|
|||
|
||||
let texture_view = WebGPUTextureView(texture_view_id);
|
||||
|
||||
GPUTextureView::new(&self.global(), texture_view, self.device, true)
|
||||
let desc = GPUTextureViewDescriptor {
|
||||
parent: GPUObjectDescriptorBase {
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|l| l.as_ref().map(|u| u.clone())),
|
||||
},
|
||||
arrayLayerCount: if descriptor.arrayLayerCount == 0 {
|
||||
self.texture_size.depth - descriptor.baseArrayLayer
|
||||
} else {
|
||||
descriptor.arrayLayerCount
|
||||
},
|
||||
aspect: descriptor.aspect,
|
||||
baseArrayLayer: descriptor.baseArrayLayer,
|
||||
baseMipLevel: descriptor.baseMipLevel,
|
||||
dimension: Some(dimension),
|
||||
format: Some(descriptor.format.unwrap_or(self.format)),
|
||||
mipLevelCount: if descriptor.mipLevelCount == 0 {
|
||||
self.mip_level_count - descriptor.baseMipLevel
|
||||
} else {
|
||||
descriptor.mipLevelCount
|
||||
},
|
||||
};
|
||||
|
||||
GPUTextureView::new(&self.global(), texture_view, &self, true, desc)
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gputexture-destroy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue