render pass stuff for multisampling

This commit is contained in:
Greg Wells
2025-07-05 17:02:38 -04:00
parent 2ffa5adbb9
commit d567ce0beb
8 changed files with 51 additions and 11 deletions

View File

@@ -3,12 +3,8 @@
#include <output_device/vulkan_device_extensions.h>
#include <vulkan_surface/vulkan_surface.h>
gnMultisampleCountFlags getVulkanSampleCount(VkPhysicalDevice device) {
VkPhysicalDeviceProperties physicalDeviceProperties;
vkGetPhysicalDeviceProperties(device, &physicalDeviceProperties);
VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts & physicalDeviceProperties.limits.framebufferDepthSampleCounts;
gnMultisampleCountFlags sampleCount = GN_SAMPLES_NONE;
gnMultisampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts) {
gnMultisampleCountFlags sampleCount = 0;
if (counts & VK_SAMPLE_COUNT_64_BIT) { sampleCount |= GN_SAMPLE_BIT_64; }
if (counts & VK_SAMPLE_COUNT_32_BIT) { sampleCount |= GN_SAMPLE_BIT_32; }
if (counts & VK_SAMPLE_COUNT_16_BIT) { sampleCount |= GN_SAMPLE_BIT_16; }
@@ -16,6 +12,21 @@ gnMultisampleCountFlags getVulkanSampleCount(VkPhysicalDevice device) {
if (counts & VK_SAMPLE_COUNT_4_BIT) { sampleCount |= GN_SAMPLE_BIT_4; }
if (counts & VK_SAMPLE_COUNT_2_BIT) { sampleCount |= GN_SAMPLE_BIT_2; }
if (counts & VK_SAMPLE_COUNT_1_BIT) { sampleCount |= GN_SAMPLE_BIT_1; }
return sampleCount;
}
#include <stdio.h>
VkSampleCountFlags gnSampleCountToVulkan(gnMultisampleCountFlags counts) {
VkSampleCountFlags sampleCount = 0;
if ((counts & GN_SAMPLE_BIT_64) == GN_SAMPLE_BIT_64) { sampleCount |= VK_SAMPLE_COUNT_64_BIT; }
if ((counts & GN_SAMPLE_BIT_32) == GN_SAMPLE_BIT_32) { sampleCount |= VK_SAMPLE_COUNT_32_BIT; }
if ((counts & GN_SAMPLE_BIT_16) == GN_SAMPLE_BIT_16) { sampleCount |= VK_SAMPLE_COUNT_16_BIT; }
if ((counts & GN_SAMPLE_BIT_8) == GN_SAMPLE_BIT_8) { sampleCount |= VK_SAMPLE_COUNT_8_BIT; }
if ((counts & GN_SAMPLE_BIT_4) == GN_SAMPLE_BIT_4) { sampleCount |= VK_SAMPLE_COUNT_4_BIT; }
if ((counts & GN_SAMPLE_BIT_2) == GN_SAMPLE_BIT_2) { sampleCount |= VK_SAMPLE_COUNT_2_BIT; }
if ((counts & GN_SAMPLE_BIT_1) == GN_SAMPLE_BIT_1) { sampleCount |= VK_SAMPLE_COUNT_1_BIT; }
return sampleCount;
}
@@ -61,7 +72,11 @@ gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* device
outputDevices[i].queueProperties.queueProperties[i].queueType = finalQueueType;
}
outputDevices[i].features.avaliableSamples = getVulkanSampleCount(physicalDevices[i]);
VkPhysicalDeviceProperties physicalDeviceProperties;
vkGetPhysicalDeviceProperties(physicalDevices[i], &physicalDeviceProperties);
VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts & physicalDeviceProperties.limits.framebufferDepthSampleCounts;
outputDevices[i].features.avaliableSamples = vkSampleCountToGryphn(counts);
}
free(physicalDevices);

View File

