finish query functions in Vulkan

This commit is contained in:
Gregory Wells
2025-09-19 10:12:10 -04:00
parent 3066f7c2bd
commit 228d75e5ac
3 changed files with 138 additions and 45 deletions

View File

@@ -11,6 +11,8 @@ gryphnInstanceFunctionLayers loadVulkanAPILayer(void) {
.destroyInstance = vulkanDestroyInstance, .destroyInstance = vulkanDestroyInstance,
.queryDevices = vulkanQueryDevices, .queryDevices = vulkanQueryDevices,
.getPhysicalDeviceProperties = vulkanQueryPhysicalDeviceProperties, .getPhysicalDeviceProperties = vulkanQueryPhysicalDeviceProperties,
.getPhysicalDeviceFeatures = vulkanQueryPhysicalDeviceFeatures,
.getPhysicalDeviceLimits = vulkanQueryPhysicalDeviceLimits,
.next = NULL .next = NULL
}; };
} }

View File

@@ -25,8 +25,99 @@ gnPhysicalDeviceProperties vulkanQueryPhysicalDeviceProperties(gnInstance instan
}; };
} }
gnMultisampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts) { gnPhysicalDeviceFeatures vulkanQueryPhysicalDeviceFeatures(gnInstance instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* layers) {
gnMultisampleCountFlags sampleCount = 0; VkPhysicalDeviceFeatures features;
vkGetPhysicalDeviceFeatures((VkPhysicalDevice)device, &features);
return (gnPhysicalDeviceFeatures){
.uint32Index = features.fullDrawIndexUint32,
.geometryShader = features.geometryShader,
.tessellationShader = features.tessellationShader,
.multiDrawIndirect = features.multiDrawIndirect,
.drawIndirectFirstInstance = features.drawIndirectFirstInstance,
.fillModeNonSolid = features.fillModeNonSolid,
.wideLines = features.wideLines,
.largePoints = features.largePoints,
.samplerAnisotropy = features.samplerAnisotropy
};
}
gnPhysicalDeviceLimits vulkanQueryPhysicalDeviceLimits(gnInstance instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* layers) {
VkPhysicalDeviceProperties properties;
vkGetPhysicalDeviceProperties((VkPhysicalDevice)device, &properties);
VkPhysicalDeviceLimits limits = properties.limits;
return (gnPhysicalDeviceLimits) {
.maxImageExtent1D = limits.maxImageDimension1D,
.maxImageExtent2D = limits.maxImageDimension2D,
.maxImageExtent3D = limits.maxImageDimension3D,
.maxImageExtentCube = limits.maxImageDimensionCube,
.maxImageArrayLayers = limits.maxImageArrayLayers,
.maxTexelBufferElements = limits.maxTexelBufferElements,
.maxUniformBufferRange = limits.maxUniformBufferRange,
.maxStorageBufferRange = limits.maxStorageBufferRange,
.maxPushConstantsSize = limits.maxPushConstantsSize,
.maxMemoryAllocationCount = limits.maxMemoryAllocationCount,
.maxSamplerAllocationCount = limits.maxSamplerAllocationCount,
.maxBoundUniforms = limits.maxBoundDescriptorSets,
.maxPerStageUniformSamplers = limits.maxPerStageDescriptorSamplers,
.maxPerStageUniformUniformBuffers = limits.maxPerStageDescriptorUniformBuffers,
.maxPerStageUniformStorageBuffers = limits.maxPerStageDescriptorStorageBuffers,
.maxPerStageUniformSampledImages = limits.maxPerStageDescriptorSampledImages,
.maxPerStageUniformStorageImages = limits.maxPerStageDescriptorStorageBuffers,
.maxPerStageUniformInputAttachments = limits.maxPerStageDescriptorInputAttachments,
.maxPerStageResources = limits.maxPerStageResources,
.maxUniformSamplers = limits.maxPerStageDescriptorSamplers,
.maxUniformUniformBuffers = limits.maxDescriptorSetUniformBuffers,
.maxUniformUniformBuffersDynamic = limits.maxDescriptorSetUniformBuffersDynamic,
.maxUniformStorageBuffers = limits.maxDescriptorSetStorageBuffers,
.maxUniformStorageBuffersDynamic = limits.maxDescriptorSetStorageBuffersDynamic,
.maxUniformSampledImages = limits.maxDescriptorSetSampledImages,
.maxUniformStorageImages = limits.maxPerStageDescriptorStorageImages,
.maxUniformInputAttachments = limits.maxDescriptorSetInputAttachments,
.maxVertexInputAttributes = limits.maxVertexInputAttributes,
.maxVertexInputBindings = limits.maxVertexInputBindings,
.maxVertexInputAttributeOffset = limits.maxVertexInputAttributeOffset,
.maxVertexInputBindingStride = limits.maxVertexInputBindingStride,
.maxVertexOutputComponents = limits.maxVertexOutputComponents,
.maxTessellationGenerationLevel = limits.maxTessellationGenerationLevel,
.maxTessellationPatchSize = limits.maxTessellationPatchSize,
.maxTessellationControlPerVertexInputComponents = limits.maxTessellationControlPerVertexInputComponents,
.maxTessellationControlPerVertexOutputComponents = limits.maxTessellationControlPerVertexOutputComponents,
.maxTessellationControlPerPatchOutputComponents = limits.maxTessellationControlPerPatchOutputComponents,
.maxTessellationControlTotalOutputComponents = limits.maxTessellationControlTotalOutputComponents,
.maxTessellationEvaluationInputComponents = limits.maxTessellationEvaluationInputComponents,
.maxTessellationEvaluationOutputComponents = limits.maxTessellationControlPerVertexOutputComponents,
.maxGeometryShaderInvocations = limits.maxGeometryShaderInvocations,
.maxGeometryInputComponents = limits.maxGeometryInputComponents,
.maxGeometryOutputComponents = limits.maxGeometryOutputComponents,
.maxGeometryOutputVertices = limits.maxGeometryOutputVertices,
.maxGeometryTotalOutputComponents = limits.maxGeometryTotalOutputComponents,
.maxFragmentInputComponents = limits.maxFragmentInputComponents,
.maxFragmentOutputAttachments = limits.maxFragmentOutputAttachments,
.maxFragmentDualSrcAttachments = limits.maxFragmentDualSrcAttachments,
.maxFragmentCombinedOutputResources = limits.maxFragmentCombinedOutputResources,
.maxDrawIndexedIndexValue = limits.maxDrawIndexedIndexValue,
.maxDrawIndirectCount = limits.maxDrawIndirectCount,
.maxSamplerLodBias = limits.maxSamplerLodBias,
.maxSamplerAnisotropy = limits.maxSamplerAnisotropy,
.maxViewports = limits.maxViewports,
.maxViewportExtents = { limits.maxViewportDimensions[0], limits.maxViewportDimensions[1] },
.viewportBoundsRange = { limits.viewportBoundsRange[0], limits.viewportBoundsRange[1] },
.maxFramebufferExtent = {limits.maxFramebufferWidth, limits.maxFramebufferHeight},
.maxFramebufferLayers = limits.maxFramebufferLayers,
.framebufferColorSampleCounts = vkSampleCountToGryphn(limits.framebufferColorSampleCounts),
.framebufferDepthSampleCounts = vkSampleCountToGryphn(limits.framebufferDepthSampleCounts),
.framebufferStencilSampleCounts = vkSampleCountToGryphn(limits.framebufferStencilSampleCounts),
.framebufferNoAttachmentsSampleCounts = vkSampleCountToGryphn(limits.framebufferNoAttachmentsSampleCounts),
.maxColorAttachments = limits.maxColorAttachments,
.pointSizeRange = { limits.pointSizeRange[0], limits.pointSizeRange[1] },
.lineWidthRange = { limits.lineWidthRange[0], limits.lineWidthRange[1] },
.pointSizeGranularity = limits.pointSizeGranularity,
.lineWidthGranularity = limits.lineWidthGranularity,
.strictLines = limits.strictLines
};
}
gnSampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts) {
gnSampleCountFlags sampleCount = 0;
if ((counts & VK_SAMPLE_COUNT_64_BIT) == VK_SAMPLE_COUNT_64_BIT) { sampleCount |= GN_SAMPLE_BIT_64; } if ((counts & VK_SAMPLE_COUNT_64_BIT) == VK_SAMPLE_COUNT_64_BIT) { sampleCount |= GN_SAMPLE_BIT_64; }
if ((counts & VK_SAMPLE_COUNT_32_BIT) == VK_SAMPLE_COUNT_32_BIT) { sampleCount |= GN_SAMPLE_BIT_32; } if ((counts & VK_SAMPLE_COUNT_32_BIT) == VK_SAMPLE_COUNT_32_BIT) { sampleCount |= GN_SAMPLE_BIT_32; }
if ((counts & VK_SAMPLE_COUNT_16_BIT) == VK_SAMPLE_COUNT_16_BIT) { sampleCount |= GN_SAMPLE_BIT_16; } if ((counts & VK_SAMPLE_COUNT_16_BIT) == VK_SAMPLE_COUNT_16_BIT) { sampleCount |= GN_SAMPLE_BIT_16; }
@@ -37,9 +128,7 @@ gnMultisampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts) {
return sampleCount; return sampleCount;
} }
#include <stdio.h> VkSampleCountFlags gnSampleCountToVulkan(gnSampleCountFlags counts) {
VkSampleCountFlags gnSampleCountToVulkan(gnMultisampleCountFlags counts) {
VkSampleCountFlags sampleCount = 0; VkSampleCountFlags sampleCount = 0;
if ((counts & GN_SAMPLE_BIT_64) == GN_SAMPLE_BIT_64) { sampleCount |= VK_SAMPLE_COUNT_64_BIT; } if ((counts & GN_SAMPLE_BIT_64) == GN_SAMPLE_BIT_64) { sampleCount |= VK_SAMPLE_COUNT_64_BIT; }
@@ -53,50 +142,50 @@ VkSampleCountFlags gnSampleCountToVulkan(gnMultisampleCountFlags counts) {
return sampleCount; return sampleCount;
} }
void vulkanLoadNeededQueues(gnPhysicalDevice physicalDevice) { // void vulkanLoadNeededQueues(gnPhysicalDevice physicalDevice) {
vulkanPhysicalDevice* device = (vulkanPhysicalDevice*)physicalDevice; // VkPhysicalDevice device = (VkPhysicalDevice)physicalDevice;
uint32_t queueFamilyCount = 0; // uint32_t queueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, NULL); // vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, NULL);
VkQueueFamilyProperties* queueFamilies = malloc(sizeof(VkQueueFamilyProperties) * queueFamilyCount); // VkQueueFamilyProperties* queueFamilies = malloc(sizeof(VkQueueFamilyProperties) * queueFamilyCount);
vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, queueFamilies); // vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies);
device->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount); // device->neededQueues = malloc(sizeof(vulkanNeededQueue) * queueFamilyCount);
for (uint32_t c = 0; c < queueFamilyCount; c++) { // for (uint32_t c = 0; c < queueFamilyCount; c++) {
gnBool hasNeededQueue = GN_FALSE; // gnBool hasNeededQueue = GN_FALSE;
if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) // if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT)
hasNeededQueue = GN_TRUE; // hasNeededQueue = GN_TRUE;
if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT) // if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT) == VK_QUEUE_TRANSFER_BIT)
hasNeededQueue = GN_TRUE; // hasNeededQueue = GN_TRUE;
if (hasNeededQueue) { // if (hasNeededQueue) {
vulkanNeededQueue neededQueue = { // vulkanNeededQueue neededQueue = {
.queueIndex = c, // .queueIndex = c,
.createFlags = 0, // .createFlags = 0,
.usedForPresent = GN_FALSE // .usedForPresent = GN_FALSE
}; // };
if ((queueFamilies[c].queueFlags & VK_QUEUE_GRAPHICS_BIT)) neededQueue.createFlags |= VK_QUEUE_GRAPHICS_BIT; // 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; // if ((queueFamilies[c].queueFlags & VK_QUEUE_TRANSFER_BIT)) neededQueue.createFlags |= VK_QUEUE_TRANSFER_BIT;
device->neededQueues[device->neededQueueCount] = neededQueue; // device->neededQueues[device->neededQueueCount] = neededQueue;
device->neededQueueCount++; // device->neededQueueCount++;
} // }
} // }
free(queueFamilies); // free(queueFamilies);
} // }
gnBool deviceCanPresentToSurface(gnPhysicalDevice physicalDevice, gnWindowSurface surface) { // gnBool deviceCanPresentToSurface(gnPhysicalDevice physicalDevice, gnWindowSurface surface) {
vulkanPhysicalDevice* device = (vulkanPhysicalDevice*)physicalDevice; // vulkanPhysicalDevice* device = (vulkanPhysicalDevice*)physicalDevice;
uint32_t queueFamilyCount = 0; // uint32_t queueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, NULL); // vkGetPhysicalDeviceQueueFamilyProperties(device->device, &queueFamilyCount, NULL);
for (uint32_t i = 0; i < queueFamilyCount; i++) { // for (uint32_t i = 0; i < queueFamilyCount; i++) {
VkBool32 supportsPresent; // VkBool32 supportsPresent;
vkGetPhysicalDeviceSurfaceSupportKHR(device->device, i, surface->windowSurface->surface, &supportsPresent); // vkGetPhysicalDeviceSurfaceSupportKHR(device->device, i, surface->windowSurface->surface, &supportsPresent);
if (supportsPresent) return GN_TRUE; // if (supportsPresent) return GN_TRUE;
} // }
return GN_FALSE; // return GN_FALSE;
} // }

View File

@@ -10,7 +10,9 @@ typedef struct vulkanNeededQueue {
} vulkanNeededQueue; } vulkanNeededQueue;
gnPhysicalDeviceProperties vulkanQueryPhysicalDeviceProperties(gnInstance instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* layers); gnPhysicalDeviceProperties vulkanQueryPhysicalDeviceProperties(gnInstance instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* layers);
gnPhysicalDeviceFeatures vulkanQueryPhysicalDeviceFeatures(gnInstance instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* layers);
gnPhysicalDeviceLimits vulkanQueryPhysicalDeviceLimits(gnInstance instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* layers);
gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface); gnBool deviceCanPresentToSurface(gnPhysicalDevice device, gnWindowSurface surface);
gnMultisampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts); gnSampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts);
VkSampleCountFlags gnSampleCountToVulkan(gnMultisampleCountFlags counts); VkSampleCountFlags gnSampleCountToVulkan(gnSampleCountFlags counts);