Sanitize some more structs

This commit is contained in:
Bill Currie 2020-02-17 23:30:25 +09:00
parent 94565c2382
commit 73fde40cad
4 changed files with 62 additions and 108 deletions

View file

@ -1,6 +1,8 @@
#ifndef __QF_Vulkan_pipeline_h
#define __QF_Vulkan_pipeline_h
#include "QF/darray.h"
typedef struct qfv_shadermodule_s {
struct qfv_device_s *device;
VkShaderModule module;
@ -13,29 +15,24 @@ typedef struct qfv_shaderstageparams_s {
const VkSpecializationInfo *specializationInfo;
} qfv_shaderstageparams_t;
typedef struct qfv_shaderstageparamsset_s {
uint32_t numParams;
qfv_shaderstageparams_t params[];
} qfv_shaderstageparamsset_t;
typedef struct qfv_shaderstageparamsset_s
DARRAY_TYPE (qfv_shaderstageparams_t) qfv_shaderstageparamsset_t;
#define QFV_AllocShaderParamsSet(num, allocator) \
allocator (field_offset (qfv_shaderstageparamsset_t, params[num]))
DARRAY_ALLOCFIXED (qfv_shaderstageparamsset_t, num, allocator)
typedef struct qfv_vertexinputbindingset_s {
uint32_t numBindings;
VkVertexInputBindingDescription bindings[];
} qfv_vertexinputbindingset_t;
typedef struct qfv_vertexinputbindingset_s
DARRAY_TYPE (VkVertexInputBindingDescription) qfv_vertexinputbindingset_t;
#define QFV_AllocVertexInputBindingSet(num, allocator) \
allocator (field_offset (qfv_vertexinputbindingset_t, bindings[num]))
DARRAY_ALLOCFIXED (qfv_vertexinputbindingset_t, num, allocator)
typedef struct qfv_vertexinputattributeset_s {
uint32_t numAttributes;
VkVertexInputAttributeDescription attributes[];
} qfv_vertexinputattributeset_t;
typedef struct qfv_vertexinputattributeset_s
DARRAY_TYPE (VkVertexInputAttributeDescription)
qfv_vertexinputattributeset_t;
#define QFV_AllocVertexInputAttributeSet(num, allocator) \
allocator (field_offset (qfv_vertexinputattributeset_t, bindings[num]))
DARRAY_ALLOCFIXED (qfv_vertexinputattributeset_t, num, allocator)
typedef struct qfv_vertexinputstate_s {
qfv_vertexinputbindingset_t *bindings;
@ -168,7 +165,7 @@ typedef struct qfv_graphicspipelinecreateinfo_s {
qfv_pipelineblend_t *colorBlendState;
qfv_dynamicstateset_t *dynamicState;
qfv_pipelinelayout_t *layout;
struct qfv_renderpass_s *renderPass;
VkRenderPass renderPass;
uint32_t subpass;
qfv_pipeline_t *basePipeline;
int32_t basePipelineIndex;

View file

@ -1,21 +1,19 @@
#ifndef __QF_Vulkan_renderpass_h
#define __QF_Vulkan_renderpass_h
typedef struct qfv_attachmentdescription_s {
uint32_t numAttachments;
VkAttachmentDescription attachments[];
} qfv_attachmentdescription_t;
#include "QF/darray.h"
typedef struct qfv_attachmentdescription_s
DARRAY_TYPE (VkAttachmentDescription) qfv_attachmentdescription_t;
#define QFV_AllocAttachmentDescription(num, allocator) \
allocator (field_offset (qfv_attachmentdescription_t, attachments[num]))
DARRAY_ALLOCFIXED (qfv_attachmentdescription_t, num, allocator)
typedef struct qfv_attachmentreference_s {
uint32_t numReferences;
VkAttachmentReference references[];
} qfv_attachmentreference_t;
typedef struct qfv_attachmentreference_s
DARRAY_TYPE (VkAttachmentReference) qfv_attachmentreference_t;
#define QFV_AllocAttachmentReference(num, allocator) \
allocator (field_offset (qfv_attachmentreference_t, references[num]))
DARRAY_ALLOCFIXED (qfv_attachmentreference_t, num, allocator)
typedef struct qfv_subpassparameters_s {
VkPipelineBindPoint pipelineBindPoint;
@ -27,46 +25,30 @@ typedef struct qfv_subpassparameters_s {
uint32_t *preserveAttachments;
} qfv_subpassparameters_t;
typedef struct qfv_subpassparametersset_s {
uint32_t numSubpasses;
qfv_subpassparameters_t subpasses[];
} qfv_subpassparametersset_t;
typedef struct qfv_subpassparametersset_s
DARRAY_TYPE (qfv_subpassparameters_t) qfv_subpassparametersset_t;
#define QFV_AllocSubpassParametersSet(num, allocator) \
allocator (field_offset (qfv_subpassparametersset_t, subpasses[num]))
DARRAY_ALLOCFIXED (qfv_subpassparametersset_t, num, allocator)
typedef struct qfv_subpassdependency_s {
uint32_t numDependencies;
VkSubpassDependency dependencies[];
} qfv_subpassdependency_t;
typedef struct qfv_subpassdependency_s
DARRAY_TYPE (VkSubpassDependency) qfv_subpassdependency_t;
#define QFV_AllocSubpassDependencies(num, allocator) \
allocator (field_offset (qfv_subpassdependency_t, dependencies[num]))
DARRAY_ALLOCFIXED (qfv_subpassdependency_t, num, allocator)
typedef struct qfv_renderpass_s {
struct qfv_device_s *device;
VkRenderPass renderPass;
} qfv_renderpass_t;
typedef struct qfv_framebuffer_s {
struct qfv_device_s *device;
VkFramebuffer framebuffer;
} qfv_framebuffer_t;
qfv_renderpass_t *
struct qfv_device_s;
VkRenderPass
QFV_CreateRenderPass (struct qfv_device_s *device,
qfv_attachmentdescription_t *attachments,
qfv_subpassparametersset_t *subpasses,
qfv_subpassdependency_t *dependencies);
struct qfv_imageview_s;
qfv_framebuffer_t *
QFV_CreateFramebuffer (qfv_renderpass_t *renderPass,
VkFramebuffer
QFV_CreateFramebuffer (struct qfv_device_s *device,
VkRenderPass renderPass,
uint32_t numAttachments,
VkImageView *attachments,
uint32_t width, uint32_t height, uint32_t layers);
void QFV_DestroyFramebuffer (qfv_framebuffer_t *framebuffer);
void QFV_DestroyRenderPass (qfv_renderpass_t *renderPass);
#endif//__QF_Vulkan_renderpass_h

View file

@ -205,10 +205,10 @@ vertexInputSCI (qfv_vertexinputstate_t vertexState)
{
VkPipelineVertexInputStateCreateInfo createInfo = {
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, 0, 0,
vertexState.bindings->numBindings,
vertexState.bindings->bindings,
vertexState.attributes->numAttributes,
vertexState.attributes->attributes,
vertexState.bindings->size,
vertexState.bindings->a,
vertexState.attributes->size,
vertexState.attributes->a,
};
return createInfo;
}
@ -339,7 +339,7 @@ QFV_CreateGraphicsPipelines (qfv_device_t *device,
uint32_t numPipelines = gpciSet->numPipelines;
uint32_t stageCount = 0;
for (uint32_t i = 0; i < numPipelines; i++) {
stageCount += gpciSet->pipelines[i]->stages->numParams;
stageCount += gpciSet->pipelines[i]->stages->size;
}
size_t blockSize = numPipelines
@ -377,7 +377,7 @@ QFV_CreateGraphicsPipelines (qfv_device_t *device,
= (void *)(pipelineInfos->pColorBlendState + numPipelines);
for (uint32_t i = 1; i < gpciSet->numPipelines; i++) {
pipelineInfos[i].pStages = pipelineInfos[i - 1].pStages
+ gpciSet->pipelines[i - 1]->stages->numParams;
+ gpciSet->pipelines[i - 1]->stages->size;
pipelineInfos[i].pVertexInputState
= pipelineInfos[i - 1].pVertexInputState + 1;
pipelineInfos[i].pInputAssemblyState
@ -403,9 +403,9 @@ QFV_CreateGraphicsPipelines (qfv_device_t *device,
gci->sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
gci->pNext = 0;
gci->flags = ci->flags;
gci->stageCount = ci->stages->numParams;
gci->stageCount = ci->stages->size;
for (uint32_t j = 0; j < gci->stageCount; j++) {
((VkPipelineShaderStageCreateInfo *)gci->pStages)[i] = shaderStageCI (ci->stages->params[j]);
((VkPipelineShaderStageCreateInfo *)gci->pStages)[i] = shaderStageCI (ci->stages->a[j]);
}
if (ci->vertexState) {
*(VkPipelineVertexInputStateCreateInfo *)gci->pVertexInputState = vertexInputSCI (*ci->vertexState);
@ -453,7 +453,7 @@ QFV_CreateGraphicsPipelines (qfv_device_t *device,
gci->pDynamicState = 0;
}
gci->layout = ci->layout->layout;
gci->renderPass = ci->renderPass->renderPass;
gci->renderPass = ci->renderPass;
gci->subpass = ci->subpass;
gci->basePipelineHandle = ci->basePipeline->pipeline;
gci->basePipelineIndex = ci->basePipelineIndex;

View file

@ -1,7 +1,7 @@
/*
descriptor.c
renderpass.c
Vulkan descriptor functions
Vulkan render pass and frame buffer functions
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2020 Bill Currie <bill@taniwha.org>
@ -62,7 +62,7 @@
#include "util.h"
qfv_renderpass_t *
VkRenderPass
QFV_CreateRenderPass (qfv_device_t *device,
qfv_attachmentdescription_t *attachments,
qfv_subpassparametersset_t *subpassparams,
@ -71,19 +71,19 @@ QFV_CreateRenderPass (qfv_device_t *device,
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
VkSubpassDescription *subpasses = alloca (subpassparams->numSubpasses
VkSubpassDescription *subpasses = alloca (subpassparams->size
* sizeof (*subpasses));
for (uint32_t i = 0; i < subpassparams->numSubpasses; i++) {
qfv_subpassparameters_t *params = &subpassparams->subpasses[i];
for (uint32_t i = 0; i < subpassparams->size; i++) {
qfv_subpassparameters_t *params = &subpassparams->a[i];
subpasses[i].flags = 0;
subpasses[i].pipelineBindPoint = params->pipelineBindPoint;
subpasses[i].inputAttachmentCount = params->inputAttachments->numReferences;
subpasses[i].pInputAttachments = params->inputAttachments->references;
subpasses[i].colorAttachmentCount = params->colorAttachments->numReferences;
subpasses[i].pColorAttachments = params->colorAttachments->references;
subpasses[i].inputAttachmentCount = params->inputAttachments->size;
subpasses[i].pInputAttachments = params->inputAttachments->a;
subpasses[i].colorAttachmentCount = params->colorAttachments->size;
subpasses[i].pColorAttachments = params->colorAttachments->a;
if (params->resolveAttachments) {
subpasses[i].pResolveAttachments = params->resolveAttachments->references;
subpasses[i].pResolveAttachments = params->resolveAttachments->a;
}
subpasses[i].pDepthStencilAttachment = params->depthStencilAttachment;
subpasses[i].preserveAttachmentCount = params->numPreserve;
@ -92,56 +92,31 @@ QFV_CreateRenderPass (qfv_device_t *device,
VkRenderPassCreateInfo createInfo = {
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, 0, 0,
attachments->numAttachments, attachments->attachments,
subpassparams->numSubpasses, subpasses,
dependencies->numDependencies, dependencies->dependencies,
attachments->size, attachments->a,
subpassparams->size, subpasses,
dependencies->size, dependencies->a,
};
qfv_renderpass_t *renderpass = malloc (sizeof (*renderpass));
renderpass->device = device;
dfunc->vkCreateRenderPass (dev, &createInfo, 0, &renderpass->renderPass);
VkRenderPass renderpass;
dfunc->vkCreateRenderPass (dev, &createInfo, 0, &renderpass);
return renderpass;
}
qfv_framebuffer_t *
QFV_CreateFramebuffer (qfv_renderpass_t *renderPass,
VkFramebuffer
QFV_CreateFramebuffer (qfv_device_t *device, VkRenderPass renderPass,
uint32_t numAttachments, VkImageView *attachments,
uint32_t width, uint32_t height, uint32_t layers)
{
qfv_device_t *device = renderPass->device;
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
VkFramebufferCreateInfo createInfo = {
VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, 0, 0,
renderPass->renderPass, numAttachments, attachments,
renderPass, numAttachments, attachments,
width, height, layers,
};
qfv_framebuffer_t *framebuffer = malloc (sizeof (*framebuffer));
framebuffer->device = device;
dfunc->vkCreateFramebuffer (dev, &createInfo, 0, &framebuffer->framebuffer);
VkFramebuffer framebuffer;
dfunc->vkCreateFramebuffer (dev, &createInfo, 0, &framebuffer);
return framebuffer;
}
void
QFV_DestroyFramebuffer (qfv_framebuffer_t *framebuffer)
{
qfv_device_t *device = framebuffer->device;
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
dfunc->vkDestroyFramebuffer (dev, framebuffer->framebuffer, 0);
free (framebuffer);
}
void
QFV_DestroyRenderPass (qfv_renderpass_t *renderPass)
{
qfv_device_t *device = renderPass->device;
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
dfunc->vkDestroyRenderPass (dev, renderPass->renderPass, 0);
free (renderPass);
}