Skip to content

Commit

Permalink
Get some things closer to some samples
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 25, 2025
1 parent 3d7153d commit 7ca0b75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typedef struct kore_webgpu_buffer_access {
typedef struct kore_webgpu_command_list {
WGPUCommandEncoder command_encoder;
WGPURenderPassEncoder render_pass_encoder;
WGPUDevice device;
WGPUSwapChain swap_chain;
} kore_webgpu_command_list;

#ifdef __cplusplus
Expand Down
9 changes: 8 additions & 1 deletion backends/gpu/webgpu/sources/commandlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@
void kore_webgpu_command_list_destroy(kore_gpu_command_list *list) {}

void kore_webgpu_command_list_begin_render_pass(kore_gpu_command_list *list, const kore_gpu_render_pass_parameters *parameters) {
WGPUCommandEncoderDescriptor command_encoder_descriptor = {0};
list->webgpu.command_encoder = wgpuDeviceCreateCommandEncoder(list->webgpu.device, &command_encoder_descriptor);

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);
//WGPUTextureView texture_view = wgpuTextureCreateView(parameters->color_attachments[0].texture.texture->webgpu.texture, &texture_view_descriptor);

WGPUTextureView texture_view = wgpuSwapChainGetCurrentTextureView(list->webgpu.swap_chain);

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

WGPURenderPassDescriptor render_pass_descriptor = {
Expand All @@ -40,6 +46,7 @@ void kore_webgpu_command_list_begin_render_pass(kore_gpu_command_list *list, con

void kore_webgpu_command_list_end_render_pass(kore_gpu_command_list *list) {
wgpuRenderPassEncoderEnd(list->webgpu.render_pass_encoder);
wgpuRenderPassEncoderRelease(list->webgpu.render_pass_encoder);
}

void kore_webgpu_command_list_present(kore_gpu_command_list *list) {}
Expand Down
26 changes: 17 additions & 9 deletions backends/gpu/webgpu/sources/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ void kore_webgpu_device_create(kore_gpu_device *device, const kore_gpu_device_wi
.chain = {
.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector,
},
.selector = "canvas",
.selector = "#canvas",
};

WGPUSurfaceDescriptor surface_descriptor = {
.nextInChain = (WGPUChainedStruct *)&canvas_selector,
};

WGPUInstance instance = 0;
WGPUInstance instance = wgpuCreateInstance(NULL);
WGPUSurface surface = wgpuInstanceCreateSurface(instance, &surface_descriptor);

WGPUSwapChainDescriptor swap_chain_descriptor = {
.usage = WGPUTextureUsage_RenderAttachment,
.format = WGPUTextureFormat_BGRA8Unorm,
.width = kore_window_width(0),
.height = kore_window_height(0),
.width = 800,// kore_window_width(0),
.height = 600,//kore_window_height(0),
.presentMode = WGPUPresentMode_Fifo,
};
device->webgpu.swap_chain = wgpuDeviceCreateSwapChain(device->webgpu.device, surface, &swap_chain_descriptor);
Expand Down Expand Up @@ -106,16 +106,19 @@ void kore_webgpu_device_create_buffer(kore_gpu_device *device, const kore_gpu_bu
WGPUBufferDescriptor buffer_descriptor = {
.size = align_pow2(parameters->size, 4),
.usage = convert_buffer_usage(parameters->usage_flags),
.mappedAtCreation = true,
//.mappedAtCreation = true,
};

buffer->webgpu.buffer = wgpuDeviceCreateBuffer(device->webgpu.device, &buffer_descriptor);
buffer->webgpu.size = parameters->size;
buffer->webgpu.size = align_pow2(parameters->size, 4);
}

void kore_webgpu_device_create_command_list(kore_gpu_device *device, kore_gpu_command_list_type type, kore_gpu_command_list *list) {
WGPUCommandEncoderDescriptor command_encoder_descriptor = {0};
list->webgpu.command_encoder = wgpuDeviceCreateCommandEncoder(device->webgpu.device, &command_encoder_descriptor);

list->webgpu.device = device->webgpu.device;
list->webgpu.swap_chain = device->webgpu.swap_chain;
}

void kore_webgpu_device_create_texture(kore_gpu_device *device, const kore_gpu_texture_parameters *parameters, kore_gpu_texture *texture) {
Expand Down Expand Up @@ -145,17 +148,22 @@ kore_gpu_texture *kore_webgpu_device_get_framebuffer(kore_gpu_device *device) {
}

kore_gpu_texture_format kore_webgpu_device_framebuffer_format(kore_gpu_device *device) {
return KORE_GPU_TEXTURE_FORMAT_RGBA8_UNORM;
return KORE_GPU_TEXTURE_FORMAT_BGRA8_UNORM;
}

void kore_webgpu_device_execute_command_list(kore_gpu_device *device, kore_gpu_command_list *list) {
WGPUCommandBufferDescriptor command_buffer_descriptor = {0};

WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(list->webgpu.command_encoder, &command_buffer_descriptor);
wgpuCommandEncoderRelease(list->webgpu.command_encoder);

wgpuQueueSubmit(device->webgpu.queue, 1, &command_buffer);
wgpuCommandBufferRelease(command_buffer);

WGPUCommandEncoderDescriptor command_encoder_descriptor = {0};
list->webgpu.command_encoder = wgpuDeviceCreateCommandEncoder(device->webgpu.device, &command_encoder_descriptor);
//emscripten_sleep(100);

//WGPUCommandEncoderDescriptor command_encoder_descriptor = {0};
//list->webgpu.command_encoder = wgpuDeviceCreateCommandEncoder(device->webgpu.device, &command_encoder_descriptor);
}

void kore_webgpu_device_wait_until_idle(kore_gpu_device *device) {}
Expand Down

0 comments on commit 7ca0b75

Please sign in to comment.