update gryphn to use GN_FALSE + GN_TRUE

This commit is contained in:
Gregory Wells
2025-07-28 20:05:44 -04:00
parent d649e5b3bb
commit 07a2cf85ad
24 changed files with 62 additions and 78 deletions

View File

@@ -1,7 +1,7 @@
#include "metal_loader.h"
gnBool metalIsExtensionSupported(gnExtension extension) {
if (extension == GN_EXT_SYNCHRONIZATION) return gnTrue;
if (extension == GN_EXT_QUEUES) return gnFalse;
return gnFalse;
if (extension == GN_EXT_SYNCHRONIZATION) return GN_TRUE;
if (extension == GN_EXT_QUEUES) return GN_FALSE;
return GN_FALSE;
}

View File

@@ -10,7 +10,7 @@ gnReturnCode allocateMetalCommandBuffers(gnCommandBufferHandle* commandBuffers,
// write a command log at some point
if ((pool->info.flags & GN_REUSE_COMMAND_BUFFERS) == GN_REUSE_COMMAND_BUFFERS)
commandBuffers[i]->commandBuffer->isIndirectCommandBuffer = gnTrue;
commandBuffers[i]->commandBuffer->isIndirectCommandBuffer = GN_TRUE;
}
return GN_SUCCESS;

View File

