adding some function pfn implementations

This commit is contained in:
2025-11-25 22:28:17 +01:00
parent 0c2ab2b539
commit e34714930c
6 changed files with 437 additions and 45 deletions

152
README.md
View File

@@ -27,12 +27,162 @@ The precise ritual varies by system — consult the tomes of your operating syst
Use at your own risk. If thy machine shudders, weeps, or attempts to flee — know that it was warned. Use at your own risk. If thy machine shudders, weeps, or attempts to flee — know that it was warned.
\ \
\ \
\
Thou may also conjure forth a tome of compile commands by doing thus: Thou may also conjure forth a tome of compile commands by doing thus:
``` ```
zig build cdb zig build cdb
``` ```
## Vulkan 1.0 specification
<details>
<summary>
The present standing of thy Vulkan 1.0 specification's implementation
</summary>
\
⚠️ Implemented, yet perchance not fully tested nor proven conformant, but rather working in a manner most general to thee and thine.
Name | Status
-----------------------------------------------|--------
vkAllocateCommandBuffers | ✅ Implemented
vkAllocateDescriptorSets | ⚙️ WIP
vkAllocateMemory | ✅ Implemented
vkBeginCommandBuffer | ✅ Implemented
vkBindBufferMemory | ✅ Implemented
vkBindImageMemory | ✅ Implemented
vkCmdBeginQuery | ⚙️ WIP
vkCmdBeginRenderPass | ⚙️ WIP
vkCmdBindDescriptorSets | ⚙️ WIP
vkCmdBindIndexBuffer | ⚙️ WIP
vkCmdBindPipeline | ⚙️ WIP
vkCmdBindVertexBuffers | ⚙️ WIP
vkCmdBlitImage | ⚙️ WIP
vkCmdClearAttachments | ⚙️ WIP
vkCmdClearColorImage | ⚙️ WIP
vkCmdClearDepthStencilImage | ⚙️ WIP
vkCmdCopyBuffer | ✅ Implemented
vkCmdCopyBufferToImage | ⚙️ WIP
vkCmdCopyImage | ⚙️ WIP
vkCmdCopyImageToBuffer | ❌ Not implemented
vkCmdCopyQueryPoolResults | ❌ Not implemented
vkCmdDispatch | ❌ Not implemented
vkCmdDispatchIndirect | ❌ Not implemented
vkCmdDraw | ❌ Not implemented
vkCmdDrawIndexed | ❌ Not implemented
vkCmdDrawIndexedIndirect | ❌ Not implemented
vkCmdDrawIndirect | ❌ Not implemented
vkCmdEndQuery | ❌ Not implemented
vkCmdEndRenderPass | ❌ Not implemented
vkCmdExecuteCommands | ❌ Not implemented
vkCmdFillBuffer | ✅ Implemented
vkCmdNextSubpass | ❌ Not implemented
vkCmdPipelineBarrier | ❌ Not implemented
vkCmdPushConstants | ❌ Not implemented
vkCmdResetEvent | ❌ Not implemented
vkCmdResetQueryPool | ❌ Not implemented
vkCmdResolveImage | ❌ Not implemented
vkCmdSetBlendConstants | ❌ Not implemented
vkCmdSetDepthBias | ❌ Not implemented
vkCmdSetDepthBounds | ❌ Not implemented
vkCmdSetEvent | ❌ Not implemented
vkCmdSetLineWidth | ❌ Not implemented
vkCmdSetScissor | ❌ Not implemented
vkCmdSetStencilCompareMask | ❌ Not implemented
vkCmdSetStencilReference | ❌ Not implemented
vkCmdSetStencilWriteMask | ❌ Not implemented
vkCmdSetViewport | ❌ Not implemented
vkCmdUpdateBuffer | ❌ Not implemented
vkCmdWaitEvents | ❌ Not implemented
vkCmdWriteTimestamp | ❌ Not implemented
vkCreateBuffer | ✅ Implemented
vkCreateBufferView | ❌ Not implemented
vkCreateCommandPool | ❌ Not implemented
vkCreateComputePipelines | ❌ Not implemented
vkCreateDescriptorPool | ❌ Not implemented
vkCreateDescriptorSetLayout | ❌ Not implemented
vkCreateDevice | ✅ Implemented
vkCreateEvent | ❌ Not implemented
vkCreateFence | ✅ Implemented
vkCreateFramebuffer | ❌ Not implemented
vkCreateGraphicsPipelines | ❌ Not implemented
vkCreateImage | ✅ Implemented
vkCreateImageView | ✅ Implemented
vkCreateInstance | ✅ Implemented
vkCreatePipelineCache | ❌ Not implemented
vkCreatePipelineLayout | ❌ Not implemented
vkCreateQueryPool | ❌ Not implemented
vkCreateRenderPass | ❌ Not implemented
vkCreateSampler | ❌ Not implemented
vkCreateSemaphore | ❌ Not implemented
vkCreateShaderModule | ❌ Not implemented
vkDestroyBuffer | ✅ Implemented
vkDestroyBufferView | ❌ Not implemented
vkDestroyCommandPool | ❌ Not implemented
vkDestroyDescriptorPool | ❌ Not implemented
vkDestroyDescriptorSetLayout | ❌ Not implemented
vkDestroyDevice | ✅ Implemented
vkDestroyEvent | ❌ Not implemented
vkDestroyFence | ✅ Implemented
vkDestroyFramebuffer | ❌ Not implemented
vkDestroyImage | ✅ Implemented
vkDestroyImageView | ✅ Implemented
vkDestroyInstance | ✅ Implemented
vkDestroyPipeline | ❌ Not implemented
vkDestroyPipelineCache | ❌ Not implemented
vkDestroyPipelineLayout | ❌ Not implemented
vkDestroyQueryPool | ❌ Not implemented
vkDestroyRenderPass | ❌ Not implemented
vkDestroySampler | ❌ Not implemented
vkDestroySemaphore | ❌ Not implemented
vkDestroyShaderModule | ❌ Not implemented
vkDeviceWaitIdle | ❌ Not implemented
vkEndCommandBuffer | ✅ Implemented
vkEnumerateDeviceExtensionProperties | ⚙️ WIP
vkEnumerateDeviceLayerProperties | ⚙️ WIP
vkEnumerateInstanceExtensionProperties | ⚙️ WIP
vkEnumerateInstanceLayerProperties | ⚙️ WIP
vkEnumeratePhysicalDevices | ✅ Implemented
vkFlushMappedMemoryRanges | ❌ Not implemented
vkFreeCommandBuffers | ✅ Implemented
vkFreeDescriptorSets | ❌ Not implemented
vkFreeMemory | ✅ Implemented
vkGetBufferMemoryRequirements | ✅ Implemented
vkGetDeviceMemoryCommitment | ❌ Not implemented
vkGetDeviceProcAddr | ✅ Implemented
vkGetDeviceQueue | ✅ Implemented
vkGetEventStatus | ❌ Not implemented
vkGetFenceStatus | ✅ Implemented
vkGetImageMemoryRequirements | ✅ Implemented
vkGetImageSparseMemoryRequirements | ❌ Not implemented
vkGetImageSubresourceLayout | ❌ Not implemented
vkGetInstanceProcAddr | ✅ Implemented
vkGetPhysicalDeviceFeatures | ✅ Implemented
vkGetPhysicalDeviceFormatProperties | ⚙️ WIP
vkGetPhysicalDeviceImageFormatProperties | ⚙️ WIP
vkGetPhysicalDeviceMemoryProperties | ✅ Implemented
vkGetPhysicalDeviceProperties | ✅ Implemented
vkGetPhysicalDeviceQueueFamilyProperties | ✅ Implemented
vkGetPhysicalDeviceSparseImageFormatProperties | ⚙️ WIP
vkGetPipelineCacheData | ❌ Not implemented
vkGetQueryPoolResults | ❌ Not implemented
vkGetRenderAreaGranularity | ❌ Not implemented
vkInvalidateMappedMemoryRanges | ❌ Not implemented
vkMapMemory | ✅ Implemented
vkMergePipelineCaches | ❌ Not implemented
vkQueueBindSparse | ❌ Not implemented
vkQueueSubmit | ✅ Implemented
vkQueueWaitIdle | ✅ Implemented
vkResetCommandBuffer | ✅ Implemented
vkResetCommandPool | ❌ Not implemented
vkResetDescriptorPool | ❌ Not implemented
vkResetEvent | ❌ Not implemented
vkResetFences | ✅ Implemented
vkSetEvent | ❌ Not implemented
vkUnmapMemory | ✅ Implemented
vkUpdateDescriptorSets | ❌ Not implemented
vkWaitForFences | ✅ Implemented
</details>
## License ## License
Released unto the world as MIT for study, experimentation, and the occasional horrified whisper. Released unto the world as MIT for study, experimentation, and the occasional horrified whisper.

