@@ -7,6 +7,10 @@ use std::num::NonZeroU64;
7
7
use deno_core:: cppgc:: Ptr ;
8
8
use deno_core:: op2;
9
9
use 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 ;
10
14
use deno_core:: webidl:: IntOptions ;
11
15
use deno_core:: webidl:: Nullable ;
12
16
use deno_core:: webidl:: WebIdlConverter ;
@@ -17,6 +21,7 @@ use deno_core::WebIDL;
17
21
use crate :: buffer:: GPUBuffer ;
18
22
use crate :: error:: GPUGenericError ;
19
23
use crate :: render_bundle:: GPURenderBundle ;
24
+ use crate :: texture:: GPUTexture ;
20
25
use crate :: texture:: GPUTextureView ;
21
26
use crate :: webidl:: GPUColor ;
22
27
use crate :: Instance ;
@@ -441,10 +446,10 @@ pub(crate) struct GPURenderPassDescriptor {
441
446
#[ derive( WebIDL ) ]
442
447
#[ webidl( dictionary) ]
443
448
pub ( crate ) struct GPURenderPassColorAttachment {
444
- pub view : Ptr < GPUTextureView > ,
449
+ pub view : GPUTextureOrView ,
445
450
#[ options( enforce_range = true ) ]
446
451
pub depth_slice : Option < u32 > ,
447
- pub resolve_target : Option < Ptr < GPUTextureView > > ,
452
+ pub resolve_target : Option < GPUTextureOrView > ,
448
453
pub clear_value : Option < GPUColor > ,
449
454
pub load_op : GPULoadOp ,
450
455
pub store_op : GPUStoreOp ,
@@ -495,7 +500,7 @@ impl From<GPUStoreOp> for wgpu_core::command::StoreOp {
495
500
#[ derive( WebIDL ) ]
496
501
#[ webidl( dictionary) ]
497
502
pub ( crate ) struct GPURenderPassDepthStencilAttachment {
498
- pub view : Ptr < GPUTextureView > ,
503
+ pub view : GPUTextureOrView ,
499
504
pub depth_clear_value : Option < f32 > ,
500
505
pub depth_load_op : Option < GPULoadOp > ,
501
506
pub depth_store_op : Option < GPUStoreOp > ,
@@ -519,3 +524,48 @@ pub(crate) struct GPURenderPassTimestampWrites {
519
524
#[ options( enforce_range = true ) ]
520
525
pub end_of_pass_write_index : Option < u32 > ,
521
526
}
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