@@ -41,21 +41,22 @@ namespace ice::render::webgpu
4141 ice::render::RenderSurface* surface
4242 ) noexcept -> ice::render::RenderSwapchain*
4343 {
44- WebGPURenderSurface* webgpu_surface = static_cast <WebGPURenderSurface*>(surface);
45- ice::platform::RenderSurface* render_surface = reinterpret_cast <ice::platform::RenderSurface*>(webgpu_surface->_surface_info .webgpu .internal );
46- ice::vec2u surface_dimensions = render_surface->get_dimensions ();
47-
48- WGPUSwapChainDescriptor descriptor{};
49- descriptor.label = " Default Swapchain" ;
50- descriptor.presentMode = WGPUPresentMode_Fifo;
51- descriptor.usage = WGPUTextureUsage_RenderAttachment;
52- descriptor.width = surface_dimensions.x ;
53- descriptor.height = surface_dimensions.y ;
54- descriptor.format = webgpu_surface->_wgpu_surface_format ;
55- WGPUSwapChain swapchain = wgpuDeviceCreateSwapChain (_wgpu_device, webgpu_surface->_wgpu_surface , &descriptor);
44+ WebGPURenderSurface* const webgpu_surface = static_cast <WebGPURenderSurface*>(surface);
45+ ice::platform::RenderSurface* const render_surface = reinterpret_cast <ice::platform::RenderSurface*>(webgpu_surface->_surface_info .webgpu .internal );
46+ ice::vec2u const surface_dimensions = render_surface->get_dimensions ();
47+
48+ WGPUSurfaceConfiguration config = WGPU_SURFACE_CONFIGURATION_INIT;
49+ config.device = _wgpu_device;
50+ config.format = webgpu_surface->_wgpu_surface_format ;
51+ config.width = surface_dimensions.x ;
52+ config.height = surface_dimensions.y ;
53+ config.usage = WGPUTextureUsage_RenderAttachment;
54+ config.presentMode = webgpu_surface->_wgpu_present_mode ;
55+ config.alphaMode = WGPUCompositeAlphaMode_Auto;
56+ wgpuSurfaceConfigure (webgpu_surface->_wgpu_surface , &config);
5657
5758 ICE_ASSERT (surface != nullptr , " Invalid render surface object!" );
58- return _allocator.create <WebGPUSwapchain>(swapchain , webgpu_surface->_wgpu_surface_format , surface_dimensions);
59+ return _allocator.create <WebGPUSwapchain>(webgpu_surface-> _wgpu_surface , webgpu_surface->_wgpu_surface_format , surface_dimensions);
5960 }
6061
6162 void WebGPUDevice::destroy_swapchain (
@@ -85,8 +86,8 @@ namespace ice::render::webgpu
8586 {
8687 WGPUBindGroupLayoutEntry entries[16 ]{};
8788
88- WGPUBindGroupLayoutDescriptor descriptor{} ;
89- descriptor.label = " Resource Set Layout" ;
89+ WGPUBindGroupLayoutDescriptor descriptor = WGPU_BIND_GROUP_LAYOUT_DESCRIPTOR_INIT ;
90+ descriptor.label = wgpu_string ( " Resource Set Layout" ) ;
9091 descriptor.entryCount = ice::count (bindings);
9192 descriptor.entries = entries;
9293 ICE_ASSERT_CORE (descriptor.entryCount <= 16 );
@@ -166,8 +167,8 @@ namespace ice::render::webgpu
166167 if (current_set != set_info.resource_set )
167168 {
168169 WebGPUResourceSet* native = WebGPUResourceSet::native (current_set);
169- WGPUBindGroupDescriptor descriptor{} ;
170- descriptor.label = " Resource Set" ;
170+ WGPUBindGroupDescriptor descriptor = WGPU_BIND_GROUP_DESCRIPTOR_INIT ;
171+ descriptor.label = wgpu_string ( " Resource Set" ) ;
171172 descriptor.layout = native->_wgpu_group_layout ;
172173 descriptor.entries = entries;
173174 descriptor.entryCount = idx;
@@ -186,7 +187,7 @@ namespace ice::render::webgpu
186187 for (ResourceUpdateInfo const & info : set_info.resources )
187188 {
188189 WGPUBindGroupEntry& entry = entries[idx];
189- entry = WGPUBindGroupEntry{} ;
190+ entry = WGPU_BIND_GROUP_ENTRY_INIT ;
190191 entry.binding = set_info.binding_index ;
191192
192193 switch (set_info.resource_type )
@@ -216,8 +217,8 @@ namespace ice::render::webgpu
216217 if (idx > 0 )
217218 {
218219 WebGPUResourceSet* native = WebGPUResourceSet::native (current_set);
219- WGPUBindGroupDescriptor descriptor{} ;
220- descriptor.label = " Resource Set" ;
220+ WGPUBindGroupDescriptor descriptor = WGPU_BIND_GROUP_DESCRIPTOR_INIT ;
221+ descriptor.label = wgpu_string ( " Resource Set" ) ;
221222 descriptor.layout = native->_wgpu_group_layout ;
222223 descriptor.entries = entries;
223224 descriptor.entryCount = idx;
@@ -262,8 +263,8 @@ namespace ice::render::webgpu
262263 count += 1 ;
263264 }
264265
265- WGPUPipelineLayoutDescriptor descriptor{} ;
266- descriptor.label = " Pipeline Layout" ;
266+ WGPUPipelineLayoutDescriptor descriptor = WGPU_PIPELINE_LAYOUT_DESCRIPTOR_INIT ;
267+ descriptor.label = wgpu_string ( " Pipeline Layout" ) ;
267268 descriptor.bindGroupLayoutCount = count;
268269 descriptor.bindGroupLayouts = layouts;
269270
@@ -285,13 +286,11 @@ namespace ice::render::webgpu
285286 char const * code = reinterpret_cast <char const *>(shader_info.shader_data .location );
286287 ICE_ASSERT_CORE (code[shader_info.shader_data .size .value - 1 ] == ' \0 ' );
287288
288- WGPUShaderModuleWGSLDescriptor wgsl_descriptor{};
289- wgsl_descriptor.chain .sType = WGPUSType_ShaderModuleWGSLDescriptor;
290- wgsl_descriptor.chain .next = nullptr ;
291- wgsl_descriptor.code = code;
289+ WGPUShaderSourceWGSL wgsl_descriptor = WGPU_SHADER_SOURCE_WGSL_INIT;
290+ wgsl_descriptor.code = wgpu_string (code);
292291
293- WGPUShaderModuleDescriptor descriptor{} ;
294- descriptor.label = " Shader" ;
292+ WGPUShaderModuleDescriptor descriptor = WGPU_SHADER_MODULE_DESCRIPTOR_INIT ;
293+ descriptor.label = wgpu_string ( " Shader" ) ;
295294 descriptor.nextInChain = &wgsl_descriptor.chain ;
296295
297296 WGPUShaderModule shader = wgpuDeviceCreateShaderModule (_wgpu_device, &descriptor);
@@ -339,12 +338,12 @@ namespace ice::render::webgpu
339338 binding_count += 1 ;
340339 }
341340
342- WGPUVertexState vertex{} ;
343- vertex.entryPoint = " main" ;
341+ WGPUVertexState vertex = WGPU_VERTEX_STATE_INIT ;
342+ vertex.entryPoint = wgpu_string ( " main" ) ;
344343 vertex.bufferCount = binding_count;
345344 vertex.buffers = bindings;
346345
347- WGPUBlendState blend{} ;
346+ WGPUBlendState blend = WGPU_BLEND_STATE_INIT ;
348347 blend.color .srcFactor = WGPUBlendFactor_SrcAlpha;
349348 blend.color .dstFactor = WGPUBlendFactor_OneMinusSrcAlpha;
350349 blend.color .operation = WGPUBlendOperation_Add;
@@ -353,8 +352,8 @@ namespace ice::render::webgpu
353352 blend.alpha .operation = WGPUBlendOperation_Add;
354353
355354 WGPUColorTargetState targets[4 ]{};
356- WGPUFragmentState fragment{} ;
357- fragment.entryPoint = " main" ;
355+ WGPUFragmentState fragment = WGPU_FRAGMENT_STATE_INIT ;
356+ fragment.entryPoint = wgpu_string ( " main" ) ;
358357 fragment.targetCount = 0 ;
359358 fragment.targets = targets;
360359
@@ -375,11 +374,11 @@ namespace ice::render::webgpu
375374 {
376375 case ShaderStageFlags::VertexStage:
377376 vertex.module = WebGPUShader::native (program.shader )->_wgpu_shader ;
378- vertex.entryPoint = ice::string::begin (program.entry_point );
377+ vertex.entryPoint = wgpu_string ( ice::string::begin (program.entry_point ) );
379378 break ;
380379 case ShaderStageFlags::FragmentStage:
381380 fragment.module = WebGPUShader::native (program.shader )->_wgpu_shader ;
382- fragment.entryPoint = ice::string::begin (program.entry_point );
381+ fragment.entryPoint = wgpu_string ( ice::string::begin (program.entry_point ) );
383382 break ;
384383 default :
385384 ICE_ASSERT_CORE (false );
@@ -406,8 +405,8 @@ namespace ice::render::webgpu
406405 // depthstencil.back.writeMask = 0;
407406 // depthstencil.front = depthstencil.back;
408407
409- WGPURenderPipelineDescriptor descriptor{} ;
410- descriptor.label = " Render Pipeline" ;
408+ WGPURenderPipelineDescriptor descriptor = WGPU_RENDER_PIPELINE_DESCRIPTOR_INIT ;
409+ descriptor.label = wgpu_string ( " Render Pipeline" ) ;
411410 descriptor.layout = WebGPUPipeline::native (info.layout );
412411 descriptor.multisample .alphaToCoverageEnabled = false ;
413412 descriptor.multisample .count = 1 ;
@@ -435,7 +434,7 @@ namespace ice::render::webgpu
435434 ice::u32 buffer_size
436435 ) noexcept -> ice::render::Buffer
437436 {
438- WGPUBufferUsageFlags flags = WGPUBufferUsage_CopyDst;
437+ WGPUBufferUsage flags = WGPUBufferUsage_CopyDst;
439438 switch (buffer_type)
440439 {
441440 case BufferType::Index:
@@ -452,8 +451,8 @@ namespace ice::render::webgpu
452451 break ;
453452 }
454453
455- WGPUBufferDescriptor descriptor{} ;
456- descriptor.label = " Buffer" ;
454+ WGPUBufferDescriptor descriptor = WGPU_BUFFER_DESCRIPTOR_INIT ;
455+ descriptor.label = wgpu_string ( " Buffer" ) ;
457456 descriptor.mappedAtCreation = false ;
458457 descriptor.size = buffer_size;
459458 descriptor.usage = flags;
@@ -520,8 +519,8 @@ namespace ice::render::webgpu
520519 {
521520 ICE_ASSERT_CORE (image_info.type == ImageType::Image2D);
522521
523- WGPUTextureDescriptor descriptor{} ;
524- descriptor.label = " Texture" ;
522+ WGPUTextureDescriptor descriptor = WGPU_TEXTURE_DESCRIPTOR_INIT ;
523+ descriptor.label = wgpu_string ( " Texture" ) ;
525524 descriptor.dimension = WGPUTextureDimension_2D;
526525 descriptor.usage = native_usage (image_info.usage );
527526 descriptor.format = native_format (image_info.format );
@@ -535,22 +534,22 @@ namespace ice::render::webgpu
535534
536535 if (data.location != nullptr && data.size > 0_B)
537536 {
538- WGPUImageCopyTexture copy_info{};
537+ WGPUTexelCopyTextureInfo copy_info{};
539538 copy_info.mipLevel = 0 ;
540539 copy_info.texture = texture;
541540 copy_info.origin = { 0 , 0 , 0 };
542541 copy_info.aspect = WGPUTextureAspect_All;
543542
544- WGPUTextureDataLayout layout{};
543+ WGPUTexelCopyBufferLayout layout{};
545544 layout.offset = 0 ;
546545 layout.bytesPerRow = image_info.width * 4 ;
547546 layout.rowsPerImage = image_info.height ;
548547
549548 wgpuQueueWriteTexture (_wgpu_queue, ©_info, data.location , data.size .value , &layout, &descriptor.size );
550549 }
551550
552- WGPUTextureViewDescriptor view_descriptor{} ;
553- view_descriptor.label = " " ;
551+ WGPUTextureViewDescriptor view_descriptor = WGPU_TEXTURE_VIEW_DESCRIPTOR_INIT ;
552+ view_descriptor.label = wgpu_string ( " " ) ;
554553 view_descriptor.dimension = WGPUTextureViewDimension_2D;
555554 view_descriptor.format = descriptor.format ;
556555 view_descriptor.mipLevelCount = descriptor.mipLevelCount ;
@@ -578,11 +577,11 @@ namespace ice::render::webgpu
578577 ice::render::SamplerInfo const & sampler_info
579578 ) noexcept -> ice::render::Sampler
580579 {
581- WGPUSamplerDescriptor descriptor{} ;
580+ WGPUSamplerDescriptor descriptor = WGPU_SAMPLER_DESCRIPTOR_INIT ;
582581 descriptor.addressModeU = native_address_mode (sampler_info.address_mode .u );
583582 descriptor.addressModeV = native_address_mode (sampler_info.address_mode .v );
584583 descriptor.addressModeW = native_address_mode (sampler_info.address_mode .w );
585- descriptor.label = " Sampler" ;
584+ descriptor.label = wgpu_string ( " Sampler" ) ;
586585 descriptor.magFilter = native_filter (sampler_info.mag_filter );
587586 descriptor.minFilter = native_filter (sampler_info.min_filter );
588587 descriptor.mipmapFilter = native_mipmap_mode (sampler_info.mip_map_mode );
@@ -610,7 +609,7 @@ namespace ice::render::webgpu
610609 ) const noexcept -> ice::render::RenderQueue*
611610 {
612611 WGPUQueue queue = wgpuDeviceGetQueue (_wgpu_device);
613- wgpuQueueReference (queue);
612+ wgpuQueueAddRef (queue);
614613 return _allocator.create <WebGPUQueue>(_allocator, _wgpu_device, queue);
615614 }
616615
0 commit comments