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
+17
View File
@@ -0,0 +1,17 @@
// vim:fileencoding=utf-8:foldmethod=marker
//
// RHI context — shared initialisation and global state.
#include "pr_rhi.h"
PrRhiContext _G_RHI_CONTEXT;
void prRhiInit(void) {
_G_RHI_CONTEXT.main = wpMemArenaAllocatorInit(MiB(64));
_G_RHI_CONTEXT.scratch = wpMemArenaAllocatorInit(MiB(32));
}
void prRhiDestroy(void) {
wpMemArenaAllocatorDestroy(&_G_RHI_CONTEXT.scratch);
wpMemArenaAllocatorDestroy(&_G_RHI_CONTEXT.main);
}
+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);
+9
View File
@@ -438,6 +438,15 @@ typedef struct PrRhiPhysicalDeviceProperties {
typedef u64 PrRhiDeviceAddress;
// ============================================================================
// RHI context (global, owns all RHI object lifetimes)
// ============================================================================
typedef struct PrRhiContext {
WpAllocator main;
WpAllocator scratch;
} PrRhiContext;
// --- Command buffer types ---
typedef struct PrRhiDepthAttachment {
+108 -130
View File
@@ -6,6 +6,7 @@
#include "pr_rhi_vk.h"
#include "profiles/vulkan_profiles.h"
#include "../pr_rhi.h"
#include <volk/volk.h>
#include <vk_mem_alloc.h>
#include <SDL3/SDL_vulkan.h>
@@ -312,7 +313,7 @@ VkPhysicalDeviceType _toVkPhysicalDeviceType(PrRhiPhysicalDeviceType type) {
// Instance
// ============================================================================
PrRhiInstance *prRhiCreateInstanceVk(PrRhiInstanceDesc desc, WpAllocator *allocator) {
PrRhiInstance *prRhiCreateInstanceVk(PrRhiInstanceDesc desc) {
_checkVk(volkInitialize(), "volkInitialize");
VkBool32 supported = VK_FALSE;
@@ -347,7 +348,7 @@ PrRhiInstance *prRhiCreateInstanceVk(PrRhiInstanceDesc desc, WpAllocator *alloca
volkLoadInstance(vk_instance);
PrRhiInstance *inst = wpMemAllocatorAlloc(allocator, sizeof(PrRhiInstance));
PrRhiInstance *inst = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiInstance));
if (!inst) { _abort("alloc failed for PrRhiInstance"); }
inst->handle = vk_instance;
inst->debug_messenger = NULL;
@@ -355,34 +356,34 @@ PrRhiInstance *prRhiCreateInstanceVk(PrRhiInstanceDesc desc, WpAllocator *alloca
return inst;
}
void prRhiDestroyInstanceVk(PrRhiInstance *inst, WpAllocator *allocator) {
void prRhiDestroyInstanceVk(PrRhiInstance *inst) {
if (!inst) { return; }
vkDestroyInstance((VkInstance)inst->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&inst, sizeof(PrRhiInstance));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&inst, sizeof(PrRhiInstance));
}
// ============================================================================
// Physical device enumeration
// ============================================================================
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevicesVk(PrRhiInstance *inst, const WpAllocator *allocator) {
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevicesVk(PrRhiInstance *inst) {
VkInstance vk_inst = (VkInstance)inst->handle;
u32 count = 0;
_checkVk(vkEnumeratePhysicalDevices(vk_inst, &count, NULL), "vkEnumeratePhysicalDevices");
if (count == 0) _abort("no physical devices");
VkPhysicalDeviceArray vk_devices = wpArrayAllocCapacity(VkPhysicalDevice, allocator, count, WP_ARRAY_INIT_FILLED);
VkPhysicalDeviceArray vk_devices = wpArrayAllocCapacity(VkPhysicalDevice, &_G_RHI_CONTEXT.scratch, count, WP_ARRAY_INIT_FILLED);
if (!vk_devices) _abort("alloc failed for physical device array");
_checkVk(vkEnumeratePhysicalDevices(vk_inst, &count, vk_devices), "vkEnumeratePhysicalDevices");
wpArraySetCount(vk_devices, count);
PrRhiPhysicalDeviceArray pdevs = wpArrayAllocCapacity(PrRhiPhysicalDevice *, allocator, count, WP_ARRAY_INIT_NONE);
PrRhiPhysicalDeviceArray pdevs = wpArrayAllocCapacity(PrRhiPhysicalDevice *, &_G_RHI_CONTEXT.main, count, WP_ARRAY_INIT_NONE);
if (!pdevs) _abort("alloc failed for PrRhiPhysicalDevice array");
for (u32 i = 0; i < count; ++i) {
PrRhiPhysicalDevice *pdev = (PrRhiPhysicalDevice *)wpMemAllocatorAlloc(allocator, sizeof(PrRhiPhysicalDevice));
PrRhiPhysicalDevice *pdev = (PrRhiPhysicalDevice *)wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiPhysicalDevice));
if (!pdev) _abort("alloc failed for PrRhiPhysicalDevice");
pdev->handle = vk_devices[i];
pdev->instance = inst;
@@ -424,8 +425,7 @@ void prRhiGetPhysicalDevicePropertiesVk(PrRhiPhysicalDevice *pdev,
// Surface
// ============================================================================
PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, void *window_handle,
WpAllocator *allocator) {
PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, void *window_handle) {
SDL_Window *window = (SDL_Window *)window_handle;
VkInstance vk_inst = (VkInstance)inst->handle;
@@ -433,16 +433,16 @@ PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, void *window_h
if (!SDL_Vulkan_CreateSurface(window, vk_inst, NULL, &vk_surface))
_abort("SDL_Vulkan_CreateSurface failed");
PrRhiSurface *surface = wpMemAllocatorAlloc(allocator, sizeof(PrRhiSurface));
PrRhiSurface *surface = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiSurface));
if (!surface) _abort("alloc failed for PrRhiSurface");
surface->handle = (void *)vk_surface;
return surface;
}
void prRhiDestroySurfaceVk(PrRhiInstance *inst, PrRhiSurface *surface, WpAllocator *allocator) {
void prRhiDestroySurfaceVk(PrRhiInstance *inst, PrRhiSurface *surface) {
if (!surface) return;
vkDestroySurfaceKHR((VkInstance)inst->handle, (VkSurfaceKHR)surface->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&surface, sizeof(PrRhiSurface));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&surface, sizeof(PrRhiSurface));
}
PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilitiesVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surface) {
@@ -469,7 +469,7 @@ PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilitiesVk(PrRhiPhysicalDevice *pdev
// ============================================================================
PrRhiDevice *prRhiCreateDeviceVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surface,
PrRhiDeviceDesc desc, WpAllocator *allocator) {
PrRhiDeviceDesc desc) {
VkInstance vk_inst = (VkInstance)pdev->instance->handle;
VkPhysicalDevice vk_pdev = (VkPhysicalDevice)pdev->handle;
VkSurfaceKHR vk_surface = (VkSurfaceKHR)surface->handle;
@@ -480,7 +480,7 @@ PrRhiDevice *prRhiCreateDeviceVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surfac
if (queue_family_count == 0) _abort("no queue families");
VkQueueFamilyProperties2Array qf_props =
wpArrayAllocCapacity(VkQueueFamilyProperties2, allocator, queue_family_count, WP_ARRAY_INIT_FILLED);
wpArrayAllocCapacity(VkQueueFamilyProperties2, &_G_RHI_CONTEXT.scratch, queue_family_count, WP_ARRAY_INIT_FILLED);
if (!qf_props) _abort("alloc failed for queue family props");
for (u32 i = 0; i < queue_family_count; ++i) {
@@ -505,7 +505,7 @@ PrRhiDevice *prRhiCreateDeviceVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surfac
"vkGetPhysicalDeviceSurfaceSupportKHR");
if (!present_supported) _abort("no presentation support");
wpArrayDealloc(VkQueueFamilyProperties2, allocator, &qf_props);
wpArrayDealloc(VkQueueFamilyProperties2, &_G_RHI_CONTEXT.scratch, &qf_props);
// Check device profile support
VkBool32 profile_supported = VK_FALSE;
@@ -557,7 +557,7 @@ PrRhiDevice *prRhiCreateDeviceVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surfac
VmaAllocator vma_allocator = VK_NULL_HANDLE;
_checkVk(vmaCreateAllocator(&vma_info, &vma_allocator), "vmaCreateAllocator");
PrRhiDevice *device = wpMemAllocatorAlloc(allocator, sizeof(PrRhiDevice));
PrRhiDevice *device = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiDevice));
if (!device) _abort("alloc failed for PrRhiDevice");
device->handle = vk_device;
device->queue = vk_queue;
@@ -569,12 +569,12 @@ PrRhiDevice *prRhiCreateDeviceVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surfac
return device;
}
void prRhiDestroyDeviceVk(PrRhiDevice *device, WpAllocator *allocator) {
void prRhiDestroyDeviceVk(PrRhiDevice *device) {
if (!device) return;
vkDeviceWaitIdle((VkDevice)device->handle);
vmaDestroyAllocator((VmaAllocator)device->allocator);
vkDestroyDevice((VkDevice)device->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&device, sizeof(PrRhiDevice));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&device, sizeof(PrRhiDevice));
}
void prRhiDeviceWaitIdleVk(PrRhiDevice *device) {
@@ -590,9 +590,9 @@ u32 prRhiGetQueueFamilyIndexVk(PrRhiDevice *device) {
// ============================================================================
static PrRhiTexture *_createSwapchainTexture(PrRhiDevice *device, VkImage vk_image,
VkFormat vk_format, u32 width, u32 height,
VkImageView vk_view, WpAllocator *allocator) {
PrRhiTexture *tex = wpMemAllocatorAlloc(allocator, sizeof(PrRhiTexture));
VkFormat vk_format, u32 width, u32 height,
VkImageView vk_view) {
PrRhiTexture *tex = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiTexture));
if (!tex) _abort("alloc failed for swapchain texture");
tex->image = vk_image;
tex->view = vk_view;
@@ -615,8 +615,7 @@ static VkFormat _pickDepthFormat(VkPhysicalDevice vk_pdev) {
return VK_FORMAT_UNDEFINED;
}
PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc desc,
WpAllocator *allocator) {
PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc desc) {
VkDevice vk_device = (VkDevice)device->handle;
VkPhysicalDevice vk_pdev = (VkPhysicalDevice)device->physical_device;
VkSurfaceKHR vk_surface = (VkSurfaceKHR)desc.surface->handle;
@@ -652,13 +651,13 @@ PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc d
_checkVk(vkGetSwapchainImagesKHR(vk_device, vk_swapchain, &image_count, NULL),
"vkGetSwapchainImagesKHR");
VkImageArray vk_images = wpArrayAllocCapacity(VkImage, allocator, image_count, WP_ARRAY_INIT_FILLED);
VkImageArray vk_images = wpArrayAllocCapacity(VkImage, &_G_RHI_CONTEXT.scratch, image_count, WP_ARRAY_INIT_FILLED);
if (!vk_images) _abort("alloc failed for swapchain VkImage array");
_checkVk(vkGetSwapchainImagesKHR(vk_device, vk_swapchain, &image_count, vk_images),
"vkGetSwapchainImagesKHR");
wpArraySetCount(vk_images, image_count);
PrRhiTextureArray images = wpArrayAllocCapacity(PrRhiTexture *, allocator, image_count, WP_ARRAY_INIT_NONE);
PrRhiTextureArray images = wpArrayAllocCapacity(PrRhiTexture *, &_G_RHI_CONTEXT.main, image_count, WP_ARRAY_INIT_NONE);
if (!images) _abort("alloc failed for swapchain image array");
for (u32 i = 0; i < image_count; ++i) {
@@ -675,13 +674,13 @@ PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc d
_checkVk(vkCreateImageView(vk_device, &view_info, NULL, &vk_view), "vkCreateImageView");
PrRhiTexture *tex = _createSwapchainTexture(device, vk_images[i], _default_image_format,
extent.width, extent.height, vk_view, allocator);
extent.width, extent.height, vk_view);
wpArrayAppendCapped(PrRhiTexture *, images, &tex);
}
wpArrayDealloc(VkImage, allocator, &vk_images);
wpArrayDealloc(VkImage, &_G_RHI_CONTEXT.scratch, &vk_images);
PrRhiSwapchain *swapchain = wpMemAllocatorAlloc(allocator, sizeof(PrRhiSwapchain));
PrRhiSwapchain *swapchain = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiSwapchain));
if (!swapchain) _abort("alloc failed for PrRhiSwapchain");
swapchain->device = device;
swapchain->handle = vk_swapchain;
@@ -741,7 +740,7 @@ PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc d
VkImageView depth_view = VK_NULL_HANDLE;
_checkVk(vkCreateImageView(vk_device, &depth_view_info, NULL, &depth_view), "vkCreateImageView (depth)");
PrRhiTexture *depth_tex = wpMemAllocatorAlloc(allocator, sizeof(PrRhiTexture));
PrRhiTexture *depth_tex = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiTexture));
if (!depth_tex) _abort("alloc failed for depth texture");
depth_tex->image = depth_image;
depth_tex->view = depth_view;
@@ -757,7 +756,7 @@ PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc d
return swapchain;
}
void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain, WpAllocator *allocator) {
void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain) {
if (!swapchain) return;
VkDevice vk_device = (VkDevice)device->handle;
@@ -767,9 +766,9 @@ void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain, WpA
PrRhiTexture *tex = swapchain->images[i];
vkDestroyImageView(vk_device, (VkImageView)tex->view, NULL);
// VkImage is owned by swapchain — skip vmaDestroyImage
wpMemAllocatorFree(allocator, (void**)&tex, sizeof(PrRhiTexture));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&tex, sizeof(PrRhiTexture));
}
wpArrayDealloc(PrRhiTexture *, allocator, &swapchain->images);
wpArrayDealloc(PrRhiTexture *, &_G_RHI_CONTEXT.main, &swapchain->images);
// Destroy depth
if (swapchain->depth) {
@@ -777,11 +776,11 @@ void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain, WpA
vkDestroyImageView(vk_device, (VkImageView)depth->view, NULL);
vmaDestroyImage((VmaAllocator)device->allocator, (VkImage)depth->image,
(VmaAllocation)depth->allocation);
wpMemAllocatorFree(allocator, (void**)&depth, sizeof(PrRhiTexture));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&depth, sizeof(PrRhiTexture));
}
vkDestroySwapchainKHR(vk_device, (VkSwapchainKHR)swapchain->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&swapchain, sizeof(PrRhiSwapchain));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&swapchain, sizeof(PrRhiSwapchain));
}
PrRhiSwapchainResult prRhiAcquireNextImageVk(PrRhiDevice *device, PrRhiSwapchain *swapchain,
@@ -816,7 +815,7 @@ PrRhiSwapchainResult prRhiPresentVk(PrRhiDevice *device, PrRhiSwapchain *swapcha
}
void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
u32 width, u32 height, WpAllocator *allocator) {
u32 width, u32 height) {
PrRhiSwapchain *old = *swapchain;
if (!old) return;
@@ -847,9 +846,9 @@ void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
for (u32 i = 0; i < old->image_count; ++i) {
PrRhiTexture *tex = old->images[i];
vkDestroyImageView(vk_device, (VkImageView)tex->view, NULL);
wpMemAllocatorFree(allocator, (void**)&tex, sizeof(PrRhiTexture));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&tex, sizeof(PrRhiTexture));
}
wpArrayDealloc(PrRhiTexture *, allocator, &old->images);
wpArrayDealloc(PrRhiTexture *, &_G_RHI_CONTEXT.main, &old->images);
// Destroy old depth
if (old->depth) {
@@ -857,7 +856,7 @@ void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
vkDestroyImageView(vk_device, (VkImageView)depth->view, NULL);
vmaDestroyImage((VmaAllocator)device->allocator, (VkImage)depth->image,
(VmaAllocation)depth->allocation);
wpMemAllocatorFree(allocator, (void**)&depth, sizeof(PrRhiTexture));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&depth, sizeof(PrRhiTexture));
}
// Destroy old swapchain
@@ -868,13 +867,13 @@ void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
_checkVk(vkGetSwapchainImagesKHR(vk_device, vk_new_swapchain, &new_image_count, NULL),
"vkGetSwapchainImagesKHR (recreate)");
VkImageArray vk_images = wpArrayAllocCapacity(VkImage, allocator, new_image_count, WP_ARRAY_INIT_FILLED);
VkImageArray vk_images = wpArrayAllocCapacity(VkImage, &_G_RHI_CONTEXT.scratch, new_image_count, WP_ARRAY_INIT_FILLED);
if (!vk_images) _abort("alloc failed for swapchain VkImage array (recreate)");
_checkVk(vkGetSwapchainImagesKHR(vk_device, vk_new_swapchain, &new_image_count, vk_images),
"vkGetSwapchainImagesKHR (recreate)");
wpArraySetCount(vk_images, new_image_count);
PrRhiTextureArray new_images = wpArrayAllocCapacity(PrRhiTexture *, allocator, new_image_count, WP_ARRAY_INIT_NONE);
PrRhiTextureArray new_images = wpArrayAllocCapacity(PrRhiTexture *, &_G_RHI_CONTEXT.main, new_image_count, WP_ARRAY_INIT_NONE);
if (!new_images) _abort("alloc failed for swapchain image array (recreate)");
for (u32 i = 0; i < new_image_count; ++i) {
@@ -891,11 +890,11 @@ void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
_checkVk(vkCreateImageView(vk_device, &view_info, NULL, &vk_view), "vkCreateImageView (recreate)");
PrRhiTexture *tex = _createSwapchainTexture(device, vk_images[i], (VkFormat)old->format,
extent.width, extent.height, vk_view, allocator);
extent.width, extent.height, vk_view);
wpArrayAppendCapped(PrRhiTexture *, new_images, &tex);
}
wpArrayDealloc(VkImage, allocator, &vk_images);
wpArrayDealloc(VkImage, &_G_RHI_CONTEXT.scratch, &vk_images);
// Recreate depth
PrRhiTexture *new_depth = NULL;
@@ -939,7 +938,7 @@ void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
VkImageView depth_view = VK_NULL_HANDLE;
_checkVk(vkCreateImageView(vk_device, &depth_view_info, NULL, &depth_view), "vkCreateImageView (depth recreate)");
new_depth = wpMemAllocatorAlloc(allocator, sizeof(PrRhiTexture));
new_depth = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiTexture));
if (!new_depth) _abort("alloc failed for depth texture (recreate)");
new_depth->image = depth_image;
new_depth->view = depth_view;
@@ -979,8 +978,7 @@ PrRhiFormat prRhiGetSwapchainFormatVk(PrRhiSwapchain *swapchain) {
// Buffers
// ============================================================================
PrRhiBuffer *prRhiCreateBufferVk(PrRhiDevice *device, PrRhiBufferDesc desc,
WpAllocator *allocator) {
PrRhiBuffer *prRhiCreateBufferVk(PrRhiDevice *device, PrRhiBufferDesc desc) {
VkBufferCreateInfo buf_info = {};
buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
buf_info.size = desc.size;
@@ -1005,7 +1003,7 @@ PrRhiBuffer *prRhiCreateBufferVk(PrRhiDevice *device, PrRhiBufferDesc desc,
&vk_buffer, &vma_alloc, &vma_alloc_info),
"vmaCreateBuffer");
PrRhiBuffer *buffer = wpMemAllocatorAlloc(allocator, sizeof(PrRhiBuffer));
PrRhiBuffer *buffer = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiBuffer));
if (!buffer) _abort("alloc failed for PrRhiBuffer");
buffer->handle = vk_buffer;
buffer->allocation = vma_alloc;
@@ -1024,11 +1022,11 @@ PrRhiBuffer *prRhiCreateBufferVk(PrRhiDevice *device, PrRhiBufferDesc desc,
return buffer;
}
void prRhiDestroyBufferVk(PrRhiDevice *device, PrRhiBuffer *buffer, WpAllocator *allocator) {
void prRhiDestroyBufferVk(PrRhiDevice *device, PrRhiBuffer *buffer) {
if (!buffer) return;
vmaDestroyBuffer((VmaAllocator)device->allocator, (VkBuffer)buffer->handle,
(VmaAllocation)buffer->allocation);
wpMemAllocatorFree(allocator, (void**)&buffer, sizeof(PrRhiBuffer));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&buffer, sizeof(PrRhiBuffer));
}
void *prRhiBufferMapVk(PrRhiDevice *device, PrRhiBuffer *buffer) {
@@ -1051,8 +1049,7 @@ PrRhiDeviceAddress prRhiGetBufferDeviceAddressVk(PrRhiDevice *device, PrRhiBuffe
// Textures
// ============================================================================
PrRhiTexture *prRhiCreateTextureVk(PrRhiDevice *device, PrRhiTextureDesc desc,
WpAllocator *allocator) {
PrRhiTexture *prRhiCreateTextureVk(PrRhiDevice *device, PrRhiTextureDesc desc) {
VkImageCreateInfo img_info = {};
img_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
img_info.imageType = VK_IMAGE_TYPE_2D;
@@ -1094,7 +1091,7 @@ PrRhiTexture *prRhiCreateTextureVk(PrRhiDevice *device, PrRhiTextureDesc desc,
_checkVk(vkCreateImageView((VkDevice)device->handle, &view_info, NULL, &vk_view),
"vkCreateImageView");
PrRhiTexture *texture = wpMemAllocatorAlloc(allocator, sizeof(PrRhiTexture));
PrRhiTexture *texture = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiTexture));
if (!texture) _abort("alloc failed for PrRhiTexture");
texture->image = vk_image;
texture->view = vk_view;
@@ -1107,8 +1104,7 @@ PrRhiTexture *prRhiCreateTextureVk(PrRhiDevice *device, PrRhiTextureDesc desc,
}
PrRhiTexture *prRhiCreateTextureFromKtxVk(PrRhiDevice *device, const char *path,
PrRhiCommandPool *pool, PrRhiCommandBuffer *cb,
WpAllocator *allocator) {
PrRhiCommandPool *pool, PrRhiCommandBuffer *cb) {
VkDevice vk_device = (VkDevice)device->handle;
ktxTexture *ktx = NULL;
@@ -1129,7 +1125,7 @@ PrRhiTexture *prRhiCreateTextureFromKtxVk(PrRhiDevice *device, const char *path,
.usage = PR_RHI_BUFFER_USAGE_TRANSFER_SRC,
.memory = PR_RHI_MEMORY_CPU_TO_GPU,
};
PrRhiBuffer *staging = prRhiCreateBufferVk(device, buf_desc, allocator);
PrRhiBuffer *staging = prRhiCreateBufferVk(device, buf_desc);
memcpy(prRhiBufferMapVk(device, staging), data, data_size);
// Create the destination image
@@ -1210,10 +1206,10 @@ PrRhiTexture *prRhiCreateTextureFromKtxVk(PrRhiDevice *device, const char *path,
// Submit and wait
PrRhiFenceDesc fence_desc = { .signaled = false };
PrRhiFence *fence = prRhiCreateFenceVk(device, fence_desc, allocator);
PrRhiFence *fence = prRhiCreateFenceVk(device, fence_desc);
prRhiQueueSubmitVk(device, cb, NULL, NULL, fence);
prRhiWaitForFencesVk(device, &(PrRhiFence *){ fence }, 1, VK_TRUE, UINT64_MAX);
prRhiDestroyFenceVk(device, fence, allocator);
prRhiDestroyFenceVk(device, fence);
vkResetCommandBuffer(vk_cb, 0);
// Create image view
@@ -1230,7 +1226,7 @@ PrRhiTexture *prRhiCreateTextureFromKtxVk(PrRhiDevice *device, const char *path,
_checkVk(vkCreateImageView(vk_device, &view_info, NULL, &vk_view),
"vkCreateImageView");
PrRhiTexture *texture = wpMemAllocatorAlloc(allocator, sizeof(PrRhiTexture));
PrRhiTexture *texture = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiTexture));
if (!texture) _abort("alloc failed for PrRhiTexture");
texture->image = vk_image;
texture->view = vk_view;
@@ -1240,13 +1236,13 @@ PrRhiTexture *prRhiCreateTextureFromKtxVk(PrRhiDevice *device, const char *path,
texture->format = vk_format;
// Cleanup staging
prRhiDestroyBufferVk(device, staging, allocator);
prRhiDestroyBufferVk(device, staging);
ktxTexture_Destroy(ktx);
return texture;
}
void prRhiDestroyTextureVk(PrRhiDevice *device, PrRhiTexture *texture, WpAllocator *allocator) {
void prRhiDestroyTextureVk(PrRhiDevice *device, PrRhiTexture *texture) {
if (!texture) return;
VkDevice vk_device = (VkDevice)device->handle;
@@ -1255,15 +1251,14 @@ void prRhiDestroyTextureVk(PrRhiDevice *device, PrRhiTexture *texture, WpAllocat
vmaDestroyImage((VmaAllocator)device->allocator, (VkImage)texture->image,
(VmaAllocation)texture->allocation);
}
wpMemAllocatorFree(allocator, (void**)&texture, sizeof(PrRhiTexture));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&texture, sizeof(PrRhiTexture));
}
// ============================================================================
// Samplers
// ============================================================================
PrRhiSampler *prRhiCreateSamplerVk(PrRhiDevice *device, PrRhiSamplerDesc desc,
WpAllocator *allocator) {
PrRhiSampler *prRhiCreateSamplerVk(PrRhiDevice *device, PrRhiSamplerDesc desc) {
VkSamplerCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
info.magFilter = _toVkFilter(desc.mag_filter);
@@ -1282,24 +1277,23 @@ PrRhiSampler *prRhiCreateSamplerVk(PrRhiDevice *device, PrRhiSamplerDesc desc,
_checkVk(vkCreateSampler((VkDevice)device->handle, &info, NULL, &vk_sampler),
"vkCreateSampler");
PrRhiSampler *sampler = wpMemAllocatorAlloc(allocator, sizeof(PrRhiSampler));
PrRhiSampler *sampler = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiSampler));
if (!sampler) _abort("alloc failed for PrRhiSampler");
sampler->handle = vk_sampler;
return sampler;
}
void prRhiDestroySamplerVk(PrRhiDevice *device, PrRhiSampler *sampler, WpAllocator *allocator) {
void prRhiDestroySamplerVk(PrRhiDevice *device, PrRhiSampler *sampler) {
if (!sampler) return;
vkDestroySampler((VkDevice)device->handle, (VkSampler)sampler->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&sampler, sizeof(PrRhiSampler));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&sampler, sizeof(PrRhiSampler));
}
// ============================================================================
// Shaders
// ============================================================================
PrRhiShader *prRhiCreateShaderVk(PrRhiDevice *device, PrRhiShaderDesc desc,
WpAllocator *allocator) {
PrRhiShader *prRhiCreateShaderVk(PrRhiDevice *device, PrRhiShaderDesc desc) {
VkShaderModuleCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
info.codeSize = desc.spirv_size;
@@ -1309,16 +1303,16 @@ PrRhiShader *prRhiCreateShaderVk(PrRhiDevice *device, PrRhiShaderDesc desc,
_checkVk(vkCreateShaderModule((VkDevice)device->handle, &info, NULL, &vk_module),
"vkCreateShaderModule");
PrRhiShader *shader = wpMemAllocatorAlloc(allocator, sizeof(PrRhiShader));
PrRhiShader *shader = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiShader));
if (!shader) _abort("alloc failed for PrRhiShader");
shader->handle = vk_module;
return shader;
}
void prRhiDestroyShaderVk(PrRhiDevice *device, PrRhiShader *shader, WpAllocator *allocator) {
void prRhiDestroyShaderVk(PrRhiDevice *device, PrRhiShader *shader) {
if (!shader) return;
vkDestroyShaderModule((VkDevice)device->handle, (VkShaderModule)shader->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&shader, sizeof(PrRhiShader));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&shader, sizeof(PrRhiShader));
}
// ============================================================================
@@ -1326,8 +1320,7 @@ void prRhiDestroyShaderVk(PrRhiDevice *device, PrRhiShader *shader, WpAllocator
// ============================================================================
PrRhiPipelineLayout *prRhiCreatePipelineLayoutVk(PrRhiDevice *device,
PrRhiPipelineLayoutDesc desc,
WpAllocator *allocator) {
PrRhiPipelineLayoutDesc desc) {
VkDevice vk_device = (VkDevice)device->handle;
// Gather descriptor set layouts
@@ -1337,7 +1330,7 @@ PrRhiPipelineLayout *prRhiCreatePipelineLayoutVk(PrRhiDevice *device,
VkDescriptorSetLayout *vk_layouts = vk_layouts_stack;
if (layout_count > 8) {
vk_layouts = wpArrayAllocCapacity(VkDescriptorSetLayout, allocator, layout_count, WP_ARRAY_INIT_NONE);
vk_layouts = wpArrayAllocCapacity(VkDescriptorSetLayout, &_G_RHI_CONTEXT.scratch, layout_count, WP_ARRAY_INIT_NONE);
if (!vk_layouts) _abort("alloc failed for VkDescriptorSetLayout array");
}
for (u32 i = 0; i < layout_count; ++i) {
@@ -1351,7 +1344,7 @@ PrRhiPipelineLayout *prRhiCreatePipelineLayoutVk(PrRhiDevice *device,
VkPushConstantRange *pc_ranges = pc_ranges_stack;
if (pc_count > 8) {
pc_ranges = wpArrayAllocCapacity(VkPushConstantRange, allocator, pc_count, WP_ARRAY_INIT_NONE);
pc_ranges = wpArrayAllocCapacity(VkPushConstantRange, &_G_RHI_CONTEXT.scratch, pc_count, WP_ARRAY_INIT_NONE);
if (!pc_ranges) _abort("alloc failed for VkPushConstantRange array");
}
for (u32 i = 0; i < pc_count; ++i) {
@@ -1372,23 +1365,22 @@ PrRhiPipelineLayout *prRhiCreatePipelineLayoutVk(PrRhiDevice *device,
"vkCreatePipelineLayout");
if (layout_count > 8) {
wpArrayDealloc(VkDescriptorSetLayout, allocator, &vk_layouts);
wpArrayDealloc(VkDescriptorSetLayout, &_G_RHI_CONTEXT.scratch, &vk_layouts);
}
if (pc_count > 8) {
wpArrayDealloc(VkPushConstantRange, allocator, &pc_ranges);
wpArrayDealloc(VkPushConstantRange, &_G_RHI_CONTEXT.scratch, &pc_ranges);
}
PrRhiPipelineLayout *layout = wpMemAllocatorAlloc(allocator, sizeof(PrRhiPipelineLayout));
PrRhiPipelineLayout *layout = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiPipelineLayout));
if (!layout) _abort("alloc failed for PrRhiPipelineLayout");
layout->handle = vk_layout;
return layout;
}
void prRhiDestroyPipelineLayoutVk(PrRhiDevice *device, PrRhiPipelineLayout *layout,
WpAllocator *allocator) {
void prRhiDestroyPipelineLayoutVk(PrRhiDevice *device, PrRhiPipelineLayout *layout) {
if (!layout) return;
vkDestroyPipelineLayout((VkDevice)device->handle, (VkPipelineLayout)layout->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&layout, sizeof(PrRhiPipelineLayout));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&layout, sizeof(PrRhiPipelineLayout));
}
// ============================================================================
@@ -1396,8 +1388,7 @@ void prRhiDestroyPipelineLayoutVk(PrRhiDevice *device, PrRhiPipelineLayout *layo
// ============================================================================
PrRhiPipeline *prRhiCreateGraphicsPipelineVk(PrRhiDevice *device,
PrRhiGraphicsPipelineDesc desc,
WpAllocator *allocator) {
PrRhiGraphicsPipelineDesc desc) {
VkDevice vk_device = (VkDevice)device->handle;
// Shader stages
@@ -1554,15 +1545,14 @@ PrRhiPipeline *prRhiCreateGraphicsPipelineVk(PrRhiDevice *device,
_checkVk(vkCreateGraphicsPipelines(vk_device, VK_NULL_HANDLE, 1, &pi, NULL, &vk_pipeline),
"vkCreateGraphicsPipelines");
PrRhiPipeline *pipeline = wpMemAllocatorAlloc(allocator, sizeof(PrRhiPipeline));
PrRhiPipeline *pipeline = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiPipeline));
if (!pipeline) _abort("alloc failed for PrRhiPipeline");
pipeline->handle = vk_pipeline;
return pipeline;
}
PrRhiPipeline *prRhiCreateComputePipelineVk(PrRhiDevice *device,
PrRhiComputePipelineDesc desc,
WpAllocator *allocator) {
PrRhiComputePipelineDesc desc) {
VkComputePipelineCreateInfo pi = {};
pi.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
pi.stage = (VkPipelineShaderStageCreateInfo){
@@ -1577,16 +1567,16 @@ PrRhiPipeline *prRhiCreateComputePipelineVk(PrRhiDevice *device,
_checkVk(vkCreateComputePipelines((VkDevice)device->handle, VK_NULL_HANDLE, 1, &pi, NULL, &vk_pipeline),
"vkCreateComputePipelines");
PrRhiPipeline *pipeline = wpMemAllocatorAlloc(allocator, sizeof(PrRhiPipeline));
PrRhiPipeline *pipeline = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiPipeline));
if (!pipeline) _abort("alloc failed for PrRhiPipeline");
pipeline->handle = vk_pipeline;
return pipeline;
}
void prRhiDestroyPipelineVk(PrRhiDevice *device, PrRhiPipeline *pipeline, WpAllocator *allocator) {
void prRhiDestroyPipelineVk(PrRhiDevice *device, PrRhiPipeline *pipeline) {
if (!pipeline) return;
vkDestroyPipeline((VkDevice)device->handle, (VkPipeline)pipeline->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&pipeline, sizeof(PrRhiPipeline));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&pipeline, sizeof(PrRhiPipeline));
}
// ============================================================================
@@ -1594,8 +1584,7 @@ void prRhiDestroyPipelineVk(PrRhiDevice *device, PrRhiPipeline *pipeline, WpAllo
// ============================================================================
PrRhiDescriptorSetLayout *prRhiCreateDescriptorSetLayoutVk(PrRhiDevice *device,
PrRhiDescriptorSetLayoutDesc desc,
WpAllocator *allocator) {
PrRhiDescriptorSetLayoutDesc desc) {
VkDevice vk_device = (VkDevice)device->handle;
u32 binding_count = (desc.bindings && wpArrayCount(desc.bindings) > 0)
@@ -1628,17 +1617,16 @@ PrRhiDescriptorSetLayout *prRhiCreateDescriptorSetLayoutVk(PrRhiDevice *device,
_checkVk(vkCreateDescriptorSetLayout(vk_device, &info, NULL, &vk_layout),
"vkCreateDescriptorSetLayout");
PrRhiDescriptorSetLayout *layout = wpMemAllocatorAlloc(allocator, sizeof(PrRhiDescriptorSetLayout));
PrRhiDescriptorSetLayout *layout = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiDescriptorSetLayout));
if (!layout) _abort("alloc failed for PrRhiDescriptorSetLayout");
layout->handle = vk_layout;
return layout;
}
void prRhiDestroyDescriptorSetLayoutVk(PrRhiDevice *device, PrRhiDescriptorSetLayout *layout,
WpAllocator *allocator) {
void prRhiDestroyDescriptorSetLayoutVk(PrRhiDevice *device, PrRhiDescriptorSetLayout *layout) {
if (!layout) return;
vkDestroyDescriptorSetLayout((VkDevice)device->handle, (VkDescriptorSetLayout)layout->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&layout, sizeof(PrRhiDescriptorSetLayout));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&layout, sizeof(PrRhiDescriptorSetLayout));
}
// ============================================================================
@@ -1646,8 +1634,7 @@ void prRhiDestroyDescriptorSetLayoutVk(PrRhiDevice *device, PrRhiDescriptorSetLa
// ============================================================================
PrRhiDescriptorPool *prRhiCreateDescriptorPoolVk(PrRhiDevice *device,
PrRhiDescriptorPoolDesc desc,
WpAllocator *allocator) {
PrRhiDescriptorPoolDesc desc) {
VkDevice vk_device = (VkDevice)device->handle;
u32 pool_size_count = (desc.pool_sizes && wpArrayCount(desc.pool_sizes) > 0)
@@ -1669,17 +1656,16 @@ PrRhiDescriptorPool *prRhiCreateDescriptorPoolVk(PrRhiDevice *device,
_checkVk(vkCreateDescriptorPool(vk_device, &info, NULL, &vk_pool),
"vkCreateDescriptorPool");
PrRhiDescriptorPool *pool = wpMemAllocatorAlloc(allocator, sizeof(PrRhiDescriptorPool));
PrRhiDescriptorPool *pool = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiDescriptorPool));
if (!pool) _abort("alloc failed for PrRhiDescriptorPool");
pool->handle = vk_pool;
return pool;
}
void prRhiDestroyDescriptorPoolVk(PrRhiDevice *device, PrRhiDescriptorPool *pool,
WpAllocator *allocator) {
void prRhiDestroyDescriptorPoolVk(PrRhiDevice *device, PrRhiDescriptorPool *pool) {
if (!pool) return;
vkDestroyDescriptorPool((VkDevice)device->handle, (VkDescriptorPool)pool->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&pool, sizeof(PrRhiDescriptorPool));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&pool, sizeof(PrRhiDescriptorPool));
}
// ============================================================================
@@ -1689,7 +1675,7 @@ void prRhiDestroyDescriptorPoolVk(PrRhiDevice *device, PrRhiDescriptorPool *pool
PrRhiDescriptorSet *prRhiAllocateDescriptorSetVk(PrRhiDevice *device,
PrRhiDescriptorPool *pool,
PrRhiDescriptorSetLayout *layout,
u32 variable_count, WpAllocator *allocator) {
u32 variable_count) {
VkDevice vk_device = (VkDevice)device->handle;
VkDescriptorSetVariableDescriptorCountAllocateInfo var_info = {};
@@ -1710,20 +1696,20 @@ PrRhiDescriptorSet *prRhiAllocateDescriptorSetVk(PrRhiDevice *device,
_checkVk(vkAllocateDescriptorSets(vk_device, &info, &vk_set),
"vkAllocateDescriptorSets");
PrRhiDescriptorSet *set = wpMemAllocatorAlloc(allocator, sizeof(PrRhiDescriptorSet));
PrRhiDescriptorSet *set = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiDescriptorSet));
if (!set) _abort("alloc failed for PrRhiDescriptorSet");
set->handle = vk_set;
return set;
}
void prRhiFreeDescriptorSetVk(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSet *set, WpAllocator *allocator) {
PrRhiDescriptorSet *set) {
if (!set) return;
VkDevice vk_device = (VkDevice)device->handle;
VkDescriptorSet vk_set = (VkDescriptorSet)set->handle;
_checkVk(vkFreeDescriptorSets(vk_device, (VkDescriptorPool)pool->handle, 1, &vk_set),
"vkFreeDescriptorSets");
wpMemAllocatorFree(allocator, (void**)&set, sizeof(PrRhiDescriptorSet));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&set, sizeof(PrRhiDescriptorSet));
}
void prRhiUpdateDescriptorSetVk(PrRhiDevice *device, PrRhiWriteDescriptorSetArray writes) {
@@ -1788,8 +1774,7 @@ void prRhiUpdateDescriptorSetVk(PrRhiDevice *device, PrRhiWriteDescriptorSetArra
// Fences
// ============================================================================
PrRhiFence *prRhiCreateFenceVk(PrRhiDevice *device, PrRhiFenceDesc desc,
WpAllocator *allocator) {
PrRhiFence *prRhiCreateFenceVk(PrRhiDevice *device, PrRhiFenceDesc desc) {
VkFenceCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
info.flags = desc.signaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0;
@@ -1798,16 +1783,16 @@ PrRhiFence *prRhiCreateFenceVk(PrRhiDevice *device, PrRhiFenceDesc desc,
_checkVk(vkCreateFence((VkDevice)device->handle, &info, NULL, &vk_fence),
"vkCreateFence");
PrRhiFence *fence = wpMemAllocatorAlloc(allocator, sizeof(PrRhiFence));
PrRhiFence *fence = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiFence));
if (!fence) _abort("alloc failed for PrRhiFence");
fence->handle = vk_fence;
return fence;
}
void prRhiDestroyFenceVk(PrRhiDevice *device, PrRhiFence *fence, WpAllocator *allocator) {
void prRhiDestroyFenceVk(PrRhiDevice *device, PrRhiFence *fence) {
if (!fence) return;
vkDestroyFence((VkDevice)device->handle, (VkFence)fence->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&fence, sizeof(PrRhiFence));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&fence, sizeof(PrRhiFence));
}
void prRhiWaitForFencesVk(PrRhiDevice *device, PrRhiFenceArray fences, u32 count,
@@ -1836,7 +1821,7 @@ void prRhiResetFencesVk(PrRhiDevice *device, PrRhiFenceArray fences, u32 count)
// Semaphores
// ============================================================================
PrRhiSemaphore *prRhiCreateSemaphoreVk(PrRhiDevice *device, WpAllocator *allocator) {
PrRhiSemaphore *prRhiCreateSemaphoreVk(PrRhiDevice *device) {
VkSemaphoreCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
@@ -1844,24 +1829,23 @@ PrRhiSemaphore *prRhiCreateSemaphoreVk(PrRhiDevice *device, WpAllocator *allocat
_checkVk(vkCreateSemaphore((VkDevice)device->handle, &info, NULL, &vk_semaphore),
"vkCreateSemaphore");
PrRhiSemaphore *semaphore = wpMemAllocatorAlloc(allocator, sizeof(PrRhiSemaphore));
PrRhiSemaphore *semaphore = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiSemaphore));
if (!semaphore) _abort("alloc failed for PrRhiSemaphore");
semaphore->handle = vk_semaphore;
return semaphore;
}
void prRhiDestroySemaphoreVk(PrRhiDevice *device, PrRhiSemaphore *semaphore, WpAllocator *allocator) {
void prRhiDestroySemaphoreVk(PrRhiDevice *device, PrRhiSemaphore *semaphore) {
if (!semaphore) return;
vkDestroySemaphore((VkDevice)device->handle, (VkSemaphore)semaphore->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&semaphore, sizeof(PrRhiSemaphore));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&semaphore, sizeof(PrRhiSemaphore));
}
// ============================================================================
// Command pools
// ============================================================================
PrRhiCommandPool *prRhiCreateCommandPoolVk(PrRhiDevice *device, PrRhiCommandPoolDesc desc,
WpAllocator *allocator) {
PrRhiCommandPool *prRhiCreateCommandPoolVk(PrRhiDevice *device, PrRhiCommandPoolDesc desc) {
VkCommandPoolCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
@@ -1871,20 +1855,20 @@ PrRhiCommandPool *prRhiCreateCommandPoolVk(PrRhiDevice *device, PrRhiCommandPool
_checkVk(vkCreateCommandPool((VkDevice)device->handle, &info, NULL, &vk_pool),
"vkCreateCommandPool");
PrRhiCommandPool *pool = wpMemAllocatorAlloc(allocator, sizeof(PrRhiCommandPool));
PrRhiCommandPool *pool = wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiCommandPool));
if (!pool) _abort("alloc failed for PrRhiCommandPool");
pool->handle = vk_pool;
return pool;
}
void prRhiDestroyCommandPoolVk(PrRhiDevice *device, PrRhiCommandPool *pool, WpAllocator *allocator) {
void prRhiDestroyCommandPoolVk(PrRhiDevice *device, PrRhiCommandPool *pool) {
if (!pool) return;
vkDestroyCommandPool((VkDevice)device->handle, (VkCommandPool)pool->handle, NULL);
wpMemAllocatorFree(allocator, (void**)&pool, sizeof(PrRhiCommandPool));
wpMemAllocatorFree(&_G_RHI_CONTEXT.main, (void**)&pool, sizeof(PrRhiCommandPool));
}
PrRhiCommandBufferArray prRhiAllocateCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, WpAllocator *allocator) {
u32 count) {
VkCommandBufferAllocateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
info.commandPool = (VkCommandPool)pool->handle;
@@ -1894,7 +1878,7 @@ PrRhiCommandBufferArray prRhiAllocateCommandBuffersVk(PrRhiDevice *device, PrRhi
VkCommandBuffer vk_cbs[16] = {0};
u32 real_count = count < 16 ? count : 16;
VkCommandBufferArray vk_cb_array = wpArrayAllocCapacity(VkCommandBuffer, allocator, real_count, WP_ARRAY_INIT_NONE);
VkCommandBufferArray vk_cb_array = wpArrayAllocCapacity(VkCommandBuffer, &_G_RHI_CONTEXT.scratch, real_count, WP_ARRAY_INIT_NONE);
if (!vk_cb_array) _abort("alloc failed for VkCommandBuffer array");
_checkVk(vkAllocateCommandBuffers((VkDevice)device->handle, &info, vk_cbs),
@@ -1904,17 +1888,17 @@ PrRhiCommandBufferArray prRhiAllocateCommandBuffersVk(PrRhiDevice *device, PrRhi
wpArrayAppendCapped(VkCommandBuffer, vk_cb_array, &vk_cbs[i]);
}
PrRhiCommandBufferArray cbs = wpArrayAllocCapacity(PrRhiCommandBuffer *, allocator, real_count, WP_ARRAY_INIT_NONE);
PrRhiCommandBufferArray cbs = wpArrayAllocCapacity(PrRhiCommandBuffer *, &_G_RHI_CONTEXT.main, real_count, WP_ARRAY_INIT_NONE);
if (!cbs) _abort("alloc failed for PrRhiCommandBuffer array");
for (u32 i = 0; i < real_count; ++i) {
PrRhiCommandBuffer *cb = (PrRhiCommandBuffer *)wpMemAllocatorAlloc(allocator, sizeof(PrRhiCommandBuffer));
PrRhiCommandBuffer *cb = (PrRhiCommandBuffer *)wpMemAllocatorAlloc(&_G_RHI_CONTEXT.main, sizeof(PrRhiCommandBuffer));
if (!cb) _abort("alloc failed for PrRhiCommandBuffer");
cb->handle = vk_cb_array[i];
wpArrayAppendCapped(PrRhiCommandBuffer *, cbs, &cb);
}
wpArrayDealloc(VkCommandBuffer, allocator, &vk_cb_array);
wpArrayDealloc(VkCommandBuffer, &_G_RHI_CONTEXT.scratch, &vk_cb_array);
return cbs;
}
@@ -1933,12 +1917,6 @@ void prRhiFreeCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool,
}
vkFreeCommandBuffers(vk_device, vk_pool, real_count, vk_cbs);
// Free PrRhiCommandBuffer structs
for (u32 i = 0; i < real_count; ++i) {
// These were allocated from the same allocator
// Since they're in an array, we need root allocator — skip, caller handles
}
}
// ============================================================================
+39 -62
View File
@@ -122,123 +122,100 @@ struct PrRhiSemaphore {
// Function declarations
// ============================================================================
PrRhiInstance *prRhiCreateInstanceVk(PrRhiInstanceDesc desc, WpAllocator *allocator);
void prRhiDestroyInstanceVk(PrRhiInstance *inst, WpAllocator *allocator);
PrRhiInstance *prRhiCreateInstanceVk(PrRhiInstanceDesc desc);
void prRhiDestroyInstanceVk(PrRhiInstance *inst);
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevicesVk(PrRhiInstance *inst, const WpAllocator *allocator);
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevicesVk(PrRhiInstance *inst);
void prRhiGetPhysicalDeviceNameVk(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceDriverInfoVk(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDevicePropertiesVk(PrRhiPhysicalDevice *pdev,
PrRhiPhysicalDeviceProperties *out);
PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, void *window_handle,
WpAllocator *allocator);
void prRhiDestroySurfaceVk(PrRhiInstance *inst, PrRhiSurface *surface, WpAllocator *allocator);
PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, void *window_handle);
void prRhiDestroySurfaceVk(PrRhiInstance *inst, PrRhiSurface *surface);
PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilitiesVk(PrRhiPhysicalDevice *pdev,
PrRhiSurface *surface);
PrRhiDevice *prRhiCreateDeviceVk(PrRhiPhysicalDevice *pdev, PrRhiSurface *surface,
PrRhiDeviceDesc desc, WpAllocator *allocator);
void prRhiDestroyDeviceVk(PrRhiDevice *device, WpAllocator *allocator);
PrRhiDeviceDesc desc);
void prRhiDestroyDeviceVk(PrRhiDevice *device);
void prRhiDeviceWaitIdleVk(PrRhiDevice *device);
u32 prRhiGetQueueFamilyIndexVk(PrRhiDevice *device);
PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc desc,
WpAllocator *allocator);
void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain,
WpAllocator *allocator);
PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc desc);
void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain);
PrRhiSwapchainResult prRhiAcquireNextImageVk(PrRhiDevice *device, PrRhiSwapchain *swapchain,
PrRhiSemaphore *signal_semaphore, u32 *out_image_index);
PrRhiSwapchainResult prRhiPresentVk(PrRhiDevice *device, PrRhiSwapchain *swapchain,
PrRhiSemaphore *wait_semaphore);
void prRhiRecreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchain **swapchain,
u32 width, u32 height, WpAllocator *allocator);
u32 width, u32 height);
PrRhiTexture *prRhiGetSwapchainTextureVk(PrRhiSwapchain *swapchain, u32 image_index);
PrRhiTexture *prRhiGetSwapchainDepthTextureVk(PrRhiSwapchain *swapchain);
PrRhiFormat prRhiGetSwapchainFormatVk(PrRhiSwapchain *swapchain);
PrRhiBuffer *prRhiCreateBufferVk(PrRhiDevice *device, PrRhiBufferDesc desc,
WpAllocator *allocator);
void prRhiDestroyBufferVk(PrRhiDevice *device, PrRhiBuffer *buffer, WpAllocator *allocator);
PrRhiBuffer *prRhiCreateBufferVk(PrRhiDevice *device, PrRhiBufferDesc desc);
void prRhiDestroyBufferVk(PrRhiDevice *device, PrRhiBuffer *buffer);
void *prRhiBufferMapVk(PrRhiDevice *device, PrRhiBuffer *buffer);
void prRhiBufferUnmapVk(PrRhiDevice *device, PrRhiBuffer *buffer);
PrRhiDeviceAddress prRhiGetBufferDeviceAddressVk(PrRhiDevice *device, PrRhiBuffer *buffer);
PrRhiTexture *prRhiCreateTextureVk(PrRhiDevice *device, PrRhiTextureDesc desc,
WpAllocator *allocator);
PrRhiTexture *prRhiCreateTextureVk(PrRhiDevice *device, PrRhiTextureDesc desc);
PrRhiTexture *prRhiCreateTextureFromKtxVk(PrRhiDevice *device, const char *path,
PrRhiCommandPool *pool, PrRhiCommandBuffer *cb,
WpAllocator *allocator);
void prRhiDestroyTextureVk(PrRhiDevice *device, PrRhiTexture *texture,
WpAllocator *allocator);
PrRhiCommandPool *pool, PrRhiCommandBuffer *cb);
void prRhiDestroyTextureVk(PrRhiDevice *device, PrRhiTexture *texture);
PrRhiSampler *prRhiCreateSamplerVk(PrRhiDevice *device, PrRhiSamplerDesc desc,
WpAllocator *allocator);
void prRhiDestroySamplerVk(PrRhiDevice *device, PrRhiSampler *sampler,
WpAllocator *allocator);
PrRhiSampler *prRhiCreateSamplerVk(PrRhiDevice *device, PrRhiSamplerDesc desc);
void prRhiDestroySamplerVk(PrRhiDevice *device, PrRhiSampler *sampler);
PrRhiShader *prRhiCreateShaderVk(PrRhiDevice *device, PrRhiShaderDesc desc,
WpAllocator *allocator);
void prRhiDestroyShaderVk(PrRhiDevice *device, PrRhiShader *shader, WpAllocator *allocator);
PrRhiShader *prRhiCreateShaderVk(PrRhiDevice *device, PrRhiShaderDesc desc);
void prRhiDestroyShaderVk(PrRhiDevice *device, PrRhiShader *shader);
PrRhiPipelineLayout *prRhiCreatePipelineLayoutVk(PrRhiDevice *device,
PrRhiPipelineLayoutDesc desc,
WpAllocator *allocator);
PrRhiPipelineLayoutDesc desc);
void prRhiDestroyPipelineLayoutVk(PrRhiDevice *device,
PrRhiPipelineLayout *layout,
WpAllocator *allocator);
PrRhiPipelineLayout *layout);
PrRhiPipeline *prRhiCreateGraphicsPipelineVk(PrRhiDevice *device,
PrRhiGraphicsPipelineDesc desc,
WpAllocator *allocator);
PrRhiGraphicsPipelineDesc desc);
PrRhiPipeline *prRhiCreateComputePipelineVk(PrRhiDevice *device,
PrRhiComputePipelineDesc desc,
WpAllocator *allocator);
void prRhiDestroyPipelineVk(PrRhiDevice *device, PrRhiPipeline *pipeline,
WpAllocator *allocator);
PrRhiComputePipelineDesc desc);
void prRhiDestroyPipelineVk(PrRhiDevice *device, PrRhiPipeline *pipeline);
PrRhiDescriptorSetLayout *prRhiCreateDescriptorSetLayoutVk(PrRhiDevice *device,
PrRhiDescriptorSetLayoutDesc desc,
WpAllocator *allocator);
PrRhiDescriptorSetLayoutDesc desc);
void prRhiDestroyDescriptorSetLayoutVk(PrRhiDevice *device,
PrRhiDescriptorSetLayout *layout,
WpAllocator *allocator);
PrRhiDescriptorSetLayout *layout);
PrRhiDescriptorPool *prRhiCreateDescriptorPoolVk(PrRhiDevice *device,
PrRhiDescriptorPoolDesc desc,
WpAllocator *allocator);
PrRhiDescriptorPoolDesc desc);
void prRhiDestroyDescriptorPoolVk(PrRhiDevice *device,
PrRhiDescriptorPool *pool,
WpAllocator *allocator);
PrRhiDescriptorPool *pool);
PrRhiDescriptorSet *prRhiAllocateDescriptorSetVk(PrRhiDevice *device,
PrRhiDescriptorPool *pool,
PrRhiDescriptorSetLayout *layout,
u32 variable_count, WpAllocator *allocator);
PrRhiDescriptorPool *pool,
PrRhiDescriptorSetLayout *layout,
u32 variable_count);
void prRhiFreeDescriptorSetVk(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSet *set, WpAllocator *allocator);
PrRhiDescriptorSet *set);
void prRhiUpdateDescriptorSetVk(PrRhiDevice *device, PrRhiWriteDescriptorSetArray writes);
PrRhiFence *prRhiCreateFenceVk(PrRhiDevice *device, PrRhiFenceDesc desc,
WpAllocator *allocator);
void prRhiDestroyFenceVk(PrRhiDevice *device, PrRhiFence *fence, WpAllocator *allocator);
PrRhiFence *prRhiCreateFenceVk(PrRhiDevice *device, PrRhiFenceDesc desc);
void prRhiDestroyFenceVk(PrRhiDevice *device, PrRhiFence *fence);
void prRhiWaitForFencesVk(PrRhiDevice *device, PrRhiFenceArray fences, u32 count,
b8 wait_all, u64 timeout_ns);
void prRhiResetFencesVk(PrRhiDevice *device, PrRhiFenceArray fences, u32 count);
PrRhiSemaphore *prRhiCreateSemaphoreVk(PrRhiDevice *device, WpAllocator *allocator);
void prRhiDestroySemaphoreVk(PrRhiDevice *device, PrRhiSemaphore *semaphore,
WpAllocator *allocator);
PrRhiSemaphore *prRhiCreateSemaphoreVk(PrRhiDevice *device);
void prRhiDestroySemaphoreVk(PrRhiDevice *device, PrRhiSemaphore *semaphore);
PrRhiCommandPool *prRhiCreateCommandPoolVk(PrRhiDevice *device,
PrRhiCommandPoolDesc desc,
WpAllocator *allocator);
void prRhiDestroyCommandPoolVk(PrRhiDevice *device, PrRhiCommandPool *pool,
WpAllocator *allocator);
PrRhiCommandPoolDesc desc);
void prRhiDestroyCommandPoolVk(PrRhiDevice *device, PrRhiCommandPool *pool);
PrRhiCommandBufferArray prRhiAllocateCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, WpAllocator *allocator);
u32 count);
void prRhiFreeCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, PrRhiCommandBufferArray buffers);