aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamson <16504129+sagudev@users.noreply.github.com>2024-09-20 15:14:08 +0200
committerGitHub <noreply@github.com>2024-09-20 13:14:08 +0000
commit4bde9af5159b18eba1b65256de0d2dda328a1eb2 (patch)
tree7fe20cb47c36828cec8f2272cb0e39287797b39c
parent157e28c59b34ec8c7334161fda658cbbb1e66a25 (diff)
downloadservo-4bde9af5159b18eba1b65256de0d2dda328a1eb2.tar.gz
servo-4bde9af5159b18eba1b65256de0d2dda328a1eb2.zip
webgpu: Support more `TextureFormat`s in `GPUCanvasContext.configure()` (#33504)
* `descriptor` -> `configuration` to match spec Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Support more `TextureFormat`s in `GPUCanvasContext.configure()` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
-rw-r--r--components/script/dom/gpucanvascontext.rs41
1 files changed, 25 insertions, 16 deletions
diff --git a/components/script/dom/gpucanvascontext.rs b/components/script/dom/gpucanvascontext.rs
index 6f399c607a9..fe16b824504 100644
--- a/components/script/dom/gpucanvascontext.rs
+++ b/components/script/dom/gpucanvascontext.rs
@@ -201,26 +201,33 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-configure>
- fn Configure(&self, descriptor: &GPUCanvasConfiguration) -> Fallible<()> {
+ fn Configure(&self, configuration: &GPUCanvasConfiguration) -> Fallible<()> {
// Step 1 is let
// Step 2
- descriptor
+ configuration
.device
- .validate_texture_format_required_features(&descriptor.format)?;
- let format = match descriptor.format {
- GPUTextureFormat::Rgba8unorm | GPUTextureFormat::Rgba8unorm_srgb => ImageFormat::RGBA8,
+ .validate_texture_format_required_features(&configuration.format)?;
+ // Mapping between wr and wgpu can be determined by inspecting
+ // https://github.com/gfx-rs/wgpu/blob/9b36a3e129da04b018257564d5129caff240cb75/wgpu-hal/src/gles/conv.rs#L10
+ // https://github.com/servo/webrender/blob/1e73f384a7a86e413f91e9e430436a9bd83381cd/webrender/src/device/gl.rs#L4064
+ let format = match configuration.format {
+ GPUTextureFormat::R8unorm => ImageFormat::R8,
GPUTextureFormat::Bgra8unorm | GPUTextureFormat::Bgra8unorm_srgb => ImageFormat::BGRA8,
+ GPUTextureFormat::Rgba8unorm | GPUTextureFormat::Rgba8unorm_srgb => ImageFormat::RGBA8,
+ GPUTextureFormat::Rgba32float => ImageFormat::RGBAF32,
+ GPUTextureFormat::Rgba32sint => ImageFormat::RGBAI32,
+ GPUTextureFormat::Rg8unorm => ImageFormat::RG8,
_ => {
return Err(Error::Type(format!(
"SwapChain format({:?}) not supported",
- descriptor.format
+ configuration.format
)))
},
};
// Step 3
- for view_format in &descriptor.viewFormats {
- descriptor
+ for view_format in &configuration.viewFormats {
+ configuration
.device
.validate_texture_format_required_features(view_format)?;
}
@@ -228,16 +235,17 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
// Step 4
let size = self.size();
let text_desc = GPUTextureDescriptor {
- format: descriptor.format,
+ format: configuration.format,
mipLevelCount: 1,
sampleCount: 1,
- usage: descriptor.usage | GPUTextureUsageConstants::COPY_SRC, // TODO: specs
+ // We need to add `COPY_SRC` so we can copy texture to presentation buffer
+ usage: configuration.usage | GPUTextureUsageConstants::COPY_SRC,
size: GPUExtent3D::GPUExtent3DDict(GPUExtent3DDict {
width: size.width as u32,
height: size.height as u32,
depthOrArrayLayers: 1,
}),
- viewFormats: descriptor.viewFormats.clone(),
+ viewFormats: configuration.viewFormats.clone(),
// other members to default
parent: GPUObjectDescriptorBase {
label: USVString::default(),
@@ -253,15 +261,15 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
buffer_ids.push(
self.global()
.wgpu_id_hub()
- .create_buffer_id(descriptor.device.id().0.backend()),
+ .create_buffer_id(configuration.device.id().0.backend()),
);
}
self.channel
.0
.send(WebGPURequest::CreateSwapChain {
- device_id: descriptor.device.id().0,
- queue_id: descriptor.device.GetQueue().id().0,
+ device_id: configuration.device.id().0,
+ queue_id: configuration.device.GetQueue().id().0,
buffer_ids,
context_id: self.context_id,
sender,
@@ -270,8 +278,9 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
})
.expect("Failed to create WebGPU SwapChain");
- self.texture
- .set(Some(&descriptor.device.CreateTexture(&text_desc).unwrap()));
+ self.texture.set(Some(
+ &configuration.device.CreateTexture(&text_desc).unwrap(),
+ ));
self.webrender_image.set(Some(receiver.recv().unwrap()));
Ok(())