RHI vulkan updates

This commit is contained in:
2026-07-12 13:43:59 +01:00
parent bffe9b8174
commit 45a34bb151
10 changed files with 1361 additions and 1082 deletions
+2 -4
View File
@@ -7,11 +7,9 @@
PrRhiContext _G_RHI_CONTEXT;
void prRhiInit(void) {
_G_RHI_CONTEXT.main = wpMemArenaAllocatorInit(MiB(64));
_G_RHI_CONTEXT.scratch = wpMemArenaAllocatorInit(MiB(32));
_G_RHI_CONTEXT.allocator = wpMemArenaAllocatorInit(MiB(64));
}
void prRhiDestroy(void) {
wpMemArenaAllocatorDestroy(&_G_RHI_CONTEXT.scratch);
wpMemArenaAllocatorDestroy(&_G_RHI_CONTEXT.main);
wpMemArenaAllocatorDestroy(&_G_RHI_CONTEXT.allocator);
}
+14 -12
View File
@@ -24,6 +24,7 @@
#define PR_RHI_H
#include "pr_rhi_types.h"
#include <SDL3/SDL_video.h>
#ifdef __cplusplus
extern "C" {
@@ -45,17 +46,16 @@ void prRhiDestroyInstance(PrRhiInstance *inst);
// Physical device enumeration
// ======================================================================
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevices(PrRhiInstance *inst);
void prRhiGetPhysicalDeviceName(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceDriverInfo(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceProperties(PrRhiPhysicalDevice *pdev,
PrRhiPhysicalDeviceProperties *out);
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevices(PrRhiInstance *inst);
void prRhiGetPhysicalDeviceName(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceDriverInfo(PrRhiPhysicalDevice *pdev, WpStr8 *out);
PrRhiPhysicalDeviceProperties prRhiGetPhysicalDeviceProperties(PrRhiPhysicalDevice *pdev);
// ======================================================================
// Surface (platform-specific)
// ======================================================================
PrRhiSurface *prRhiCreateSurfaceFromWindow(PrRhiInstance *inst, void *window_handle);
PrRhiSurface *prRhiCreateSurfaceFromWindow(PrRhiInstance *inst, SDL_Window *window);
void prRhiDestroySurface(PrRhiInstance *inst, PrRhiSurface *surface);
PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilities(PrRhiPhysicalDevice *pdev,
PrRhiSurface *surface);
@@ -77,6 +77,7 @@ u32 prRhiGetQueueFamilyIndex(PrRhiDevice *device);
PrRhiSwapchain *prRhiCreateSwapchain(PrRhiDevice *device, PrRhiSwapchainDesc desc);
void prRhiDestroySwapchain(PrRhiDevice *device, PrRhiSwapchain *swapchain);
u32 prRhiGetSwapchainImageCount(PrRhiSwapchain *swapchain);
PrRhiSwapchainResult prRhiAcquireNextImage(PrRhiDevice *device, PrRhiSwapchain *swapchain,
PrRhiSemaphore *signal_semaphore, u32 *out_image_index);
@@ -167,8 +168,8 @@ void prRhiDestroyDescriptorPool(PrRhiDevice *device,
// ======================================================================
PrRhiDescriptorSet *prRhiAllocateDescriptorSet(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSetLayout *layout,
u32 variable_count);
PrRhiDescriptorSetLayout *layout,
WpU32Array variable_descriptor_counts);
void prRhiFreeDescriptorSet(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSet *set);
void prRhiUpdateDescriptorSet(PrRhiDevice *device, PrRhiWriteDescriptorSetArray writes);
@@ -191,13 +192,14 @@ void prRhiDestroySemaphore(PrRhiDevice *device, PrRhiSemaphore *semap
// Command pools and command buffers
// ======================================================================
PrRhiCommandPool *prRhiCreateCommandPool(PrRhiDevice *device, PrRhiCommandPoolDesc desc);
PrRhiCommandPool *prRhiCreateCommandPool(PrRhiDevice *device);
void prRhiDestroyCommandPool(PrRhiDevice *device, PrRhiCommandPool *pool);
PrRhiCommandBufferArray prRhiAllocateCommandBuffers(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count);
void prRhiFreeCommandBuffers(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, PrRhiCommandBufferArray buffers);
PrRhiCommandBufferArray buffers);
// ======================================================================
// Command buffer recording
@@ -238,8 +240,8 @@ void prRhiCmdPushConstants(PrRhiCommandBuffer *cb, PrRhiPipelineLayout *layout,
// --- Vertex / index buffers ---
void prRhiCmdBindVertexBuffers(PrRhiCommandBuffer *cb, u32 first_binding,
PrRhiBufferArray buffers, const u64 *offsets, u32 count);
void prRhiCmdBindVertexBuffers(PrRhiCommandBuffer *cb, u32 first_binding, PrRhiBufferArray buffers,
WpU64Array offsets);
void prRhiCmdBindIndexBuffer(PrRhiCommandBuffer *cb, PrRhiBuffer *buffer, u64 offset,
PrRhiIndexType index_type);
+44 -7
View File
@@ -357,9 +357,40 @@ typedef struct PrRhiPipelineLayoutDesc {
PrRhiPushConstantRangeArray push_constant_ranges;
} PrRhiPipelineLayoutDesc;
typedef enum PrRhiPolygonMode {
PR_RHI_POLYGON_MODE_FILL = 0,
PR_RHI_POLYGON_MODE_LINE = 1,
PR_RHI_POLYGON_MODE_POINT = 2,
} PrRhiPolygonMode;
typedef enum PrRhiCullMode {
PR_RHI_CULL_MODE_NONE = 0,
PR_RHI_CULL_MODE_FRONT = 0x00000001,
PR_RHI_CULL_MODE_BACK = 0x00000002,
PR_RHI_CULL_MODE_FRONT_AND_BACK = 0x00000003,
} PrRhiCullMode;
typedef enum PrRhiFrontFace {
PR_RHI_FRONT_FACE_COUNTER_CLOCKWISE = 0,
PR_RHI_FRONT_FACE_CLOCKWISE = 1,
} PrRhiFrontFace;
typedef enum PrRhiMultisampleCount {
PR_RHI_SAMPLE_COUNT_1 = 0x00000001,
PR_RHI_SAMPLE_COUNT_2 = 0x00000002,
PR_RHI_SAMPLE_COUNT_4 = 0x00000004,
PR_RHI_SAMPLE_COUNT_8 = 0x00000008,
PR_RHI_SAMPLE_COUNT_16 = 0x00000010,
PR_RHI_SAMPLE_COUNT_32 = 0x00000020,
PR_RHI_SAMPLE_COUNT_64 = 0x00000040,
} PrRhiMultisampleCount;
typedef struct PrRhiGraphicsPipelineDesc {
PrRhiShader *vertex_shader;
const char *vertex_shader_entry_point;
PrRhiShader *fragment_shader;
const char *fragment_shader_entry_point;
PrRhiVertexInputBindingArray vertex_bindings;
PrRhiVertexAttributeArray vertex_attributes;
@@ -378,11 +409,22 @@ typedef struct PrRhiGraphicsPipelineDesc {
b8 dynamic_viewport;
b8 dynamic_scissor;
PrRhiPolygonMode polygon_mode;
PrRhiCullMode cull_mode;
PrRhiFrontFace front_face;
f32 line_width;
PrRhiMultisampleCount multisample_count;
PrRhiPipelineLayout *layout;
} PrRhiGraphicsPipelineDesc;
typedef struct PrRhiComputePipelineDesc {
PrRhiShader *shader;
const char *shader_entry_point;
PrRhiPipelineLayout *layout;
} PrRhiComputePipelineDesc;
@@ -408,10 +450,6 @@ typedef struct PrRhiFenceDesc {
b8 signaled;
} PrRhiFenceDesc;
typedef struct PrRhiCommandPoolDesc {
u32 queue_family_index;
} PrRhiCommandPoolDesc;
typedef struct PrRhiSwapchainDesc {
PrRhiSurface *surface;
u32 width;
@@ -432,7 +470,7 @@ typedef struct PrRhiSurfaceCapabilities {
} PrRhiSurfaceCapabilities;
typedef struct PrRhiPhysicalDeviceProperties {
u32 api_version;
u32 api_version;
PrRhiPhysicalDeviceType device_type;
} PrRhiPhysicalDeviceProperties;
@@ -443,8 +481,7 @@ typedef u64 PrRhiDeviceAddress;
// ============================================================================
typedef struct PrRhiContext {
WpAllocator main;
WpAllocator scratch;
WpAllocator allocator;
} PrRhiContext;
// --- Command buffer types ---
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -8,6 +8,7 @@
#define PR_RHI_VK_H
#include "../pr_rhi_types.h"
#include <SDL3/SDL_video.h>
#include <volk/volk.h>
#include <vk_mem_alloc.h>
@@ -128,10 +129,9 @@ void prRhiDestroyInstanceVk(PrRhiInstance *inst);
PrRhiPhysicalDeviceArray prRhiGetPhysicalDevicesVk(PrRhiInstance *inst);
void prRhiGetPhysicalDeviceNameVk(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDeviceDriverInfoVk(PrRhiPhysicalDevice *pdev, WpStr8 *out);
void prRhiGetPhysicalDevicePropertiesVk(PrRhiPhysicalDevice *pdev,
PrRhiPhysicalDeviceProperties *out);
PrRhiPhysicalDeviceProperties prRhiGetPhysicalDevicePropertiesVk(PrRhiPhysicalDevice *pdev);
PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, void *window_handle);
PrRhiSurface *prRhiCreateSurfaceFromWindowVk(PrRhiInstance *inst, SDL_Window *window);
void prRhiDestroySurfaceVk(PrRhiInstance *inst, PrRhiSurface *surface);
PrRhiSurfaceCapabilities prRhiGetSurfaceCapabilitiesVk(PrRhiPhysicalDevice *pdev,
@@ -145,6 +145,7 @@ u32 prRhiGetQueueFamilyIndexVk(PrRhiDevice *device);
PrRhiSwapchain *prRhiCreateSwapchainVk(PrRhiDevice *device, PrRhiSwapchainDesc desc);
void prRhiDestroySwapchainVk(PrRhiDevice *device, PrRhiSwapchain *swapchain);
u32 prRhiGetSwapchainImageCountVk(PrRhiSwapchain *swapchain);
PrRhiSwapchainResult prRhiAcquireNextImageVk(PrRhiDevice *device, PrRhiSwapchain *swapchain,
PrRhiSemaphore *signal_semaphore, u32 *out_image_index);
PrRhiSwapchainResult prRhiPresentVk(PrRhiDevice *device, PrRhiSwapchain *swapchain,
@@ -196,7 +197,7 @@ void prRhiDestroyDescriptorPoolVk(PrRhiDevice *device,
PrRhiDescriptorSet *prRhiAllocateDescriptorSetVk(PrRhiDevice *device,
PrRhiDescriptorPool *pool,
PrRhiDescriptorSetLayout *layout,
u32 variable_count);
WpU32Array variable_descriptor_counts);
void prRhiFreeDescriptorSetVk(PrRhiDevice *device, PrRhiDescriptorPool *pool,
PrRhiDescriptorSet *set);
void prRhiUpdateDescriptorSetVk(PrRhiDevice *device, PrRhiWriteDescriptorSetArray writes);
@@ -211,13 +212,12 @@ void prRhiResetFencesVk(PrRhiDevice *device, PrRhiFenceArray fences, u32 count);
PrRhiSemaphore *prRhiCreateSemaphoreVk(PrRhiDevice *device);
void prRhiDestroySemaphoreVk(PrRhiDevice *device, PrRhiSemaphore *semaphore);
PrRhiCommandPool *prRhiCreateCommandPoolVk(PrRhiDevice *device,
PrRhiCommandPoolDesc desc);
PrRhiCommandPool *prRhiCreateCommandPoolVk(PrRhiDevice *device);
void prRhiDestroyCommandPoolVk(PrRhiDevice *device, PrRhiCommandPool *pool);
PrRhiCommandBufferArray prRhiAllocateCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count);
void prRhiFreeCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool,
u32 count, PrRhiCommandBufferArray buffers);
void prRhiFreeCommandBuffersVk(PrRhiDevice *device, PrRhiCommandPool *pool, PrRhiCommandBufferArray buffers);
void prRhiBeginCommandBufferVk(PrRhiCommandBuffer *cb);
void prRhiEndCommandBufferVk(PrRhiCommandBuffer *cb);
@@ -243,8 +243,8 @@ void prRhiCmdBindDescriptorSetsVk(PrRhiCommandBuffer *cb, PrRhiPipelineBindPoint
void prRhiCmdPushConstantsVk(PrRhiCommandBuffer *cb, PrRhiPipelineLayout *layout,
PrRhiShaderStage stage_flags, u32 offset, u32 size,
const void *data);
void prRhiCmdBindVertexBuffersVk(PrRhiCommandBuffer *cb, u32 first_binding,
PrRhiBufferArray buffers, const u64 *offsets, u32 count);
void prRhiCmdBindVertexBuffersVk(PrRhiCommandBuffer *cb, u32 first_binding, PrRhiBufferArray buffers,
WpU64Array offsets);
void prRhiCmdBindIndexBufferVk(PrRhiCommandBuffer *cb, PrRhiBuffer *buffer, u64 offset,
PrRhiIndexType index_type);
+2 -1
View File
@@ -17,9 +17,10 @@
#define prRhiCreateDevice prRhiCreateDeviceVk
#define prRhiDestroyDevice prRhiDestroyDeviceVk
#define prRhiDeviceWaitIdle prRhiDeviceWaitIdleVk
#define prRhiGetQueueFamilyIndex prRhiGetQueueFamilyIndexVk
#define prRhiGetQueueFamilyIndex prRhiGetQueueFamilyIndexVk
#define prRhiCreateSwapchain prRhiCreateSwapchainVk
#define prRhiDestroySwapchain prRhiDestroySwapchainVk
#define prRhiGetSwapchainImageCount prRhiGetSwapchainImageCountVk
#define prRhiAcquireNextImage prRhiAcquireNextImageVk
#define prRhiPresent prRhiPresentVk
#define prRhiRecreateSwapchain prRhiRecreateSwapchainVk