@@ -117,7 +117,7 @@ void metalBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t
if (uniform->uniform->isDynamic[c]) {
gnBufferUniformInfo updateInfo = {
.binding = c,
.dynamic = gnTrue,
.dynamic = GN_TRUE,
.offset = dynamicOffsets[i],
.size = 0
};

View File

@@ -23,14 +23,6 @@ gnPhysicalDevice* getMetalDevices(gnInstanceHandle instance, uint32_t* deviceCou
else if (deviceLocation == MTLDeviceLocationExternal)
devicesList[i]->properties.deviceType = GN_EXTERNAL_DEVICE;
// below I am going to fake that there is one queue that can support graphics, compute, and transfer queues
// devicesList[i]->queueProperties.queueCount = 1;
// devicesList[i]->queueProperties.queueProperties = malloc(sizeof(gnQueueProperties));
// devicesList[i]->queueProperties.queueProperties[0] = (gnQueueProperties){
// .queueCount = 1,
// .queueType = GN_QUEUE_GRAPHICS | GN_QUEUE_COMPUTE | GN_QUEUE_TRANSFER
// };
devicesList[i]->features.maxColorSamples = GN_SAMPLE_BIT_1;
if ([device supportsTextureSampleCount:2]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_2; } else {}
if ([device supportsTextureSampleCount:4]) { devicesList[i]->features.maxColorSamples |= GN_SAMPLE_BIT_4; } else {}
@@ -47,5 +39,5 @@ gnPhysicalDevice* getMetalDevices(gnInstanceHandle instance, uint32_t* deviceCou
}
gnBool metalCanDevicePresent(gnPhysicalDevice device, gnWindowSurface windowSurface) {
return gnTrue; // I belive that a window should always be able to present to a surface in metal
return GN_TRUE; // I belive that a window should always be able to present to a surface in metal
}

View File

@@ -10,7 +10,7 @@ gnReturnCode createMetalFramebuffer(gnFramebuffer framebuffer, gnOutputDevice de
framebuffer->framebuffer->clearCopyCount = info.attachmentCount;
framebuffer->framebuffer->clearCopies = malloc(sizeof(mtlClearCopy) * info.attachmentCount);
for (int i = 0; i < info.attachmentCount; i++) {
framebuffer->framebuffer->clearCopies[i].clear = gnFalse;
framebuffer->framebuffer->clearCopies[i].clear = GN_FALSE;
}
framebuffer->framebuffer->subpassCount = info.renderPassDescriptor->renderPassDescriptor->subpassCount;
@@ -27,7 +27,7 @@ gnReturnCode createMetalFramebuffer(gnFramebuffer framebuffer, gnOutputDevice de
colorPass.texture = info.attachments[info.renderPassDescriptor->renderPassDescriptor->copyInfos[i].colorAttachments[c].attachmentIndex]->texture->texture;
if (info.renderPassDescriptor->renderPassDescriptor->copyInfos[i].colorAttachments[c].resolveAttachmentIndex >= 0)
colorPass.resolveTexture = info.attachments[info.renderPassDescriptor->renderPassDescriptor->copyInfos[i].colorAttachments[c].resolveAttachmentIndex]->texture->texture;
framebuffer->framebuffer->clearCopies[info.renderPassDescriptor->renderPassDescriptor->copyInfos[i].colorAttachments[c].attachmentIndex].clear = gnTrue;
framebuffer->framebuffer->clearCopies[info.renderPassDescriptor->renderPassDescriptor->copyInfos[i].colorAttachments[c].attachmentIndex].clear = GN_TRUE;
framebuffer->framebuffer->clearCopies[info.renderPassDescriptor->renderPassDescriptor->copyInfos[i].colorAttachments[c].attachmentIndex].descriptor = colorPass;
}

View File

@@ -53,7 +53,7 @@ gnReturnCode createMetalGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gn
MTLRenderPassColorAttachmentDescriptor* colorPass = subpass.colorAttachments[i];
descriptor.colorAttachments[i].pixelFormat = copyInfo.colorAttachments[i].format;
if (info.colorBlending.enable == gnTrue) {
if (info.colorBlending.enable == GN_TRUE) {
[descriptor.colorAttachments objectAtIndexedSubscript:i].blendingEnabled = YES;
[descriptor.colorAttachments objectAtIndexedSubscript:i].rgbBlendOperation = mtlGryphnBlendOperation(info.colorBlending.colorBlendOperation);
[descriptor.colorAttachments objectAtIndexedSubscript:i].alphaBlendOperation = mtlGryphnBlendOperation(info.colorBlending.alphaBlendOperation);

View File

@@ -22,7 +22,7 @@ gnReturnCode metalSyncSubmit(gnOutputDevice device, gnSubmitSyncInfo info) {
NSLog(@"Command buffer error: %s", buffer.error.localizedDescription.UTF8String);
}
if (atomic_fetch_sub_explicit(&buffersLeft, 1, memory_order_acq_rel) == 1) {
fenceToSignal->signaled = gnTrue;
fenceToSignal->signaled = GN_TRUE;
}
}];

View File

@@ -15,7 +15,7 @@ void singalMetalFence(gnFence fence) {
}
void waitForMetalFence(gnFence fence, uint64_t timeout) {
// dispatch_semaphore_wait(fence->fence->semaphore, timeout);
while (fence->signaled == gnFalse) {}
while (fence->signaled == GN_FALSE) {}
}
void resetMetalFence(gnFence fence) {
// dispatch_semaphore_signal(fence->fence->semaphore);

View File

@@ -1,7 +1,7 @@
#include "vulkan_loader.h"
gnBool vulkanIsExtensionSupported(gnExtension extension){
if (extension == GN_EXT_SYNCHRONIZATION) return gnTrue;
if (extension == GN_EXT_QUEUES) return gnTrue;
return gnFalse;
if (extension == GN_EXT_SYNCHRONIZATION) return GN_TRUE;
if (extension == GN_EXT_QUEUES) return GN_TRUE;
return GN_FALSE;
}

View File

@@ -20,7 +20,7 @@ uint32_t VkMemoryIndex(VkPhysicalDevice device, uint32_t memoryType, VkMemoryPro
vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties);
for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) {
if ((memoryType & (1 << i)) && (memoryProperties.memoryTypes[i].propertyFlags & flags) == flags) {
*foundMemory = gnTrue;
*foundMemory = GN_TRUE;
return i;
}
} // this whole thing was adapted from vulkan-tutorial.com
@@ -43,7 +43,7 @@ gnReturnCode VkCreateBuffer(
VkMemoryRequirements bufferRequirements;
vkGetBufferMemoryRequirements(device->outputDevice->device, buffer->buffer, &bufferRequirements);
gnBool foundMemory = gnFalse;
gnBool foundMemory = GN_FALSE;
VkMemoryAllocateInfo memoryAllocateInfo = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = bufferRequirements.size,

View File

@@ -56,7 +56,7 @@ void bindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBuf
if (type == GN_VERTEX_BUFFER)
vkCmdBindVertexBuffers(buffer->commandBuffer->buffer, 0, 1, &bufferToBind->buffer->buffer.buffer, offsets);
else if (type == GN_INDEX_BUFFER) {
buffer->commandBuffer->changedBuffer = gnTrue;
buffer->commandBuffer->changedBuffer = GN_TRUE;
buffer->commandBuffer->boundIndexBuffer = bufferToBind;
}
}
@@ -66,7 +66,7 @@ void draw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instance
void drawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance) {
if (buffer->commandBuffer->changedBuffer) vkCmdBindIndexBuffer(buffer->commandBuffer->buffer, buffer->commandBuffer->boundIndexBuffer->buffer->buffer.buffer, 0, (type == GN_UINT32) ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16);
vkCmdDrawIndexed(buffer->commandBuffer->buffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
buffer->commandBuffer->changedBuffer = gnFalse;
buffer->commandBuffer->changedBuffer = GN_FALSE;
}
void bindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets) {

View File

@@ -36,7 +36,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
vkUserData* userData = (vkUserData*)pUserData;
gnDebuggerCallback callback = userData->debuggerCallback;
gnBool result = callback(severity, type, data, userData->userData);
if (result == gnFalse) return VK_FALSE;
if (result == GN_FALSE) return VK_FALSE;
return VK_TRUE;
}
@@ -110,12 +110,12 @@ gnReturnCode createInstance(gnInstanceHandle instance, gnInstanceInfo instanceIn
VkResult result = vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance);
if (result != VK_SUCCESS)
return GN_FAILED_CREATE_INSTANCE;
instance->valid = gnTrue;
instance->valid = GN_TRUE;
return GN_SUCCESS;
}
void destroyInstance(gnInstanceHandle instance) {
instance->valid = gnFalse;
instance->valid = GN_FALSE;
vkDestroyInstance(instance->instance->vk_instance, NULL);
}

View File

@@ -20,10 +20,10 @@ const char* *vkGetGryphnDeviceExtensions(uint32_t* outCount, VkPhysicalDevice de
VkExtensionProperties* vkExtensions = malloc(sizeof(VkExtensionProperties) * extensionCount);
vkEnumerateDeviceExtensionProperties(device, NULL, &extensionCount, vkExtensions);
gnBool supportsDescriptorPoolOverallocation = gnFalse;
gnBool supportsDescriptorPoolOverallocation = GN_FALSE;
for (uint32_t i = 0; i < extensionCount; i++) {
if (strcmp(VK_NV_DESCRIPTOR_POOL_OVERALLOCATION_EXTENSION_NAME, vkExtensions[i].extensionName) == 0) {
supportsDescriptorPoolOverallocation = gnTrue;
supportsDescriptorPoolOverallocation = GN_TRUE;
break;
}
}

View File

@@ -46,9 +46,9 @@ gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHan
};
deviceCreateInfo.ppEnabledExtensionNames = vkGetGryphnDeviceExtensions(&deviceCreateInfo.enabledExtensionCount, deviceInfo.physicalDevice->physicalDevice->device);
outputDevice->outputDevice->enabledOversizedDescriptorPools = gnFalse;
outputDevice->outputDevice->enabledOversizedDescriptorPools = GN_FALSE;
for (int i = 0; i < deviceCreateInfo.enabledExtensionCount; i++)
if (strcmp(deviceCreateInfo.ppEnabledExtensionNames[i], VK_NV_DESCRIPTOR_POOL_OVERALLOCATION_EXTENSION_NAME) == 0) outputDevice->outputDevice->enabledOversizedDescriptorPools = gnTrue;
if (strcmp(deviceCreateInfo.ppEnabledExtensionNames[i], VK_NV_DESCRIPTOR_POOL_OVERALLOCATION_EXTENSION_NAME) == 0) outputDevice->outputDevice->enabledOversizedDescriptorPools = GN_TRUE;
if (instance->hasDebugger)
deviceCreateInfo.enabledLayerCount = 0;

View File

@@ -38,24 +38,24 @@ void vulkanLoadNeededQueues(VkPhysicalDevice vulkanDevice, gnPhysicalDevice gryp
vkGetPhysicalDeviceQueueFamilyProperties(vulkanDevice, &queueFamilyCount, queueFamilies);
gryphnDevice->physicalDevice->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount);
gnBool foundGraphicsQueueFamily = gnFalse, foundTransferQueueFamily = gnFalse;
gnBool foundGraphicsQueueFamily = GN_FALSE, foundTransferQueueFamily = GN_FALSE;
for (int c = 0; c < queueFamilyCount; c++) {
gnBool hasNeededQueue = gnFalse;
gnBool hasNeededQueue = GN_FALSE;
if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) {
foundGraphicsQueueFamily = true;
hasNeededQueue = gnTrue;
foundGraphicsQueueFamily = GN_TRUE;
hasNeededQueue = GN_TRUE;
}
if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) {
foundTransferQueueFamily = true;
hasNeededQueue = gnTrue;
foundTransferQueueFamily = GN_TRUE;
hasNeededQueue = GN_TRUE;
}
if (hasNeededQueue) {
vulkanNeededQueue neededQueue = {
.queueIndex = c,
.createFlags = 0,
.usedForPresent = gnFalse
.usedForPresent = GN_FALSE
};
if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT)) neededQueue.createFlags |= VK_QUEUE_GRAPHICS_BIT;
if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT)) neededQueue.createFlags |= VK_QUEUE_TRANSFER_BIT;
@@ -94,7 +94,7 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device
case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: outputDevices[i]->properties.deviceType = GN_INTEGRATED_DEVICE;
}
if (instance->enabledExtensions[GN_EXT_QUEUES] == gnFalse)
if (instance->enabledExtensions[GN_EXT_QUEUES] == GN_FALSE)
vulkanLoadNeededQueues(physicalDevices[i], outputDevices[i]);
@@ -111,13 +111,13 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device
}
gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface) {
gnBool foundQueue = gnFalse;
gnBool foundQueue = GN_FALSE;
for (int i = 0; i < device->physicalDevice->neededQueueCount; i++) {
VkBool32 supportsPresent = VK_FALSE;
vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, device->physicalDevice->neededQueues[i].queueIndex, surface->windowSurface->surface, &supportsPresent);
if (supportsPresent) {
device->physicalDevice->neededQueues[i].usedForPresent = gnTrue;
foundQueue = gnTrue;
device->physicalDevice->neededQueues[i].usedForPresent = GN_TRUE;
foundQueue = GN_TRUE;
break;
}
surface->windowSurface->presentQueueIndex = i;
@@ -134,9 +134,9 @@ gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surfac
device->physicalDevice->neededQueues[device->physicalDevice->neededQueueCount] = (vulkanNeededQueue){
.queueIndex = i,
.createFlags = 0,
.usedForPresent = gnTrue
.usedForPresent = GN_TRUE
};
foundQueue = gnTrue;
foundQueue = GN_TRUE;
surface->windowSurface->presentQueueIndex = device->physicalDevice->neededQueueCount;
device->physicalDevice->neededQueueCount++;
break;
@@ -146,11 +146,3 @@ gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surfac
return foundQueue;
}
// gnBool queueCanPresentToSurface(gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
// VkBool32 supportsPresent = VK_FALSE;
// vkGetPhysicalDeviceSurfaceSupportKHR(device->physicalDevice->device, queueIndex, windowSurface->windowSurface->surface, &supportsPresent);
// if (supportsPresent)
// return gnTrue;
// return gnFalse;
// }

