Skip to content

Commit

Permalink
Almost make WebGPU work
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 25, 2025
1 parent 181a4a4 commit d0c8b9d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
3 changes: 2 additions & 1 deletion backends/gpu/webgpu/sources/commandlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ void kore_webgpu_command_list_begin_render_pass(kore_gpu_command_list *list, con
WGPUTextureViewDescriptor texture_view_descriptor = {
.format = WGPUTextureFormat_BGRA8Unorm,
.dimension = WGPUTextureViewDimension_2D,
.arrayLayerCount = 1,
};
WGPUTextureView texture_view = wgpuTextureCreateView(parameters->color_attachments[0].texture.texture->webgpu.texture, &texture_view_descriptor);

WGPURenderPassColorAttachment color_attachment = {
.view = texture_view,
.loadOp = WGPULoadOp_Clear,
.storeOp = WGPUStoreOp_Store,
.clearValue = {0, 0, 0, 1},
.clearValue = {0.5, 0, 0, 1},
};

WGPURenderPassDescriptor render_pass_descriptor = {
Expand Down
4 changes: 3 additions & 1 deletion backends/gpu/webgpu/sources/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void kore_webgpu_device_create(kore_gpu_device *device, const kore_gpu_device_wi
#ifdef KORE_EMSCRIPTEN
device->webgpu.device = emscripten_webgpu_get_device();
#endif
wgpuDevicePushErrorScope(device->webgpu.device, WGPUErrorFilter_Validation);

device->webgpu.queue = wgpuDeviceGetQueue(device->webgpu.device);

WGPUSurfaceDescriptorFromCanvasHTMLSelector canvas_selector = {
Expand Down Expand Up @@ -102,7 +104,7 @@ static WGPUBufferUsage convert_buffer_usage(kore_gpu_buffer_usage usage) {

void kore_webgpu_device_create_buffer(kore_gpu_device *device, const kore_gpu_buffer_parameters *parameters, kore_gpu_buffer *buffer) {
WGPUBufferDescriptor buffer_descriptor = {
.size = parameters->size,
.size = align_pow2(parameters->size, 4),
.usage = convert_buffer_usage(parameters->usage_flags),
.mappedAtCreation = true,
};
Expand Down
64 changes: 32 additions & 32 deletions backends/gpu/webgpu/sources/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,65 @@ static WGPUVertexFormat convert_vertex_format(kore_webgpu_vertex_format format)
case KORE_WEBGPU_VERTEX_FORMAT_UINT8X2:
return WGPUVertexFormat_Uint8x2;
case KORE_WEBGPU_VERTEX_FORMAT_UINT8X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint8x4;
case KORE_WEBGPU_VERTEX_FORMAT_SINT8X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint8x2;
case KORE_WEBGPU_VERTEX_FORMAT_SINT8X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint8x4;
case KORE_WEBGPU_VERTEX_FORMAT_UNORM8X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Unorm8x2;
case KORE_WEBGPU_VERTEX_FORMAT_UNORM8X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Unorm8x4;
case KORE_WEBGPU_VERTEX_FORMAT_SNORM8X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Snorm8x2;
case KORE_WEBGPU_VERTEX_FORMAT_SNORM8X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Snorm8x4;
case KORE_WEBGPU_VERTEX_FORMAT_UINT16X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint16x2;
case KORE_WEBGPU_VERTEX_FORMAT_UINT16X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint16x4;
case KORE_WEBGPU_VERTEX_FORMAT_SINT16X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint16x2;
case KORE_WEBGPU_VERTEX_FORMAT_SINT16X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint16x4;
case KORE_WEBGPU_VERTEX_FORMAT_UNORM16X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Unorm16x2;
case KORE_WEBGPU_VERTEX_FORMAT_UNORM16X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Unorm16x4;
case KORE_WEBGPU_VERTEX_FORMAT_SNORM16X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Snorm16x2;
case KORE_WEBGPU_VERTEX_FORMAT_SNORM16X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Snorm16x4;
case KORE_WEBGPU_VERTEX_FORMAT_FLOAT16X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Float16x2;
case KORE_WEBGPU_VERTEX_FORMAT_FLOAT16X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Float16x4;
case KORE_WEBGPU_VERTEX_FORMAT_FLOAT32:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Float32;
case KORE_WEBGPU_VERTEX_FORMAT_FLOAT32X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Float32x2;
case KORE_WEBGPU_VERTEX_FORMAT_FLOAT32X3:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Float32x3;
case KORE_WEBGPU_VERTEX_FORMAT_FLOAT32X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Float32x4;
case KORE_WEBGPU_VERTEX_FORMAT_UINT32:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint32;
case KORE_WEBGPU_VERTEX_FORMAT_UINT32X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint32x2;
case KORE_WEBGPU_VERTEX_FORMAT_UINT32X3:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint32x3;
case KORE_WEBGPU_VERTEX_FORMAT_UINT32X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Uint32x4;
case KORE_WEBGPU_VERTEX_FORMAT_SIN32:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint32;
case KORE_WEBGPU_VERTEX_FORMAT_SINT32X2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint32x2;
case KORE_WEBGPU_VERTEX_FORMAT_SINT32X3:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint32x3;
case KORE_WEBGPU_VERTEX_FORMAT_SINT32X4:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Sint32x4;
case KORE_WEBGPU_VERTEX_FORMAT_UNORM10_10_10_2:
return WGPUVertexFormat_Uint8x2;
return WGPUVertexFormat_Unorm10_10_10_2;
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ void kore_webgpu_render_pipeline_init(kore_webgpu_device *device, kore_webgpu_re

WGPUPrimitiveState primitive_state = {
.topology = WGPUPrimitiveTopology_TriangleList,
.stripIndexFormat = WGPUIndexFormat_Uint32,
//.stripIndexFormat = WGPUIndexFormat_Uint32,
.frontFace = WGPUFrontFace_CW,
.cullMode = WGPUCullMode_None,
};
Expand All @@ -143,7 +143,7 @@ void kore_webgpu_render_pipeline_init(kore_webgpu_device *device, kore_webgpu_re
WGPURenderPipelineDescriptor render_pipeline_descriptor = {
.layout = wgpuDeviceCreatePipelineLayout(device->device, &pipeline_layout_descriptor),
.fragment = &fragment_state,
.vertex = (WGPUChainedStruct *)&vertex_state,
.vertex = vertex_state,
.multisample = multisample_state,
.primitive = primitive_state,
};
Expand Down

0 comments on commit d0c8b9d

Please sign in to comment.