Add RHI global context allocator

This commit is contained in:
2026-07-11 11:34:30 +01:00
parent 943f00345c
commit bffe9b8174
8 changed files with 376 additions and 295 deletions
+43 -61
View File
@@ -29,18 +29,23 @@
extern "C" {
#endif
wp_extern PrRhiContext _G_RHI_CONTEXT;
wp_extern void prRhiInit(void);
wp_extern void prRhiDestroy(void);
// ======================================================================
// Instance
// ======================================================================
PrRhiInstance *prRhiCreateInstance(PrRhiInstanceDesc desc, WpAllocator *allocator);
void prRhiDestroyInstance(PrRhiInstance *inst, WpAllocator *allocator);
PrRhiInstance *prRhiCreateInstance(PrRhiInstanceDesc desc);
void prRhiDestroyInstance(PrRhiInstance *inst);
// ======================================================================
// Physical device enumeration
// ======================================================================
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevices(PrRhiInstance *inst, const WpAllocator *allocator);
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevices(PrRhiInstance *inst);
void prRhiGetPhysicalDeviceName(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceDriverInfo(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceProperties(PrRhiPhysicalDevice *pdev,
@@ -50,9 +55,8 @@ void prRhiGetPhysicalDeviceProperties(PrRhiPhysicalDevice *p
// Surface (platform-specific)
// ======================================================================
PrRhiSurface *prRhiCreateSurfaceFromWindow(PrRhiInstance *inst, void *window_handle,
WpAllocator *allocator);
void prRhiDestroySurface(PrRhiInstance *inst, PrRhiSurface *surface, WpAllocator *allocator);
PrRhiSurface *prRhiCreateSurfaceFromWindow(PrRhiInstance *inst, void *window_handle);
void prRhiDestroySurface(PrRhiInstance *inst, PrRhiSurface *surface);
PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilities(PrRhiPhysicalDevice *pdev,
PrRhiSurface *surface);
@@ -61,8 +65,8 @@ PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilities(PrRhiPhysicalDevice *pdev,
// ======================================================================
PrRhiDevice *prRhiCreateDevice(PrRhiPhysicalDevice *pdev, PrRhiSurface *surface,
PrRhiDeviceDesc desc, WpAllocator *allocator);
void prRhiDestroyDevice(PrRhiDevice *device, WpAllocator *allocator);
PrRhiDeviceDesc desc);
void prRhiDestroyDevice(PrRhiDevice *device);
void prRhiDeviceWaitIdle(PrRhiDevice *device);
u32 prRhiGetQueueFamilyIndex(PrRhiDevice *device);
@@ -70,10 +74,8 @@ u32 prRhiGetQueueFamilyIndex(PrRhiDevice *device);
// Swapchain
// ======================================================================
PrRhiSwapchain *prRhiCreateSwapchain(PrRhiDevice *device, PrRhiSwapchainDesc desc,
WpAllocator *allocator);
void prRhiDestroySwapchain(PrRhiDevice *device, PrRhiSwapchain *swapchain,
WpAllocator *allocator);
PrRhiSwapchain *prRhiCreateSwapchain(PrRhiDevice *device, PrRhiSwapchainDesc desc);
void prRhiDestroySwapchain(PrRhiDevice *device, PrRhiSwapchain *swapchain);
PrRhiSwapchainResult prRhiAcquireNextImage(PrRhiDevice *device, PrRhiSwapchain *swapchain,
PrRhiSemaphore *signal_semaphore, u32 *out_image_index);
@@ -82,7 +84,7 @@ PrRhiSwapchainResult prRhiPresent(PrRhiDevice *device, PrRhiSwapchain *swapchain
PrRhiSemaphore *wait_semaphore);
void prRhiRecreateSwapchain(PrRhiDevice *device, PrRhiSwapchain **swapchain,
u32 width, u32 height, WpAllocator *allocator);
u32 width, u32 height);
PrRhiTexture *prRhiGetSwapchainTexture(PrRhiSwapchain *swapchain, u32 image_index);
PrRhiTexture *prRhiGetSwapchainDepthTexture(PrRhiSwapchain *swapchain);
@@ -92,9 +94,8 @@ PrRhiFormat prRhiGetSwapchainFormat(PrRhiSwapchain *swapchain);
// Buffers
// ======================================================================
PrRhiBuffer *prRhiCreateBuffer(PrRhiDevice *device, PrRhiBufferDesc desc,
WpAllocator *allocator);
void prRhiDestroyBuffer(PrRhiDevice *device, PrRhiBuffer *buffer, WpAllocator *allocator);
PrRhiBuffer *prRhiCreateBuffer(PrRhiDevice *device, PrRhiBufferDesc desc);
void prRhiDestroyBuffer(PrRhiDevice *device, PrRhiBuffer *buffer);
void *prRhiBufferMap(PrRhiDevice *device, PrRhiBuffer *buffer);
void prRhiBufferUnmap(PrRhiDevice *device, PrRhiBuffer *buffer);
@@ -105,115 +106,96 @@ PrRhiDeviceAddress prRhiGetBufferDeviceAddress(PrRhiDevice *device, PrRhiBuffer
// Textures
// ======================================================================
PrRhiTexture *prRhiCreateTexture(PrRhiDevice *device, PrRhiTextureDesc desc,
WpAllocator *allocator);
PrRhiTexture *prRhiCreateTexture(PrRhiDevice *device, PrRhiTextureDesc desc);
PrRhiTexture *prRhiCreateTextureFromKtx(PrRhiDevice *device, const char *path,
PrRhiCommandPool *pool, PrRhiCommandBuffer *cb,
WpAllocator *allocator);
void prRhiDestroyTexture(PrRhiDevice *device, PrRhiTexture *texture,
WpAllocator *allocator);
PrRhiCommandPool *pool, PrRhiCommandBuffer *cb);
void prRhiDestroyTexture(PrRhiDevice *device, PrRhiTexture *texture);
// ======================================================================
// Samplers
// ======================================================================
PrRhiSampler *prRhiCreateSampler(PrRhiDevice *device, PrRhiSamplerDesc desc,
WpAllocator *allocator);
void prRhiDestroySampler(PrRhiDevice *device, PrRhiSampler *sampler,
WpAllocator *allocator);
PrRhiSampler *prRhiCreateSampler(PrRhiDevice *device, PrRhiSamplerDesc desc);
void prRhiDestroySampler(PrRhiDevice *device, PrRhiSampler *sampler);
// ======================================================================
// Shaders (from SPIR-V)
// ======================================================================
PrRhiShader *prRhiCreateShader(PrRhiDevice *device, PrRhiShaderDesc desc,
WpAllocator *allocator);
void prRhiDestroyShader(PrRhiDevice *device, PrRhiShader *shader, WpAllocator *allocator);
PrRhiShader *prRhiCreateShader(PrRhiDevice *device, PrRhiShaderDesc desc);
void prRhiDestroyShader(PrRhiDevice *device, PrRhiShader *shader);
// ======================================================================
// Pipeline layouts
// ======================================================================
PrRhiPipelineLayout *prRhiCreatePipelineLayout(PrRhiDevice *device,
PrRhiPipelineLayoutDesc desc,
WpAllocator *allocator);
PrRhiPipelineLayoutDesc desc);
void prRhiDestroyPipelineLayout(PrRhiDevice *device,
PrRhiPipelineLayout *layout,
WpAllocator *allocator);
PrRhiPipelineLayout *layout);
// ======================================================================
// Pipelines
// ======================================================================
PrRhiPipeline *prRhiCreateGraphicsPipeline(PrRhiDevice *device,
PrRhiGraphicsPipelineDesc desc,
WpAllocator *allocator);
PrRhiGraphicsPipelineDesc desc);
PrRhiPipeline *prRhiCreateComputePipeline(PrRhiDevice *device,
PrRhiComputePipelineDesc desc,
WpAllocator *allocator);
void prRhiDestroyPipeline(PrRhiDevice *device, PrRhiPipeline *pipeline,
WpAllocator *allocator);
PrRhiComputePipelineDesc desc);
void prRhiDestroyPipeline(PrRhiDevice *device, PrRhiPipeline *pipeline);
// ======================================================================
// Descriptor set layouts
// ======================================================================
PrRhiDescriptorSetLayout *prRhiCreateDescriptorSetLayout(PrRhiDevice *device,
PrRhiDescriptorSetLayoutDesc desc,
WpAllocator *allocator);
PrRhiDescriptorSetLayoutDesc desc);
void prRhiDestroyDescriptorSetLayout(PrRhiDevice *device,
PrRhiDescriptorSetLayout *layout,
WpAllocator *allocator);
PrRhiDescriptorSetLayout *layout);
// ======================================================================
// Descriptor pools
// ======================================================================
PrRhiDescriptorPool *prRhiCreateDescriptorPool(PrRhiDevice *device,
PrRhiDescriptorPoolDesc desc,
WpAllocator *allocator);
PrRhiDescriptorPoolDesc desc);
void prRhiDestroyDescriptorPool(PrRhiDevice *device,
PrRhiDescriptorPool *pool,
WpAllocator *allocator);
PrRhiDescriptorPool *pool);
// ======================================================================
// Descriptor sets
// ======================================================================
PrRhiDescriptorSet *prRhiAllocateDescriptorSet(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSetLayout *layout,
u32 variable_count, WpAllocator *allocator);
PrRhiDescriptorSetLayout *layout,
u32 variable_count);
void prRhiFreeDescriptorSet(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSet *set, WpAllocator *allocator);
PrRhiDescriptorSet *set);
void prRhiUpdateDescriptorSet(PrRhiDevice *device, PrRhiWriteDescriptorSetArray writes);
// ======================================================================
// Fences and semaphores
// ======================================================================
PrRhiFence *prRhiCreateFence(PrRhiDevice *device, PrRhiFenceDesc desc,
WpAllocator *allocator);
void prRhiDestroyFence(PrRhiDevice *device, PrRhiFence *fence, WpAllocator *allocator);
PrRhiFence *prRhiCreateFence(PrRhiDevice *device, PrRhiFenceDesc desc);
void prRhiDestroyFence(PrRhiDevice *device, PrRhiFence *fence);
void prRhiWaitForFences(PrRhiDevice *device, PrRhiFenceArray fences, u32 count,
b8 wait_all, u64 timeout_ns);
void prRhiResetFences(PrRhiDevice *device, PrRhiFenceArray fences, u32 count);
PrRhiSemaphore *prRhiCreateSemaphore(PrRhiDevice *device, WpAllocator *allocator);
void prRhiDestroySemaphore(PrRhiDevice *device, PrRhiSemaphore *semaphore,
WpAllocator *allocator);
PrRhiSemaphore *prRhiCreateSemaphore(PrRhiDevice *device);
void prRhiDestroySemaphore(PrRhiDevice *device, PrRhiSemaphore *semaphore);
// ======================================================================
// Command pools and command buffers
// ======================================================================
PrRhiCommandPool *prRhiCreateCommandPool(PrRhiDevice *device, PrRhiCommandPoolDesc desc,
WpAllocator *allocator);
void prRhiDestroyCommandPool(PrRhiDevice *device, PrRhiCommandPool *pool,
WpAllocator *allocator);
PrRhiCommandPool *prRhiCreateCommandPool(PrRhiDevice *device, PrRhiCommandPoolDesc desc);
void prRhiDestroyCommandPool(PrRhiDevice *device, PrRhiCommandPool *pool);
PrRhiCommandBufferArray prRhiAllocateCommandBuffers(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, WpAllocator *allocator);
u32 count);
void prRhiFreeCommandBuffers(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, PrRhiCommandBufferArray buffers);