@@ -533,6 +533,10 @@ fn map_address_mode(mode: wgt::AddressMode) -> web_sys::GpuAddressMode {
533
533
}
534
534
}
535
535
536
+ fn map_color ( color : wgt:: Color ) -> web_sys:: GpuColorDict {
537
+ web_sys:: GpuColorDict :: new ( color. a , color. b , color. g , color. r )
538
+ }
539
+
536
540
pub ( crate ) fn create_render_pipeline (
537
541
device : & DeviceId ,
538
542
desc : & RenderPipelineDescriptor ,
@@ -665,6 +669,10 @@ pub(crate) fn buffer_unmap(buffer: &BufferId) {
665
669
buffer. unmap ( ) ;
666
670
}
667
671
672
+ pub ( crate ) fn buffer_drop ( _buffer : & BufferId ) {
673
+ // Buffer is dropped automatically
674
+ }
675
+
668
676
pub ( crate ) fn device_create_buffer ( device : & DeviceId , desc : & BufferDescriptor ) -> crate :: Buffer {
669
677
let mapped_desc = web_sys:: GpuBufferDescriptor :: new ( desc. size as f64 , desc. usage . bits ( ) ) ;
670
678
crate :: Buffer {
@@ -752,6 +760,19 @@ pub(crate) fn command_encoder_copy_texture_to_buffer(
752
760
) ;
753
761
}
754
762
763
+ pub ( crate ) fn command_encoder_copy_texture_to_texture (
764
+ command_encoder : & CommandEncoderId ,
765
+ source : crate :: TextureCopyView ,
766
+ destination : crate :: TextureCopyView ,
767
+ copy_size : wgt:: Extent3d ,
768
+ ) {
769
+ command_encoder. copy_texture_to_texture_with_gpu_extent_3d_dict (
770
+ & map_texture_copy_view ( source) ,
771
+ & map_texture_copy_view ( destination) ,
772
+ & map_extent_3d ( copy_size) ,
773
+ ) ;
774
+ }
775
+
755
776
pub ( crate ) fn begin_compute_pass ( command_encoder : & CommandEncoderId ) -> ComputePassId {
756
777
let mapped_desc = web_sys:: GpuComputePassDescriptor :: new ( ) ;
757
778
command_encoder. begin_compute_pass_with_descriptor ( & mapped_desc)
@@ -831,6 +852,26 @@ pub(crate) async fn buffer_map_read(
831
852
} )
832
853
}
833
854
855
+ pub ( crate ) async fn buffer_map_write (
856
+ buffer : & crate :: Buffer ,
857
+ _start : wgt:: BufferAddress ,
858
+ _size : wgt:: BufferAddress ,
859
+ ) -> Result < crate :: BufferWriteMapping , crate :: BufferAsyncErr > {
860
+ let array_buffer_promise = buffer. id . map_write_async ( ) ;
861
+ let array_buffer: js_sys:: ArrayBuffer =
862
+ wasm_bindgen_futures:: JsFuture :: from ( array_buffer_promise)
863
+ . await
864
+ . expect ( "Unable to map buffer" )
865
+ . into ( ) ;
866
+ let view = js_sys:: Uint8Array :: new ( & array_buffer) ;
867
+ Ok ( crate :: BufferWriteMapping {
868
+ detail : BufferWriteMappingDetail {
869
+ buffer_id : buffer. id . clone ( ) ,
870
+ mapped : view. to_vec ( ) ,
871
+ } ,
872
+ } )
873
+ }
874
+
834
875
pub ( crate ) struct BufferReadMappingDetail {
835
876
pub ( crate ) buffer_id : BufferId ,
836
877
mapped : Vec < u8 > ,
@@ -842,6 +883,17 @@ impl BufferReadMappingDetail {
842
883
}
843
884
}
844
885
886
+ pub ( crate ) struct BufferWriteMappingDetail {
887
+ pub ( crate ) buffer_id : BufferId ,
888
+ mapped : Vec < u8 > ,
889
+ }
890
+
891
+ impl BufferWriteMappingDetail {
892
+ pub ( crate ) fn as_slice ( & mut self ) -> & mut [ u8 ] {
893
+ & mut self . mapped [ ..]
894
+ }
895
+ }
896
+
845
897
pub ( crate ) fn device_create_surface < W : raw_window_handle:: HasRawWindowHandle > (
846
898
window : & W ,
847
899
) -> SurfaceId {
@@ -901,12 +953,7 @@ pub(crate) fn command_encoder_begin_render_pass<'a>(
901
953
let mut mapped_color_attachment = web_sys:: GpuRenderPassColorAttachmentDescriptor :: new (
902
954
& ca. attachment . id ,
903
955
& match ca. load_op {
904
- wgt:: LoadOp :: Clear => {
905
- let color = ca. clear_color ;
906
- let mapped_color =
907
- web_sys:: GpuColorDict :: new ( color. a , color. b , color. g , color. r ) ;
908
- wasm_bindgen:: JsValue :: from ( mapped_color)
909
- }
956
+ wgt:: LoadOp :: Clear => wasm_bindgen:: JsValue :: from ( map_color ( ca. clear_color ) ) ,
910
957
wgt:: LoadOp :: Load => wasm_bindgen:: JsValue :: from ( web_sys:: GpuLoadOp :: Load ) ,
911
958
} ,
912
959
) ;
@@ -952,6 +999,10 @@ pub(crate) fn render_pass_set_pipeline(
952
999
render_pass. set_pipeline ( & pipeline) ;
953
1000
}
954
1001
1002
+ pub ( crate ) fn render_pass_set_blend_color ( render_pass : & RenderPassEncoderId , color : wgt:: Color ) {
1003
+ render_pass. set_blend_color_with_gpu_color_dict ( & map_color ( color) ) ;
1004
+ }
1005
+
955
1006
pub ( crate ) fn render_pass_set_bind_group (
956
1007
render_pass : & RenderPassEncoderId ,
957
1008
index : u32 ,
@@ -997,6 +1048,32 @@ pub(crate) fn render_pass_set_vertex_buffer<'a>(
997
1048
) ;
998
1049
}
999
1050
1051
+ pub ( crate ) fn render_pass_set_scissor_rect (
1052
+ render_pass : & RenderPassEncoderId ,
1053
+ x : u32 ,
1054
+ y : u32 ,
1055
+ width : u32 ,
1056
+ height : u32 ,
1057
+ ) {
1058
+ render_pass. set_scissor_rect ( x, y, width, height) ;
1059
+ }
1060
+
1061
+ pub ( crate ) fn render_pass_set_viewport (
1062
+ render_pass : & RenderPassEncoderId ,
1063
+ x : f32 ,
1064
+ y : f32 ,
1065
+ width : f32 ,
1066
+ height : f32 ,
1067
+ min_depth : f32 ,
1068
+ max_depth : f32 ,
1069
+ ) {
1070
+ render_pass. set_viewport ( x, y, width, height, min_depth, max_depth) ;
1071
+ }
1072
+
1073
+ pub ( crate ) fn render_pass_set_stencil_reference ( render_pass : & RenderPassEncoderId , reference : u32 ) {
1074
+ render_pass. set_stencil_reference ( reference) ;
1075
+ }
1076
+
1000
1077
pub ( crate ) fn render_pass_draw (
1001
1078
render_pass : & RenderPassEncoderId ,
1002
1079
vertices : Range < u32 > ,
@@ -1026,6 +1103,22 @@ pub(crate) fn render_pass_draw_indexed(
1026
1103
) ;
1027
1104
}
1028
1105
1106
+ pub ( crate ) fn render_pass_draw_indirect < ' a > (
1107
+ render_pass : & RenderPassEncoderId ,
1108
+ indirect_buffer : & ' a crate :: Buffer ,
1109
+ indirect_offset : wgt:: BufferAddress ,
1110
+ ) {
1111
+ render_pass. draw_indirect_with_f64 ( & indirect_buffer. id , indirect_offset as f64 ) ;
1112
+ }
1113
+
1114
+ pub ( crate ) fn render_pass_draw_indexed_indirect < ' a > (
1115
+ render_pass : & RenderPassEncoderId ,
1116
+ indirect_buffer : & ' a crate :: Buffer ,
1117
+ indirect_offset : wgt:: BufferAddress ,
1118
+ ) {
1119
+ render_pass. draw_indexed_indirect_with_f64 ( & indirect_buffer. id , indirect_offset as f64 ) ;
1120
+ }
1121
+
1029
1122
pub ( crate ) fn render_pass_end_pass ( render_pass : & RenderPassEncoderId ) {
1030
1123
render_pass. end_pass ( ) ;
1031
1124
}
@@ -1050,6 +1143,14 @@ pub(crate) fn texture_create_view(
1050
1143
}
1051
1144
}
1052
1145
1146
+ pub ( crate ) fn texture_drop ( _texture : & TextureId ) {
1147
+ // Texture is dropped automatically
1148
+ }
1149
+
1150
+ pub ( crate ) fn texture_view_drop ( _texture_view : & TextureViewId ) {
1151
+ // Texture view is dropped automatically
1152
+ }
1153
+
1053
1154
pub ( crate ) fn swap_chain_present ( _swap_chain : & SwapChainId ) {
1054
1155
// Swapchain is presented automatically
1055
1156
}
0 commit comments