diff options
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/headless_platform.cc | 60 | ||||
| -rw-r--r-- | src/platform/platform.h | 5 | ||||
| -rw-r--r-- | src/platform/stub_platform.cc | 53 | ||||
| -rw-r--r-- | src/platform/stub_types.h | 159 |
4 files changed, 276 insertions, 1 deletions
diff --git a/src/platform/headless_platform.cc b/src/platform/headless_platform.cc new file mode 100644 index 0000000..4ec8c5d --- /dev/null +++ b/src/platform/headless_platform.cc @@ -0,0 +1,60 @@ +// Headless platform - time simulation without window +// Workspace: demo (shared across all workspaces) + +#if defined(DEMO_HEADLESS) + +#include "platform.h" +#include "stub_types.h" +#include <stdio.h> + +static double g_virtual_time = 0.0; +static bool g_should_close = false; +static const double FRAME_TIME = 1.0 / 60.0; + +PlatformState platform_init(bool fullscreen, int width, int height) { + (void)fullscreen; + g_virtual_time = 0.0; + g_should_close = false; + printf("[headless] Platform initialized (simulated %dx%d)\n", width, height); + + PlatformState state = {}; + state.width = width; + state.height = height; + state.aspect_ratio = (float)width / (float)height; + state.window = nullptr; + state.time = 0.0; + state.is_fullscreen = false; + return state; +} + +void platform_shutdown(PlatformState* state) { + (void)state; + printf("[headless] Platform shutdown\n"); +} + +void platform_poll(PlatformState* state) { + (void)state; + g_virtual_time += FRAME_TIME; +} + +bool platform_should_close(PlatformState* state) { + (void)state; + return g_should_close; +} + +void platform_toggle_fullscreen(PlatformState* state) { + (void)state; +} + +WGPUSurface platform_create_wgpu_surface(WGPUInstance instance, + PlatformState* state) { + (void)instance; + (void)state; + return nullptr; +} + +double platform_get_time() { + return g_virtual_time; +} + +#endif // DEMO_HEADLESS diff --git a/src/platform/platform.h b/src/platform/platform.h index 0a98850..7bcee9d 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -7,7 +7,10 @@ #include <cstring> // WebGPU specific headers and shims -#if defined(DEMO_CROSS_COMPILE_WIN32) +#if defined(STRIP_EXTERNAL_LIBS) +#include "stub_types.h" + +#elif defined(DEMO_CROSS_COMPILE_WIN32) #include <webgpu/webgpu.h> #include <webgpu/wgpu.h> diff --git a/src/platform/stub_platform.cc b/src/platform/stub_platform.cc new file mode 100644 index 0000000..61473a0 --- /dev/null +++ b/src/platform/stub_platform.cc @@ -0,0 +1,53 @@ +// Stub platform implementation for size measurement builds. +// All functions are no-ops. Binary compiles but does NOT run. +// This file is only compiled when STRIP_EXTERNAL_LIBS is defined. + +#if defined(STRIP_EXTERNAL_LIBS) + +#include "platform.h" +#include "stub_types.h" + +// Forward declare GLFWwindow stub +struct GLFWwindow {}; + +PlatformState platform_init(bool fullscreen, int width, int height) { + (void)fullscreen; + PlatformState state = {}; + state.width = width; + state.height = height; + state.aspect_ratio = (float)width / (float)height; + state.window = nullptr; + state.time = 0.0; + state.is_fullscreen = false; + return state; +} + +void platform_shutdown(PlatformState* state) { + (void)state; +} + +void platform_poll(PlatformState* state) { + (void)state; +} + +bool platform_should_close(PlatformState* state) { + (void)state; + return false; +} + +void platform_toggle_fullscreen(PlatformState* state) { + (void)state; +} + +WGPUSurface platform_create_wgpu_surface(WGPUInstance instance, + PlatformState* state) { + (void)instance; + (void)state; + return nullptr; +} + +double platform_get_time() { + return 0.0; +} + +#endif // STRIP_EXTERNAL_LIBS diff --git a/src/platform/stub_types.h b/src/platform/stub_types.h new file mode 100644 index 0000000..f532e04 --- /dev/null +++ b/src/platform/stub_types.h @@ -0,0 +1,159 @@ +// Minimal WebGPU type definitions for size measurement builds. +// All types are opaque pointers, all descriptor structs are empty. +// This file is only used when STRIP_EXTERNAL_LIBS is defined. + +#pragma once + +#if defined(STRIP_EXTERNAL_LIBS) + +#include <cstdint> +#include <cstring> + +// Opaque handle types +typedef void* WGPUInstance; +typedef void* WGPUAdapter; +typedef void* WGPUSurface; +typedef void* WGPUDevice; +typedef void* WGPUQueue; +typedef void* WGPUBuffer; +typedef void* WGPUTexture; +typedef void* WGPUTextureView; +typedef void* WGPUSampler; +typedef void* WGPUShaderModule; +typedef void* WGPUBindGroupLayout; +typedef void* WGPUPipelineLayout; +typedef void* WGPUBindGroup; +typedef void* WGPURenderPipeline; +typedef void* WGPUComputePipeline; +typedef void* WGPUCommandEncoder; +typedef void* WGPURenderPassEncoder; +typedef void* WGPUComputePassEncoder; +typedef void* WGPUCommandBuffer; +typedef void* WGPUQuerySet; +typedef void* WGPURenderBundle; +typedef void* WGPURenderBundleEncoder; + +// Enums (minimal values) +typedef enum { + WGPUTextureFormat_Undefined = 0, + WGPUTextureFormat_BGRA8Unorm = 1, + WGPUTextureFormat_RGBA8Unorm = 2, +} WGPUTextureFormat; + +typedef enum { + WGPUBufferBindingType_Uniform = 0, + WGPUBufferBindingType_Storage = 1, + WGPUBufferBindingType_ReadOnlyStorage = 2, +} WGPUBufferBindingType; + +typedef enum { + WGPULoadOp_Clear = 0, + WGPULoadOp_Load = 1, +} WGPULoadOp; + +typedef enum { + WGPUStoreOp_Store = 0, + WGPUStoreOp_Discard = 1, +} WGPUStoreOp; + +typedef enum { + WGPUSurfaceGetCurrentTextureStatus_Success = 0, + WGPUSurfaceGetCurrentTextureStatus_Timeout = 1, + WGPUSurfaceGetCurrentTextureStatus_Outdated = 2, + WGPUSurfaceGetCurrentTextureStatus_Lost = 3, +} WGPUSurfaceGetCurrentTextureStatus; + +// Buffer usage flags +#define WGPUBufferUsage_MapRead 0x00000001 +#define WGPUBufferUsage_MapWrite 0x00000002 +#define WGPUBufferUsage_CopySrc 0x00000004 +#define WGPUBufferUsage_CopyDst 0x00000008 +#define WGPUBufferUsage_Index 0x00000010 +#define WGPUBufferUsage_Vertex 0x00000020 +#define WGPUBufferUsage_Uniform 0x00000040 +#define WGPUBufferUsage_Storage 0x00000080 +#define WGPUBufferUsage_Indirect 0x00000100 +#define WGPUBufferUsage_QueryResolve 0x00000200 + +// Descriptor structs (all empty) +struct WGPUInstanceDescriptor {}; +struct WGPUAdapterInfo {}; +struct WGPUSurfaceConfiguration {}; +struct WGPUDeviceDescriptor {}; +struct WGPUBufferDescriptor {}; +struct WGPUTextureDescriptor {}; +struct WGPUTextureViewDescriptor {}; +struct WGPUSamplerDescriptor {}; +struct WGPUShaderModuleDescriptor {}; +struct WGPUShaderSourceWGSL {}; +struct WGPUShaderModuleWGSLDescriptor {}; +struct WGPUBindGroupLayoutDescriptor {}; +struct WGPUBindGroupLayoutEntry {}; +struct WGPUPipelineLayoutDescriptor {}; +struct WGPUBindGroupDescriptor {}; +struct WGPUBindGroupEntry {}; +struct WGPURenderPipelineDescriptor {}; +struct WGPUComputePipelineDescriptor {}; +struct WGPUVertexState {}; +struct WGPUFragmentState {}; +struct WGPUColorTargetState {}; +struct WGPUBlendState {}; +struct WGPUPrimitiveState {}; +struct WGPUMultisampleState {}; +struct WGPUDepthStencilState {}; +struct WGPURenderPassDescriptor {}; +struct WGPURenderPassColorAttachment { + WGPUTextureView view; + WGPULoadOp loadOp; + WGPUStoreOp storeOp; + struct { float r, g, b, a; } clearValue; + uint32_t depthSlice; +}; +struct WGPUComputePassDescriptor {}; +struct WGPUCommandEncoderDescriptor {}; +struct WGPUCommandBufferDescriptor {}; +struct WGPUSurfaceTexture { + WGPUTexture texture; + WGPUSurfaceGetCurrentTextureStatus status; +}; +struct WGPUColor { float r, g, b, a; }; +struct WGPUExtent3D { uint32_t width, height, depthOrArrayLayers; }; +struct WGPUOrigin3D { uint32_t x, y, z; }; +struct WGPUImageCopyTexture {}; +struct WGPUImageCopyBuffer {}; +struct WGPUTextureDataLayout {}; +struct WGPUBufferBindingLayout {}; +struct WGPUSamplerBindingLayout {}; +struct WGPUTextureBindingLayout {}; +struct WGPUStorageTextureBindingLayout {}; + +// String view helper (for compatibility) +struct WGPUStringView { + const char* data; + size_t length; +}; + +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) { + (void)str; + return {nullptr, 0}; +} + +// Platform shims (no-ops) +static inline void platform_wgpu_wait_any(WGPUInstance) {} +static inline void platform_wgpu_set_error_callback(WGPUDevice, void*) {} + +// Constants +#define WGPU_DEPTH_SLICE_UNDEFINED 0xffffffff +#define WGPUOptionalBool_True true +#define WGPUOptionalBool_False false + +// Callback types (empty) +typedef void (*WGPUErrorCallback)(void*, void*, const char*); +typedef void (*WGPUUncapturedErrorCallback)(void*, void*, const char*); + +#endif // STRIP_EXTERNAL_LIBS |