View File

@@ -91,11 +91,11 @@ VkStencilOp vkGryphnStencilOperation(gnStencilOperation operation) {
gnReturnCode createGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) {
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = gnFalse;
for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = GN_FALSE;
graphicsPipeline->graphicsPipeline->dynamicStates = malloc(sizeof(VkDynamicState) * info.dynamicState.dynamicStateCount);
for (int i = 0; i < info.dynamicState.dynamicStateCount; i++) {
graphicsPipeline->graphicsPipeline->isDynamic[info.dynamicState.dynamicStates[i]] = gnTrue;
graphicsPipeline->graphicsPipeline->isDynamic[info.dynamicState.dynamicStates[i]] = GN_TRUE;
graphicsPipeline->graphicsPipeline->dynamicStates[i] = vkGryphnDynamicStateToVulkanDynamicState(info.dynamicState.dynamicStates[i]);
}
@@ -184,7 +184,7 @@ gnReturnCode createGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnDevic
graphicsPipeline->graphicsPipeline->colorBlendAttachment = (VkPipelineColorBlendAttachmentState){
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
.blendEnable = ( info.colorBlending.enable == gnTrue ) ? VK_TRUE : VK_FALSE,
.blendEnable = ( info.colorBlending.enable == GN_TRUE ) ? VK_TRUE : VK_FALSE,
.srcColorBlendFactor = vkGryphnBlendFactor(info.colorBlending.sourceColorBlendFactor),
.dstColorBlendFactor = vkGryphnBlendFactor(info.colorBlending.destinationColorBlendFactor),
.colorBlendOp = vkGryphnBlendOperation(info.colorBlending.colorBlendOperation),

View File

@@ -178,7 +178,7 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn
VkMemoryRequirements memRequirements;
vkGetImageMemoryRequirements(device->outputDevice->device, texture->texture->image.image, &memRequirements);
gnBool foundMemory = gnFalse;
gnBool foundMemory = GN_FALSE;
VkMemoryAllocateInfo allocInfo = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = memRequirements.size,
@@ -191,7 +191,7 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn
vkBindImageMemory(device->outputDevice->device, texture->texture->image.image, texture->texture->image.memory, 0);
texture->texture->beenWrittenToo = gnFalse;
texture->texture->beenWrittenToo = GN_FALSE;
VkImageViewCreateInfo viewInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -255,7 +255,7 @@ void textureData(gnTextureHandle texture, void* pixelData) {
VkCopyBufferToImage(texture->texture->buffer, texture->texture->image, texture->info.extent, texture->device);
VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
texture->texture->beenWrittenToo = gnTrue;
texture->texture->beenWrittenToo = GN_TRUE;
}
void gnDestroyVulkanImage(VkGryphnImage* image, VkDevice device) {

View File

@@ -12,7 +12,7 @@ gnReturnCode createUniformPool(gnUniformPool pool, gnDeviceHandle device) {
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
pool->uniformPool->pools = VkGryphnUniformPoolArrayListCreate();
if (device->outputDevice->enabledOversizedDescriptorPools == gnTrue) {
if (device->outputDevice->enabledOversizedDescriptorPools == GN_TRUE) {
{
VkGryphnUniformPool firstPool = {
.pool = VK_NULL_HANDLE,