View File

@@ -39,7 +39,7 @@ fn clearColorImage(data: *const cmd.CommandClearColorImage) VkError!void {
_ = range; _ = range;
_ = &memory_map; _ = &memory_map;
std.log.scoped(.commandExecutor).warn("FIXME: implement image clear", .{}); base.logger.fixme("Implement image clear", .{});
memory.unmap(); memory.unmap();
} }

View File

@@ -48,5 +48,17 @@ comptime {
} }
test { test {
//std.testing.refAllDeclsRecursive(@This()); std.testing.refAllDecls(base);
std.testing.refAllDecls(SoftInstance);
std.testing.refAllDecls(SoftDevice);
std.testing.refAllDecls(SoftPhysicalDevice);
std.testing.refAllDecls(SoftQueue);
std.testing.refAllDecls(SoftBuffer);
std.testing.refAllDecls(SoftCommandBuffer);
std.testing.refAllDecls(SoftCommandPool);
std.testing.refAllDecls(SoftDeviceMemory);
std.testing.refAllDecls(SoftFence);
std.testing.refAllDecls(SoftImage);
std.testing.refAllDecls(SoftImageView);
std.testing.refAllDecls(Executor);
} }

View File

@@ -44,6 +44,10 @@ fn entryPointNotFoundErrorLog(comptime scope: @Type(.enum_literal), name: []cons
std.log.scoped(scope).err("Could not find function {s}", .{name}); std.log.scoped(scope).err("Could not find function {s}", .{name});
} }
inline fn notImplementedWarning() void {
logger.nestedFixme("function not yet implemented", .{});
}
fn functionMapEntryPoint(comptime name: []const u8) struct { []const u8, vk.PfnVoidFunction } { fn functionMapEntryPoint(comptime name: []const u8) struct { []const u8, vk.PfnVoidFunction } {
// Mapping 'vkFnName' to 'strollFnName' // Mapping 'vkFnName' to 'strollFnName'
const stroll_name = std.fmt.comptimePrint("stroll{s}", .{name[2..]}); const stroll_name = std.fmt.comptimePrint("stroll{s}", .{name[2..]});
@@ -64,9 +68,9 @@ const icd_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
const global_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{ const global_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkCreateInstance"), functionMapEntryPoint("vkCreateInstance"),
functionMapEntryPoint("vkGetInstanceProcAddr"),
functionMapEntryPoint("vkEnumerateInstanceExtensionProperties"), functionMapEntryPoint("vkEnumerateInstanceExtensionProperties"),
functionMapEntryPoint("vkEnumerateInstanceVersion"), functionMapEntryPoint("vkEnumerateInstanceVersion"),
functionMapEntryPoint("vkGetInstanceProcAddr"),
}); });
const instance_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{ const instance_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
@@ -78,27 +82,38 @@ const instance_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
const physical_device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{ const physical_device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkCreateDevice"), functionMapEntryPoint("vkCreateDevice"),
functionMapEntryPoint("vkEnumerateDeviceExtensionProperties"), functionMapEntryPoint("vkEnumerateDeviceExtensionProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceFormatProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceFeatures"), functionMapEntryPoint("vkGetPhysicalDeviceFeatures"),
functionMapEntryPoint("vkGetPhysicalDeviceFormatProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceImageFormatProperties"), functionMapEntryPoint("vkGetPhysicalDeviceImageFormatProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceMemoryProperties"), functionMapEntryPoint("vkGetPhysicalDeviceMemoryProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceQueueFamilyProperties"), functionMapEntryPoint("vkGetPhysicalDeviceQueueFamilyProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceSparseImageFormatProperties"), functionMapEntryPoint("vkGetPhysicalDeviceSparseImageFormatProperties"),
}); });
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{ const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkAllocateCommandBuffers"), functionMapEntryPoint("vkAllocateCommandBuffers"),
functionMapEntryPoint("vkAllocateDescriptorSets"),
functionMapEntryPoint("vkAllocateMemory"), functionMapEntryPoint("vkAllocateMemory"),
functionMapEntryPoint("vkBeginCommandBuffer"), functionMapEntryPoint("vkBeginCommandBuffer"),
functionMapEntryPoint("vkBindBufferMemory"), functionMapEntryPoint("vkBindBufferMemory"),
functionMapEntryPoint("vkBindImageMemory"), functionMapEntryPoint("vkBindImageMemory"),
functionMapEntryPoint("vkCmdBeginQuery"),
functionMapEntryPoint("vkCmdBeginRenderPass"),
functionMapEntryPoint("vkCmdBindDescriptorSets"),
functionMapEntryPoint("vkCmdBindIndexBuffer"),
functionMapEntryPoint("vkCmdBindPipeline"),
functionMapEntryPoint("vkCmdBindVertexBuffers"),
functionMapEntryPoint("vkCmdBlitImage"),
functionMapEntryPoint("vkCmdClearAttachments"),
functionMapEntryPoint("vkCmdClearColorImage"), functionMapEntryPoint("vkCmdClearColorImage"),
functionMapEntryPoint("vkCmdClearDepthStencilImage"),
functionMapEntryPoint("vkCmdCopyBuffer"), functionMapEntryPoint("vkCmdCopyBuffer"),
functionMapEntryPoint("vkCmdCopyBufferToImage"),
functionMapEntryPoint("vkCmdCopyImage"), functionMapEntryPoint("vkCmdCopyImage"),
functionMapEntryPoint("vkCmdFillBuffer"), functionMapEntryPoint("vkCmdFillBuffer"),
functionMapEntryPoint("vkCreateCommandPool"),
functionMapEntryPoint("vkCreateBuffer"), functionMapEntryPoint("vkCreateBuffer"),
functionMapEntryPoint("vkCreateCommandPool"),
functionMapEntryPoint("vkCreateFence"), functionMapEntryPoint("vkCreateFence"),
functionMapEntryPoint("vkCreateImage"), functionMapEntryPoint("vkCreateImage"),
functionMapEntryPoint("vkCreateImageView"), functionMapEntryPoint("vkCreateImageView"),
@@ -116,12 +131,12 @@ const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkGetFenceStatus"), functionMapEntryPoint("vkGetFenceStatus"),
functionMapEntryPoint("vkGetImageMemoryRequirements"), functionMapEntryPoint("vkGetImageMemoryRequirements"),
functionMapEntryPoint("vkMapMemory"), functionMapEntryPoint("vkMapMemory"),
functionMapEntryPoint("vkUnmapMemory"),
functionMapEntryPoint("vkResetCommandBuffer"),
functionMapEntryPoint("vkResetFences"),
functionMapEntryPoint("vkQueueBindSparse"), functionMapEntryPoint("vkQueueBindSparse"),
functionMapEntryPoint("vkQueueSubmit"), functionMapEntryPoint("vkQueueSubmit"),
functionMapEntryPoint("vkQueueWaitIdle"), functionMapEntryPoint("vkQueueWaitIdle"),
functionMapEntryPoint("vkResetCommandBuffer"),
functionMapEntryPoint("vkResetFences"),
functionMapEntryPoint("vkUnmapMemory"),
functionMapEntryPoint("vkWaitForFences"), functionMapEntryPoint("vkWaitForFences"),
}); });
@@ -187,11 +202,10 @@ pub export fn vkGetInstanceProcAddr(p_instance: vk.Instance, p_name: ?[*:0]const
return null; return null;
} }
pub export fn strollCreateInstance(p_info: ?*const vk.InstanceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_instance: *vk.Instance) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateInstance(info: *const vk.InstanceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_instance: *vk.Instance) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateInstance); entryPointBeginLogTrace(.vkCreateInstance);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .instance_create_info) { if (info.s_type != .instance_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -265,11 +279,10 @@ pub export fn strollEnumeratePhysicalDevices(p_instance: vk.Instance, count: *u3
// Physical Device functions ================================================================================================================================= // Physical Device functions =================================================================================================================================
pub export fn strollCreateDevice(p_physical_device: vk.PhysicalDevice, p_info: ?*const vk.DeviceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_device: *vk.Device) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateDevice(p_physical_device: vk.PhysicalDevice, info: *const vk.DeviceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_device: *vk.Device) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateDevice); entryPointBeginLogTrace(.vkCreateDevice);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .device_create_info) { if (info.s_type != .device_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -411,13 +424,12 @@ pub export fn strollQueueWaitIdle(p_queue: vk.Queue) callconv(vk.vulkan_call_con
// Device functions ========================================================================================================================================== // Device functions ==========================================================================================================================================
pub export fn strollAllocateCommandBuffers(p_device: vk.Device, p_info: ?*const vk.CommandBufferAllocateInfo, p_cmds: [*]vk.CommandBuffer) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollAllocateCommandBuffers(p_device: vk.Device, info: *const vk.CommandBufferAllocateInfo, p_cmds: [*]vk.CommandBuffer) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkAllocateCommandBuffers); entryPointBeginLogTrace(.vkAllocateCommandBuffers);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return toVkResult(err); Dispatchable(Device).checkHandleValidity(p_device) catch |err| return toVkResult(err);
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .command_buffer_allocate_info) { if (info.s_type != .command_buffer_allocate_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -430,11 +442,28 @@ pub export fn strollAllocateCommandBuffers(p_device: vk.Device, p_info: ?*const
return .success; return .success;
} }
pub export fn strollAllocateMemory(p_device: vk.Device, p_info: ?*const vk.MemoryAllocateInfo, callbacks: ?*const vk.AllocationCallbacks, p_memory: *vk.DeviceMemory) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollAllocateDescriptorSets(p_device: vk.Device, info: *const vk.DescriptorSetAllocateInfo, p_set: *vk.DescriptorSet) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkAllocateCommandBuffers);
defer entryPointEndLogTrace();
if (info.s_type != .descriptor_set_allocate_info) {
return .error_validation_failed;
}
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
notImplementedWarning();
_ = device;
_ = p_set;
return .success;
}
pub export fn strollAllocateMemory(p_device: vk.Device, info: *const vk.MemoryAllocateInfo, callbacks: ?*const vk.AllocationCallbacks, p_memory: *vk.DeviceMemory) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkAllocateMemory); entryPointBeginLogTrace(.vkAllocateMemory);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .memory_allocate_info) { if (info.s_type != .memory_allocate_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -479,11 +508,10 @@ pub export fn strollBindImageMemory(p_device: vk.Device, p_image: vk.Image, p_me
return .success; return .success;
} }
pub export fn strollCreateBuffer(p_device: vk.Device, p_info: ?*const vk.BufferCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_buffer: *vk.Buffer) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateBuffer(p_device: vk.Device, info: *const vk.BufferCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_buffer: *vk.Buffer) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateBuffer); entryPointBeginLogTrace(.vkCreateBuffer);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .buffer_create_info) { if (info.s_type != .buffer_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -494,11 +522,10 @@ pub export fn strollCreateBuffer(p_device: vk.Device, p_info: ?*const vk.BufferC
return .success; return .success;
} }
pub export fn strollCreateCommandPool(p_device: vk.Device, p_info: ?*const vk.CommandPoolCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_pool: *vk.CommandPool) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateCommandPool(p_device: vk.Device, info: *const vk.CommandPoolCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_pool: *vk.CommandPool) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateCommandPool); entryPointBeginLogTrace(.vkCreateCommandPool);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .command_pool_create_info) { if (info.s_type != .command_pool_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -510,11 +537,10 @@ pub export fn strollCreateCommandPool(p_device: vk.Device, p_info: ?*const vk.Co
return .success; return .success;
} }
pub export fn strollCreateFence(p_device: vk.Device, p_info: ?*const vk.FenceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_fence: *vk.Fence) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateFence(p_device: vk.Device, info: *const vk.FenceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_fence: *vk.Fence) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateFence); entryPointBeginLogTrace(.vkCreateFence);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .fence_create_info) { if (info.s_type != .fence_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -526,11 +552,10 @@ pub export fn strollCreateFence(p_device: vk.Device, p_info: ?*const vk.FenceCre
return .success; return .success;
} }
pub export fn strollCreateImage(p_device: vk.Device, p_info: ?*const vk.ImageCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_image: *vk.Image) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateImage(p_device: vk.Device, info: *const vk.ImageCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_image: *vk.Image) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateImage); entryPointBeginLogTrace(.vkCreateImage);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .image_create_info) { if (info.s_type != .image_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -541,11 +566,10 @@ pub export fn strollCreateImage(p_device: vk.Device, p_info: ?*const vk.ImageCre
return .success; return .success;
} }
pub export fn strollCreateImageView(p_device: vk.Device, p_info: ?*const vk.ImageViewCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_image_view: *vk.ImageView) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollCreateImageView(p_device: vk.Device, info: *const vk.ImageViewCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_image_view: *vk.ImageView) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkCreateImageView); entryPointBeginLogTrace(.vkCreateImageView);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .image_view_create_info) { if (info.s_type != .image_view_create_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -762,11 +786,10 @@ pub export fn strollWaitForFences(p_device: vk.Device, count: u32, p_fences: [*]
// Command Buffer functions =================================================================================================================================== // Command Buffer functions ===================================================================================================================================
pub export fn strollBeginCommandBuffer(p_cmd: vk.CommandBuffer, p_info: ?*const vk.CommandBufferBeginInfo) callconv(vk.vulkan_call_conv) vk.Result { pub export fn strollBeginCommandBuffer(p_cmd: vk.CommandBuffer, info: *const vk.CommandBufferBeginInfo) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkBeginCommandBuffer); entryPointBeginLogTrace(.vkBeginCommandBuffer);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .command_buffer_begin_info) { if (info.s_type != .command_buffer_begin_info) {
return .error_validation_failed; return .error_validation_failed;
} }
@@ -775,6 +798,149 @@ pub export fn strollBeginCommandBuffer(p_cmd: vk.CommandBuffer, p_info: ?*const
return .success; return .success;
} }
pub export fn strollCmdBeginQuery(p_cmd: vk.CommandBuffer, p_pool: vk.QueryPool, query: u32, flags: vk.QueryControlFlags) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBeginQuery);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = p_pool;
_ = query;
_ = flags;
}
pub export fn strollCmdBeginRenderPass(p_cmd: vk.CommandBuffer, info: *const vk.RenderPassBeginInfo, contents: vk.SubpassContents) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBeginRenderPass);
defer entryPointEndLogTrace();
if (info.s_type != .render_pass_begin_info) {
return errorLogger(VkError.ValidationFailed);
}
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = contents;
}
pub export fn strollCmdBindDescriptorSets(
p_cmd: vk.CommandBuffer,
bind_point: vk.PipelineBindPoint,
layout: vk.PipelineLayout,
first: u32,
count: u32,
sets: [*]const vk.DescriptorSet,
dynamic_offset_count: u32,
dynamic_offsets: [*]const u32,
) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBindDescriptorSets);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = bind_point;
_ = layout;
_ = first;
_ = count;
_ = sets;
_ = dynamic_offsets;
_ = dynamic_offset_count;
}
pub export fn strollCmdBindIndexBuffer(p_cmd: vk.CommandBuffer, p_buffer: vk.Buffer, offset: vk.DeviceSize, index_type: vk.IndexType) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBindIndexBuffer);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
const buffer = NonDispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = buffer;
_ = offset;
_ = index_type;
}
pub export fn strollCmdBindPipeline(p_cmd: vk.CommandBuffer, bind_point: vk.PipelineBindPoint, p_pipeline: vk.Pipeline) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBindPipeline);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = bind_point;
_ = p_pipeline;
}
pub export fn strollCmdBindVertexBuffers(p_cmd: vk.CommandBuffer, first: u32, count: u32, p_buffers: [*]const vk.Buffer, offsets: [*]const vk.DeviceSize) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBindVertexBuffer);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = first;
_ = count;
_ = p_buffers;
_ = offsets;
}
pub export fn strollCmdBlitImage(
p_cmd: vk.CommandBuffer,
p_src_image: vk.Image,
src_layout: vk.ImageLayout,
p_dst_image: vk.Image,
dst_layout: vk.ImageLayout,
count: u32,
regions: [*]const vk.ImageBlit,
filter: vk.Filter,
) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdBlitImage);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
const src = NonDispatchable(Image).fromHandleObject(p_src_image) catch |err| return errorLogger(err);
const dst = NonDispatchable(Image).fromHandleObject(p_dst_image) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = src;
_ = src_layout;
_ = dst;
_ = dst_layout;
_ = count;
_ = regions;
_ = filter;
}
pub export fn strollCmdClearAttachments(p_cmd: vk.CommandBuffer, attachment_count: u32, attachments: [*]const vk.ClearAttachment, rect_count: u32, rects: [*]const vk.ClearRect) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdClearAttachments);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = attachment_count;
_ = attachments;
_ = rect_count;
_ = rects;
}
pub export fn strollCmdClearColorImage(p_cmd: vk.CommandBuffer, p_image: vk.Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, count: u32, ranges: [*]const vk.ImageSubresourceRange) callconv(vk.vulkan_call_conv) void { pub export fn strollCmdClearColorImage(p_cmd: vk.CommandBuffer, p_image: vk.Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, count: u32, ranges: [*]const vk.ImageSubresourceRange) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdCopyImage); entryPointBeginLogTrace(.vkCmdCopyImage);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
@@ -784,6 +950,23 @@ pub export fn strollCmdClearColorImage(p_cmd: vk.CommandBuffer, p_image: vk.Imag
cmd.clearColorImage(image, layout, color, ranges[0..count]) catch |err| return errorLogger(err); cmd.clearColorImage(image, layout, color, ranges[0..count]) catch |err| return errorLogger(err);
} }
pub export fn strollCmdClearDepthStencilImage(p_cmd: vk.CommandBuffer, p_image: vk.Image, layout: vk.ImageLayout, stencil: *const vk.ClearDepthStencilValue, count: u32, ranges: [*]const vk.ImageSubresourceRange) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdClearDepthStencilImage);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
const image = NonDispatchable(Image).fromHandleObject(p_image) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = image;
_ = layout;
_ = stencil;
_ = count;
_ = ranges;
}
pub export fn strollCmdCopyBuffer(p_cmd: vk.CommandBuffer, p_src: vk.Buffer, p_dst: vk.Buffer, count: u32, regions: [*]const vk.BufferCopy) callconv(vk.vulkan_call_conv) void { pub export fn strollCmdCopyBuffer(p_cmd: vk.CommandBuffer, p_src: vk.Buffer, p_dst: vk.Buffer, count: u32, regions: [*]const vk.BufferCopy) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdCopyBuffer); entryPointBeginLogTrace(.vkCmdCopyBuffer);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();
@@ -794,6 +977,24 @@ pub export fn strollCmdCopyBuffer(p_cmd: vk.CommandBuffer, p_src: vk.Buffer, p_d
cmd.copyBuffer(src, dst, regions[0..count]) catch |err| return errorLogger(err); cmd.copyBuffer(src, dst, regions[0..count]) catch |err| return errorLogger(err);
} }
pub export fn strollCmdCopyBufferToImage(p_cmd: vk.CommandBuffer, p_src: vk.Buffer, p_dst: vk.Image, layout: vk.ImageLayout, count: u32, regions: [*]const vk.BufferImageCopy) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdCopyBufferToImage);
defer entryPointEndLogTrace();
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
const src = NonDispatchable(Buffer).fromHandleObject(p_src) catch |err| return errorLogger(err);
const dst = NonDispatchable(Image).fromHandleObject(p_dst) catch |err| return errorLogger(err);
notImplementedWarning();
_ = cmd;
_ = src;
_ = dst;
_ = layout;
_ = count;
_ = regions;
}
pub export fn strollCmdCopyImage(p_cmd: vk.CommandBuffer, p_src: vk.Image, p_dst: vk.Image, count: u32, regions: [*]const vk.ImageCopy) callconv(vk.vulkan_call_conv) void { pub export fn strollCmdCopyImage(p_cmd: vk.CommandBuffer, p_src: vk.Image, p_dst: vk.Image, count: u32, regions: [*]const vk.ImageCopy) callconv(vk.vulkan_call_conv) void {
entryPointBeginLogTrace(.vkCmdCopyImage); entryPointBeginLogTrace(.vkCmdCopyImage);
defer entryPointEndLogTrace(); defer entryPointEndLogTrace();

View File

@@ -21,6 +21,7 @@ const DebugStackElement = struct {
log_level: std.log.Level, log_level: std.log.Level,
}; };
var indent_enabled = true;
var indent_level: usize = 0; var indent_level: usize = 0;
var debug_stack = std.ArrayList(DebugStackElement).empty; var debug_stack = std.ArrayList(DebugStackElement).empty;
@@ -45,10 +46,28 @@ pub inline fn unindent() void {
} }
} }
pub inline fn enableIndent() void {
indent_enabled = true;
}
pub inline fn disableIndent() void {
indent_enabled = false;
}
pub inline fn freeInnerDebugStack() void { pub inline fn freeInnerDebugStack() void {
debug_stack.deinit(std.heap.c_allocator); debug_stack.deinit(std.heap.c_allocator);
} }
pub inline fn fixme(comptime format: []const u8, args: anytype) void {
disableIndent();
defer enableIndent();
nestedFixme(format, args);
}
pub inline fn nestedFixme(comptime format: []const u8, args: anytype) void {
std.log.scoped(.FIXME).warn("FIXME: " ++ format, args);
}
pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype) void { pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype) void {
if (lib.getLogVerboseLevel() == .None) { if (lib.getLogVerboseLevel() == .None) {
return; return;
@@ -113,8 +132,10 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
out_config.setColor(&writer, .reset) catch {}; out_config.setColor(&writer, .reset) catch {};
for (0..indent_level) |_| { if (indent_enabled) {
writer.print("> ", .{}) catch {}; for (0..indent_level) |_| {
writer.print("> ", .{}) catch {};
}
} }
writer.print(format ++ "\n", args) catch {}; writer.print(format ++ "\n", args) catch {};
writer.flush() catch return; writer.flush() catch return;
@@ -125,7 +146,10 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
.indent_level = indent_level, .indent_level = indent_level,
.log_level = level, .log_level = level,
}; };
} else { return;
}
if (indent_enabled) {
while (debug_stack.items.len != 0) { while (debug_stack.items.len != 0) {
const elem = debug_stack.orderedRemove(0); const elem = debug_stack.orderedRemove(0);
switch (elem.log_level) { switch (elem.log_level) {
@@ -133,9 +157,9 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
.warn, .err => _ = stderr_file.write(&elem.log) catch {}, .warn, .err => _ = stderr_file.write(&elem.log) catch {},
} }
} }
switch (level) { }
.info, .debug => _ = stdout_file.write(&buffer) catch {}, switch (level) {
.warn, .err => _ = stderr_file.write(&buffer) catch {}, .info, .debug => _ = stdout_file.write(&buffer) catch {},
} .warn, .err => _ = stderr_file.write(&buffer) catch {},
} }
} }