@@ -8,3 +8,7 @@ typedef struct gnPlatformPhysicalDevice_t {
gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* deviceCount);
gnBool queueCanPresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface);
gnMultisampleCountFlags vkSampleCountToGryphn(VkSampleCountFlags counts);
VkSampleCountFlags gnSampleCountToVulkan(gnMultisampleCountFlags counts);

View File

@@ -1,6 +1,7 @@
#include "vulkan_render_pass_descriptor.h"
#include "vulkan_surface/vulkan_surface.h"
#include "output_device/vulkan_output_devices.h"
#include <output_device/vulkan_physical_device.h>
#include "stdio.h"
VkAttachmentLoadOp vkGryphnLoadOperation(gnLoadOperation loadOperation) {
@@ -50,7 +51,7 @@ gnReturnCode createRenderPass(gnRenderPassDescriptor renderPass, gnDevice device
for (int i = 0; i < info.attachmentCount; i++) {
renderPass->renderPassDescriptor->attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format);
renderPass->renderPassDescriptor->attachments[i].flags = 0;
renderPass->renderPassDescriptor->attachments[i].samples = VK_SAMPLE_COUNT_1_BIT;
renderPass->renderPassDescriptor->attachments[i].samples = gnSampleCountToVulkan(info.attachmentInfos[i].samples);
renderPass->renderPassDescriptor->attachments[i].loadOp = vkGryphnLoadOperation(info.attachmentInfos[i].loadOperation);
renderPass->renderPassDescriptor->attachments[i].storeOp = vkGryphnStoreOperation(info.attachmentInfos[i].storeOperation);
@@ -66,9 +67,12 @@ gnReturnCode createRenderPass(gnRenderPassDescriptor renderPass, gnDevice device
renderPass->renderPassDescriptor->subpasses = malloc(sizeof(VkSubpassDescription) * info.subpassCount);
renderPass->renderPassDescriptor->colorAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount);
renderPass->renderPassDescriptor->depthAttachments = malloc(sizeof(VkAttachmentReference) * info.subpassCount);
renderPass->renderPassDescriptor->resolveAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount);
for (int i = 0; i < info.subpassCount; i++) {
renderPass->renderPassDescriptor->colorAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount);
renderPass->renderPassDescriptor->resolveAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].resolveAttachmentCount);
for (int c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) {
renderPass->renderPassDescriptor->colorAttachments[i][c] = (VkAttachmentReference){
@@ -77,11 +81,19 @@ gnReturnCode createRenderPass(gnRenderPassDescriptor renderPass, gnDevice device
};
}
for (int c = 0; c < info.subpassInfos[i].resolveAttachmentCount; c++) {
renderPass->renderPassDescriptor->resolveAttachments[i][c] = (VkAttachmentReference){
.attachment = info.subpassInfos[i].resolveAttachments[c].index,
.layout = vkGryphnImageLayout(info.subpassInfos[i].resolveAttachments[c].imageLayout)
};
}
renderPass->renderPassDescriptor->subpasses[i] = (VkSubpassDescription){
.flags = 0,
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount,
.pColorAttachments = renderPass->renderPassDescriptor->colorAttachments[i]
.pColorAttachments = renderPass->renderPassDescriptor->colorAttachments[i],
.pResolveAttachments = renderPass->renderPassDescriptor->resolveAttachments[i]
};
if (info.subpassInfos[i].depthAttachment != NULL) {

View File

@@ -14,6 +14,7 @@ typedef struct gnPlatformRenderPassDescriptor_t {
VkAttachmentReference** colorAttachments;
VkAttachmentReference* depthAttachments;
VkAttachmentReference** resolveAttachments;
} gnPlatformRenderPassDescriptor;
VkPipelineStageFlags vkGryphnRenderPassStage(gnRenderPassStage stage);

View File

@@ -146,7 +146,7 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.samples = VK_SAMPLE_COUNT_1_BIT,
.samples = gnSampleCountToVulkan(info.samples),
.extent = {
.width = info.extent.width,
.height = info.extent.height,