webgpu: Clean up GPUCommandEncoders and add some validation (#33223)

* TextureUsages::from_bits_retain

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Fixup CreateBindGroupLayout

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* GPUExtent3D checking and converting

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Cleanup GPUCommandEncoders and some TODOs

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* validate gpuorigin3d

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* validate GPUColor

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* set good expect

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-08-30 13:23:17 +02:00 committed by GitHub
parent 83a40c5180
commit 817a91f2ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 276 additions and 361 deletions

View file

@ -6,6 +6,7 @@ use dom_struct::dom_struct;
use webgpu::{wgt, RenderCommand, WebGPU, WebGPURenderPass, WebGPURequest};
use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat;
use super::bindings::error::Fallible;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUColor, GPURenderPassEncoderMethods,
@ -18,6 +19,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandencoder::GPUCommandEncoder;
use crate::dom::gpuconvert::convert_color;
use crate::dom::gpurenderbundle::GPURenderBundle;
use crate::dom::gpurenderpipeline::GPURenderPipeline;
@ -129,28 +131,9 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setblendcolor>
fn SetBlendConstant(&self, color: GPUColor) {
let color = match color {
GPUColor::GPUColorDict(d) => wgt::Color {
r: *d.r,
g: *d.g,
b: *d.b,
a: *d.a,
},
GPUColor::DoubleSequence(mut s) => {
if s.len() < 3 {
s.resize(3, Finite::wrap(0.0f64));
}
s.resize(4, Finite::wrap(1.0f64));
wgt::Color {
r: *s[0],
g: *s[1],
b: *s[2],
a: *s[3],
}
},
};
self.send_render_command(RenderCommand::SetBlendConstant(color))
fn SetBlendConstant(&self, color: GPUColor) -> Fallible<()> {
self.send_render_command(RenderCommand::SetBlendConstant(convert_color(&color)?));
Ok(())
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setstencilreference>