// 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 #include // For strlen #if defined(DEMO_CROSS_COMPILE_WIN32) // Windows (MinGW) using wgpu-native v0.19.4.1 #define WGPUOptionalBool_True true #define WGPUOptionalBool_False false #include #include static inline const char* str_view(const char* str) { return str; } static inline const char* label_view(const char* str) { return str; } #define WGPUSType_ShaderSourceWGSL WGPUSType_ShaderModuleWGSLDescriptor using WGPUShaderSourceWGSL = WGPUShaderModuleWGSLDescriptor; #define WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal \ WGPUSurfaceGetCurrentTextureStatus_Success #define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ WGPUSurfaceGetCurrentTextureStatus_Success #define WGPUCallbackMode_WaitAnyOnly 0 #else // Native (macOS/Linux) using newer wgpu-native #include #include static inline WGPUStringView str_view(const char* str) { if (!str) return {nullptr, 0}; return {str, strlen(str)}; } static inline WGPUStringView label_view(const char* str) { #if !defined(STRIP_ALL) if (!str) return {nullptr, 0}; return {str, strlen(str)}; #else (void)str; return {nullptr, 0}; #endif /* !defined(STRIP_ALL) */ } #endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ 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); void gpu_shutdown(); // 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; #if !defined(DEMO_CROSS_COMPILE_WIN32) 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);