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

@ -5,8 +5,6 @@
//! IPC messages that are received in wgpu thread
//! (usually from script thread more specifically from dom objects)
use std::borrow::Cow;
use arrayvec::ArrayVec;
use base::id::PipelineId;
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
@ -27,6 +25,7 @@ use wgc::resource::{
BufferDescriptor, SamplerDescriptor, TextureDescriptor, TextureViewDescriptor,
};
use wgpu_core::command::{RenderPassColorAttachment, RenderPassDepthStencilAttachment};
use wgpu_core::Label;
pub use {wgpu_core as wgc, wgpu_types as wgt};
use crate::identity::*;
@ -46,9 +45,7 @@ pub enum WebGPURequest {
CommandEncoderFinish {
command_encoder_id: id::CommandEncoderId,
device_id: id::DeviceId,
is_error: bool,
// TODO(zakorgy): Serialize CommandBufferDescriptor in wgpu-core
// wgc::command::CommandBufferDescriptor,
desc: wgt::CommandBufferDescriptor<Label<'static>>,
},
CopyBufferToBuffer {
command_encoder_id: id::CommandEncoderId,
@ -93,10 +90,8 @@ pub enum WebGPURequest {
},
CreateCommandEncoder {
device_id: id::DeviceId,
// TODO(zakorgy): Serialize CommandEncoderDescriptor in wgpu-core
// wgc::command::CommandEncoderDescriptor,
command_encoder_id: id::CommandEncoderId,
label: Option<Cow<'static, str>>,
desc: wgt::CommandEncoderDescriptor<Label<'static>>,
},
CreateComputePipeline {
device_id: id::DeviceId,
@ -144,7 +139,7 @@ pub enum WebGPURequest {
CreateTexture {
device_id: id::DeviceId,
texture_id: id::TextureId,
descriptor: Option<TextureDescriptor<'static>>,
descriptor: TextureDescriptor<'static>,
},
CreateTextureView {
texture_id: id::TextureId,
@ -203,7 +198,7 @@ pub enum WebGPURequest {
BeginComputePass {
command_encoder_id: id::CommandEncoderId,
compute_pass_id: ComputePassId,
label: Option<Cow<'static, str>>,
label: Label<'static>,
device_id: id::DeviceId,
},
ComputePassSetPipeline {
@ -240,7 +235,7 @@ pub enum WebGPURequest {
BeginRenderPass {
command_encoder_id: id::CommandEncoderId,
render_pass_id: RenderPassId,
label: Option<Cow<'static, str>>,
label: Label<'static>,
color_attachments: Vec<Option<RenderPassColorAttachment>>,
depth_stencil_attachment: Option<RenderPassDepthStencilAttachment>,
device_id: id::DeviceId,

View file

@ -230,21 +230,15 @@ impl WGPU {
WebGPURequest::CommandEncoderFinish {
command_encoder_id,
device_id,
is_error,
desc,
} => {
let global = &self.global;
let result = if is_error {
Err(Error::Validation(String::from("Invalid GPUCommandEncoder")))
} else if let Some(err) =
let result = if let Some(err) =
self.error_command_encoders.get(&command_encoder_id)
{
Err(Error::Validation(err.clone()))
} else if let Some(error) = global
.command_encoder_finish(
command_encoder_id,
&wgt::CommandBufferDescriptor::default(),
)
.1
} else if let Some(error) =
global.command_encoder_finish(command_encoder_id, &desc).1
{
Err(Error::from_error(error))
} else {
@ -363,10 +357,9 @@ impl WGPU {
WebGPURequest::CreateCommandEncoder {
device_id,
command_encoder_id,
label,
desc,
} => {
let global = &self.global;
let desc = wgt::CommandEncoderDescriptor { label };
let (_, error) = global.device_create_command_encoder(
device_id,
&desc,
@ -579,11 +572,9 @@ impl WGPU {
descriptor,
} => {
let global = &self.global;
if let Some(desc) = descriptor {
let (_, error) =
global.device_create_texture(device_id, &desc, Some(texture_id));
self.maybe_dispatch_wgpu_error(device_id, error);
}
let (_, error) =
global.device_create_texture(device_id, &descriptor, Some(texture_id));
self.maybe_dispatch_wgpu_error(device_id, error);
},
WebGPURequest::CreateTextureView {
texture_id,