@@ -67,7 +67,6 @@ pub(crate) async fn request_device_and_queue(
67
67
// TODO: Extensions
68
68
let mut mapped_limits = web_sys:: GpuLimits :: new ( ) ;
69
69
mapped_limits. max_bind_groups ( d. limits . max_bind_groups ) ;
70
- // TODO: Other fields
71
70
mapped_descriptor. limits ( & mapped_limits) ;
72
71
adapter. request_device_with_descriptor ( & mapped_descriptor)
73
72
}
@@ -109,35 +108,43 @@ pub(crate) fn create_bind_group_layout(
109
108
BindingType :: StorageTexture { .. } => bt:: WriteonlyStorageTexture ,
110
109
} ;
111
110
112
- let mapped_dynamic = match bind. ty {
111
+ let mut mapped_entry = web_sys:: GpuBindGroupLayoutEntry :: new (
112
+ bind. binding ,
113
+ mapped_type,
114
+ bind. visibility . bits ( ) ,
115
+ ) ;
116
+
117
+ match bind. ty {
113
118
BindingType :: UniformBuffer { dynamic }
114
- | BindingType :: StorageBuffer { dynamic, .. } => dynamic,
115
- _ => false ,
116
- } ;
119
+ | BindingType :: StorageBuffer { dynamic, .. } => {
120
+ mapped_entry. has_dynamic_offset ( dynamic) ;
121
+ }
122
+ _ => { }
123
+ }
117
124
118
- let mapped_multisampled = match bind. ty {
119
- BindingType :: SampledTexture { multisampled, .. } => multisampled,
120
- _ => false ,
121
- } ;
125
+ if let BindingType :: SampledTexture { multisampled, .. } = bind. ty {
126
+ mapped_entry. multisampled ( multisampled) ;
127
+ }
122
128
123
- let mapped_view_dimension = match bind. ty {
129
+ match bind. ty {
124
130
BindingType :: SampledTexture { dimension, .. }
125
131
| BindingType :: StorageTexture { dimension, .. } => {
126
- map_texture_view_dimension ( dimension)
132
+ mapped_entry . view_dimension ( map_texture_view_dimension ( dimension) ) ;
127
133
}
128
- _ => web_sys :: GpuTextureViewDimension :: N2d ,
129
- } ;
134
+ _ => { }
135
+ }
130
136
131
- let mut mapped_entry = web_sys:: GpuBindGroupLayoutEntry :: new (
132
- bind. binding ,
133
- mapped_type,
134
- bind. visibility . bits ( ) ,
135
- ) ;
136
- mapped_entry. has_dynamic_offset ( mapped_dynamic) ;
137
- mapped_entry. multisampled ( mapped_multisampled) ;
138
- mapped_entry. view_dimension ( mapped_view_dimension) ;
137
+ if let BindingType :: StorageTexture { format, .. } = bind. ty {
138
+ mapped_entry. storage_texture_format ( map_texture_format ( format) ) ;
139
+ }
139
140
140
- // TODO: Texture component type, storage texture format
141
+ match bind. ty {
142
+ BindingType :: SampledTexture { component_type, .. }
143
+ | BindingType :: StorageTexture { component_type, .. } => {
144
+ mapped_entry. texture_component_type ( map_texture_component_type ( component_type) ) ;
145
+ }
146
+ _ => { }
147
+ }
141
148
142
149
mapped_entry
143
150
} )
@@ -180,7 +187,6 @@ pub(crate) fn create_pipeline_layout(
180
187
device : & DeviceId ,
181
188
desc : & PipelineLayoutDescriptor ,
182
189
) -> PipelineLayoutId {
183
- //TODO: avoid allocation here
184
190
let temp_layouts = desc
185
191
. bind_group_layouts
186
192
. iter ( )
@@ -235,6 +241,16 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture
235
241
}
236
242
}
237
243
244
+ fn map_texture_component_type (
245
+ texture_component_type : wgt:: TextureComponentType ,
246
+ ) -> web_sys:: GpuTextureComponentType {
247
+ match texture_component_type {
248
+ wgt:: TextureComponentType :: Float => web_sys:: GpuTextureComponentType :: Float ,
249
+ wgt:: TextureComponentType :: Sint => web_sys:: GpuTextureComponentType :: Sint ,
250
+ wgt:: TextureComponentType :: Uint => web_sys:: GpuTextureComponentType :: Uint ,
251
+ }
252
+ }
253
+
238
254
fn map_stage_descriptor (
239
255
desc : & ProgrammableStageDescriptor ,
240
256
) -> web_sys:: GpuProgrammableStageDescriptor {
@@ -794,9 +810,7 @@ pub(crate) fn compute_pass_set_bind_group<'a>(
794
810
compute_pass. set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length (
795
811
index,
796
812
bind_group,
797
- // TODO: `offsets` currently requires `&mut` so we have to clone it
798
- // here, but this should be fixed upstream in web-sys in the future
799
- & mut offsets. to_vec ( ) ,
813
+ offsets,
800
814
0f64 ,
801
815
offsets. len ( ) as u32 ,
802
816
) ;
@@ -929,12 +943,26 @@ pub(crate) fn device_create_swap_chain(
929
943
surface. configure_swap_chain ( & mapped)
930
944
}
931
945
932
- pub ( crate ) fn swap_chain_get_next_texture ( swap_chain : & SwapChainId ) -> Option < TextureViewId > {
946
+ pub ( crate ) fn device_drop ( _device : & DeviceId ) {
947
+ // Device is dropped automatically
948
+ }
949
+
950
+ pub ( crate ) fn swap_chain_get_next_texture (
951
+ swap_chain : & SwapChainId ,
952
+ ) -> Result < crate :: SwapChainOutput , crate :: TimeOut > {
933
953
// TODO: Should we pass a descriptor here?
934
954
// Or is the default view always correct?
935
- Some ( swap_chain. get_current_texture ( ) . create_view ( ) )
955
+ Ok ( crate :: SwapChainOutput {
956
+ view : crate :: TextureView {
957
+ id : swap_chain. get_current_texture ( ) . create_view ( ) ,
958
+ owned : false ,
959
+ } ,
960
+ detail : ( ) ,
961
+ } )
936
962
}
937
963
964
+ pub ( crate ) type SwapChainOutputDetail = ( ) ;
965
+
938
966
fn map_store_op ( op : wgt:: StoreOp ) -> web_sys:: GpuStoreOp {
939
967
match op {
940
968
wgt:: StoreOp :: Clear => web_sys:: GpuStoreOp :: Clear ,
@@ -1012,9 +1040,7 @@ pub(crate) fn render_pass_set_bind_group(
1012
1040
render_pass. set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length (
1013
1041
index,
1014
1042
bind_group,
1015
- // TODO: `offsets` currently requires `&mut` so we have to clone it
1016
- // here, but this should be fixed upstream in web-sys in the future
1017
- & mut offsets. to_vec ( ) ,
1043
+ offsets,
1018
1044
0f64 ,
1019
1045
offsets. len ( ) as u32 ,
1020
1046
) ;
@@ -1024,28 +1050,19 @@ pub(crate) fn render_pass_set_index_buffer<'a>(
1024
1050
render_pass : & RenderPassEncoderId ,
1025
1051
buffer : & ' a crate :: Buffer ,
1026
1052
offset : wgt:: BufferAddress ,
1027
- _size : wgt:: BufferAddress ,
1053
+ size : wgt:: BufferAddress ,
1028
1054
) {
1029
- render_pass. set_index_buffer_with_f64 (
1030
- & buffer. id ,
1031
- offset as f64 ,
1032
- // TODO: size,
1033
- ) ;
1055
+ render_pass. set_index_buffer_with_f64_and_f64 ( & buffer. id , offset as f64 , size as f64 ) ;
1034
1056
}
1035
1057
1036
1058
pub ( crate ) fn render_pass_set_vertex_buffer < ' a > (
1037
1059
render_pass : & RenderPassEncoderId ,
1038
1060
slot : u32 ,
1039
1061
buffer : & ' a crate :: Buffer ,
1040
1062
offset : wgt:: BufferAddress ,
1041
- _size : wgt:: BufferAddress ,
1063
+ size : wgt:: BufferAddress ,
1042
1064
) {
1043
- render_pass. set_vertex_buffer_with_f64 (
1044
- slot,
1045
- & buffer. id ,
1046
- offset as f64 ,
1047
- // TODO: size,
1048
- ) ;
1065
+ render_pass. set_vertex_buffer_with_f64_and_f64 ( slot, & buffer. id , offset as f64 , size as f64 ) ;
1049
1066
}
1050
1067
1051
1068
pub ( crate ) fn render_pass_set_scissor_rect (
@@ -1151,7 +1168,11 @@ pub(crate) fn texture_view_drop(_texture_view: &TextureViewId) {
1151
1168
// Texture view is dropped automatically
1152
1169
}
1153
1170
1154
- pub ( crate ) fn swap_chain_present ( _swap_chain : & SwapChainId ) {
1171
+ pub ( crate ) fn bind_group_drop ( _bind_group : & BindGroupId ) {
1172
+ // Bind group is dropped automatically
1173
+ }
1174
+
1175
+ pub ( crate ) fn swap_chain_present ( _swap_chain_output : & crate :: SwapChainOutput ) {
1155
1176
// Swapchain is presented automatically
1156
1177
}
1157
1178
0 commit comments