@@ -7,6 +7,10 @@ use std::num::NonZeroU64;
77use deno_core:: cppgc:: Ptr ;
88use deno_core:: op2;
99use deno_core:: v8;
10+ use deno_core:: v8:: HandleScope ;
11+ use deno_core:: v8:: Local ;
12+ use deno_core:: v8:: Value ;
13+ use deno_core:: webidl:: ContextFn ;
1014use deno_core:: webidl:: IntOptions ;
1115use deno_core:: webidl:: Nullable ;
1216use deno_core:: webidl:: WebIdlConverter ;
@@ -17,6 +21,7 @@ use deno_core::WebIDL;
1721use crate :: buffer:: GPUBuffer ;
1822use crate :: error:: GPUGenericError ;
1923use crate :: render_bundle:: GPURenderBundle ;
24+ use crate :: texture:: GPUTexture ;
2025use crate :: texture:: GPUTextureView ;
2126use crate :: webidl:: GPUColor ;
2227use crate :: Instance ;
@@ -441,10 +446,10 @@ pub(crate) struct GPURenderPassDescriptor {
441446#[ derive( WebIDL ) ]
442447#[ webidl( dictionary) ]
443448pub ( crate ) struct GPURenderPassColorAttachment {
444- pub view : Ptr < GPUTextureView > ,
449+ pub view : GPUTextureOrView ,
445450 #[ options( enforce_range = true ) ]
446451 pub depth_slice : Option < u32 > ,
447- pub resolve_target : Option < Ptr < GPUTextureView > > ,
452+ pub resolve_target : Option < GPUTextureOrView > ,
448453 pub clear_value : Option < GPUColor > ,
449454 pub load_op : GPULoadOp ,
450455 pub store_op : GPUStoreOp ,
@@ -495,7 +500,7 @@ impl From<GPUStoreOp> for wgpu_core::command::StoreOp {
495500#[ derive( WebIDL ) ]
496501#[ webidl( dictionary) ]
497502pub ( crate ) struct GPURenderPassDepthStencilAttachment {
498- pub view : Ptr < GPUTextureView > ,
503+ pub view : GPUTextureOrView ,
499504 pub depth_clear_value : Option < f32 > ,
500505 pub depth_load_op : Option < GPULoadOp > ,
501506 pub depth_store_op : Option < GPUStoreOp > ,
@@ -519,3 +524,48 @@ pub(crate) struct GPURenderPassTimestampWrites {
519524 #[ options( enforce_range = true ) ]
520525 pub end_of_pass_write_index : Option < u32 > ,
521526}
527+
528+ pub ( crate ) enum GPUTextureOrView {
529+ Texture ( Ptr < GPUTexture > ) ,
530+ TextureView ( Ptr < GPUTextureView > ) ,
531+ }
532+
533+ impl GPUTextureOrView {
534+ pub ( crate ) fn to_view_id ( & self ) -> wgpu_core:: id:: TextureViewId {
535+ match self {
536+ Self :: Texture ( texture) => texture. default_view_id ( ) ,
537+ Self :: TextureView ( texture_view) => texture_view. id ,
538+ }
539+ }
540+ }
541+
542+ impl < ' a > WebIdlConverter < ' a > for GPUTextureOrView {
543+ type Options = ( ) ;
544+
545+ fn convert < ' b > (
546+ scope : & mut HandleScope < ' a > ,
547+ value : Local < ' a , Value > ,
548+ prefix : Cow < ' static , str > ,
549+ context : ContextFn < ' b > ,
550+ options : & Self :: Options ,
551+ ) -> Result < Self , WebIdlError > {
552+ <Ptr < GPUTexture > >:: convert (
553+ scope,
554+ value,
555+ prefix. clone ( ) ,
556+ context. borrowed ( ) ,
557+ options,
558+ )
559+ . map ( Self :: Texture )
560+ . or_else ( |_| {
561+ <Ptr < GPUTextureView > >:: convert (
562+ scope,
563+ value,
564+ prefix. clone ( ) ,
565+ context. borrowed ( ) ,
566+ options,
567+ )
568+ . map ( Self :: TextureView )
569+ } )
570+ }
571+ }
0 commit comments