View File

@@ -23,7 +23,7 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h> #include <stb_image_write.h>
void CreateAndBindMemoryToBuffer(VkPhysicalDevice physical_device, VkDevice device, VkBuffer buffer, VkDeviceMemory* memory, VkMemoryPropertyFlags props) VkDeviceMemory CreateAndBindMemoryToBuffer(VkPhysicalDevice physical_device, VkDevice device, VkBuffer buffer, VkMemoryPropertyFlags props)
{ {
VkMemoryRequirements requirements; VkMemoryRequirements requirements;
vkGetBufferMemoryRequirements(device, buffer, &requirements); vkGetBufferMemoryRequirements(device, buffer, &requirements);
@@ -32,11 +32,14 @@ void CreateAndBindMemoryToBuffer(VkPhysicalDevice physical_device, VkDevice devi
alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
alloc_info.allocationSize = requirements.size; alloc_info.allocationSize = requirements.size;
alloc_info.memoryTypeIndex = kvfFindMemoryType(physical_device, requirements.memoryTypeBits, props); alloc_info.memoryTypeIndex = kvfFindMemoryType(physical_device, requirements.memoryTypeBits, props);
kvfCheckVk(vkAllocateMemory(device, &alloc_info, NULL, memory));
kvfCheckVk(vkBindBufferMemory(device, buffer, *memory, 0)); VkDeviceMemory memory;
kvfCheckVk(vkAllocateMemory(device, &alloc_info, NULL, &memory));
kvfCheckVk(vkBindBufferMemory(device, buffer, memory, 0));
return memory;
} }
void CreateAndBindMemoryToImage(VkPhysicalDevice physical_device, VkDevice device, VkImage image, VkDeviceMemory* memory, VkMemoryPropertyFlags props) VkDeviceMemory CreateAndBindMemoryToImage(VkPhysicalDevice physical_device, VkDevice device, VkImage image, VkMemoryPropertyFlags props)
{ {
VkMemoryRequirements requirements; VkMemoryRequirements requirements;
vkGetImageMemoryRequirements(device, image, &requirements); vkGetImageMemoryRequirements(device, image, &requirements);
@@ -45,8 +48,11 @@ void CreateAndBindMemoryToImage(VkPhysicalDevice physical_device, VkDevice devic
alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
alloc_info.allocationSize = requirements.size; alloc_info.allocationSize = requirements.size;
alloc_info.memoryTypeIndex = kvfFindMemoryType(physical_device, requirements.memoryTypeBits, props); alloc_info.memoryTypeIndex = kvfFindMemoryType(physical_device, requirements.memoryTypeBits, props);
kvfCheckVk(vkAllocateMemory(device, &alloc_info, NULL, memory));
kvfCheckVk(vkBindImageMemory(device, image, *memory, 0)); VkDeviceMemory memory;
kvfCheckVk(vkAllocateMemory(device, &alloc_info, NULL, &memory));
kvfCheckVk(vkBindImageMemory(device, image, memory, 0));
return memory;
} }
int main(void) int main(void)
@@ -82,8 +88,7 @@ int main(void)
volkLoadDevice(device); volkLoadDevice(device);
VkImage image = kvfCreateImage(device, 256, 256, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, KVF_IMAGE_COLOR); VkImage image = kvfCreateImage(device, 256, 256, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, KVF_IMAGE_COLOR);
VkDeviceMemory memory; VkDeviceMemory memory = CreateAndBindMemoryToImage(physical_device, device, image, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
CreateAndBindMemoryToImage(physical_device, device, image, &memory, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
VkImageView image_view = kvfCreateImageView(device, image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, 1); VkImageView image_view = kvfCreateImageView(device, image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, 1);