1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// This file is part of the 64k demo project.
// It defines the public interface for the GPU rendering system.
// Coordinates WebGPU lifecycle and draw calls.
#pragma once
#include "platform.h"
struct PlatformState; // Forward declaration
// Basic wrapper for WebGPU buffers
struct GpuBuffer {
WGPUBuffer buffer;
size_t size;
};
// Encapsulates a compute operation
struct ComputePass {
WGPUComputePipeline pipeline;
WGPUBindGroup bind_group;
uint32_t workgroup_size_x;
uint32_t workgroup_size_y;
uint32_t workgroup_size_z;
};
// Encapsulates a render operation
struct RenderPass {
WGPURenderPipeline pipeline;
WGPUBindGroup bind_group;
uint32_t vertex_count;
uint32_t instance_count;
};
void gpu_init(PlatformState* platform_state);
void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat);
void gpu_resize(int width, int height);
#if !defined(STRIP_ALL)
void gpu_simulate_until(float time);
#endif
void gpu_shutdown();
// Placeholder for GPU performance capture.
// This define can be controlled via CMake to conditionally enable profiling
// code. #define ENABLE_GPU_PERF_CAPTURE
// Helper functions (exposed for internal/future use)
struct ResourceBinding {
GpuBuffer buffer;
WGPUBufferBindingType type; // e.g., WGPUBufferBindingType_Uniform,
// WGPUBufferBindingType_Storage
};
// Cross-platform helper for color attachment initialization
inline void gpu_init_color_attachment(WGPURenderPassColorAttachment& attachment,
WGPUTextureView view) {
attachment.view = view;
attachment.loadOp = WGPULoadOp_Clear;
attachment.storeOp = WGPUStoreOp_Store;
attachment.clearValue = {0.0f, 0.0f, 0.0f, 1.0f};
#if defined(DEMO_CROSS_COMPILE_WIN32)
// depthSlice is handled via macro in platform.h if needed,
// but usually it's better to just avoid setting it on older wgpu-native
#else
attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
#endif
}
GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage,
const void* data = nullptr);
ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code,
ResourceBinding* bindings,
int num_bindings);
RenderPass
gpu_create_render_pass(WGPUDevice device,
WGPUTextureFormat format, // Needed for render pipeline
const char* shader_code, ResourceBinding* bindings,
int num_bindings);
|