finish depth buffering

This commit is contained in:
Gregory Wells
2025-06-17 15:21:16 -04:00
parent 86f2ac6e5a
commit e4e182610a
4 changed files with 116 additions and 31 deletions

View File

@@ -16,7 +16,7 @@ VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e st
}
}
VkPrimitiveTopology vkGryphnPrimitiveType(enum gnPrimitiveType_e primitiveType) {
VkPrimitiveTopology vkGryphnPrimitiveType(gnPrimitiveType primitiveType) {
switch (primitiveType) {
case GN_PRIMITIVE_POINTS: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
case GN_PRIMITIVE_LINES: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
@@ -64,6 +64,32 @@ VkFormat vkGryphnVertexFormat(gnVertexFormat format) {
}
}
VkCompareOp vkGrypnCompareOperation(gnCompareOperation operation) {
switch(operation) {
case GN_COMPARE_NEVER: return VK_COMPARE_OP_NEVER;
case GN_COMPARE_LESS: return VK_COMPARE_OP_LESS;
case GN_COMPARE_EQUAL: return VK_COMPARE_OP_EQUAL;
case GN_COMPARE_LESS_OR_EQUAL: return VK_COMPARE_OP_LESS_OR_EQUAL;
case GN_COMPARE_GREATER: return VK_COMPARE_OP_GREATER;
case GN_COMPARE_NOT_EQUAL: return VK_COMPARE_OP_NOT_EQUAL;
case GN_COMPARE_GREATER_OR_EQUAL: return VK_COMPARE_OP_GREATER_OR_EQUAL;
case GN_COMPARE_ALWAYS: return VK_COMPARE_OP_ALWAYS;
}
}
VkStencilOp vkGryphnStencilOperation(gnStencilOperation operation) {
switch(operation) {
case GN_STENCIL_KEEP: return VK_STENCIL_OP_KEEP;
case GN_STENCIL_ZERO: return VK_STENCIL_OP_ZERO;
case GN_STENCIL_REPLACE: return VK_STENCIL_OP_REPLACE;
case GN_STENCIL_INCREMENT_AND_CLAMP: return VK_STENCIL_OP_INCREMENT_AND_CLAMP;
case GN_STENCIL_DECREMENT_AND_CLAMP: return VK_STENCIL_OP_DECREMENT_AND_CLAMP;
case GN_STENCIL_INVERT: return VK_STENCIL_OP_INVERT;
case GN_STENCIL_INCREMENT_AND_WRAP: return VK_STENCIL_OP_INCREMENT_AND_WRAP;
case GN_STENCIL_DECREMENT_AND_WRAP: return VK_STENCIL_OP_DECREMENT_AND_WRAP;
}
}
gnReturnCode gnCreateGraphicsPipelineFn(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;
@@ -180,6 +206,37 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD
.blendConstants[3] = 0.0f
};
graphicsPipeline->graphicsPipeline->depthStencil = (VkPipelineDepthStencilStateCreateInfo){
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
.depthWriteEnable = info.depthStencil.depthWriteEnable,
.depthTestEnable = info.depthStencil.depthWriteEnable,
.depthCompareOp = vkGrypnCompareOperation(info.depthStencil.operation),
.depthBoundsTestEnable = VK_FALSE,
.stencilTestEnable = info.depthStencil.stencilTestEnable,
};
if (info.depthStencil.stencilTestEnable) {
graphicsPipeline->graphicsPipeline->depthStencil.front = (VkStencilOpState){
.failOp = vkGryphnStencilOperation(info.depthStencil.front.failOperation),
.passOp = vkGryphnStencilOperation(info.depthStencil.front.passOperation),
.depthFailOp = vkGryphnStencilOperation(info.depthStencil.front.depthFailOperation),
.compareOp = vkGrypnCompareOperation(info.depthStencil.front.compareOperation),
.compareMask = info.depthStencil.front.compareMask,
.writeMask = info.depthStencil.front.writeMask,
.reference = info.depthStencil.front.reference,
};
graphicsPipeline->graphicsPipeline->depthStencil.back = (VkStencilOpState){
.failOp = vkGryphnStencilOperation(info.depthStencil.back.failOperation),
.passOp = vkGryphnStencilOperation(info.depthStencil.back.passOperation),
.depthFailOp = vkGryphnStencilOperation(info.depthStencil.back.depthFailOperation),
.compareOp = vkGrypnCompareOperation(info.depthStencil.back.compareOperation),
.compareMask = info.depthStencil.back.compareMask,
.writeMask = info.depthStencil.back.writeMask,
.reference = info.depthStencil.back.reference,
};
}
graphicsPipeline->graphicsPipeline->setCount = info.uniformLayout.setCount;
graphicsPipeline->graphicsPipeline->sets = malloc(sizeof(VkDescriptorSetLayout) * info.uniformLayout.setCount);
for (int i = 0; i < info.uniformLayout.setCount; i++) graphicsPipeline->graphicsPipeline->sets[i] = vkGryphnCreateSetLayouts(&info.uniformLayout.sets[i], device->outputDevice->device);
@@ -209,7 +266,7 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD
.pViewportState = &graphicsPipeline->graphicsPipeline->viewportState,
.pRasterizationState = &graphicsPipeline->graphicsPipeline->rasterizer,
.pMultisampleState = &multisampling,
.pDepthStencilState = NULL,
.pDepthStencilState = &graphicsPipeline->graphicsPipeline->depthStencil,
.pColorBlendState = &graphicsPipeline->graphicsPipeline->colorBlending,
.pDynamicState = &graphicsPipeline->graphicsPipeline->dynamicState,
.layout = graphicsPipeline->graphicsPipeline->pipelineLayout,

View File

@@ -14,6 +14,7 @@ typedef struct gnPlatformGraphicsPipeline_t {
VkPipelineRasterizationStateCreateInfo rasterizer;
VkPipelineColorBlendAttachmentState colorBlendAttachment;
VkPipelineColorBlendStateCreateInfo colorBlending;
VkPipelineDepthStencilStateCreateInfo depthStencil;
// gnBool createdPipelineLayout;
uint32_t setCount;

View File

@@ -1,7 +1,7 @@
#include "gryphn_graphics_pipeline.h"
#include "core/gryphn_platform_functions.h"
gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t info) {
gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) {
*graphicsPipeline = malloc(sizeof(struct gnGraphicsPipeline_t));
(*graphicsPipeline)->device = device;
(*graphicsPipeline)->info = info;

View File

@@ -14,14 +14,25 @@ typedef enum gnDynamicState_e {
GN_DYNAMIC_STATE_MAX
} gnDynamicState;
typedef struct gnDynamicStateInfo_t {
typedef struct gnDynamicStateInfo {
uint32_t dynamicStateCount;
enum gnDynamicState_e* dynamicStates;
} gnDynamicStateInfo;
typedef enum gnPrimitiveType_e {
typedef enum gnPrimitiveType {
GN_PRIMITIVE_POINTS, GN_PRIMITIVE_LINES, GN_PRIMITIVE_LINE_STRIP, GN_PRIMITIVE_TRIANGLES, GN_PRIMITIVE_TRIANGLE_STRIP
} gnPrimativeType;
} gnPrimitiveType;
typedef enum gnBlendFactor_e {
GN_BLEND_FACTOR_ZERO,
GN_BLEND_FACTOR_ONE,
GN_BLEND_FACTOR_SRC_ALPHA,
GN_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
} gnBlendFactor;
typedef enum gnBlendOperation_e {
GN_OPERATION_ADD
} gnBlendOperation;
typedef struct gnViewport_t {
gnVec2 position;
@@ -47,41 +58,57 @@ typedef enum gnCullDirection_e {
GN_DIRECTION_CLOCK_WISE, GN_DIRECTION_COUNTER_CLOCK_WISE
} gnCullDirection;
typedef enum gnCompareOperation {
GN_COMPARE_NEVER, GN_COMPARE_LESS, GN_COMPARE_EQUAL,
GN_COMPARE_LESS_OR_EQUAL, GN_COMPARE_GREATER, GN_COMPARE_NOT_EQUAL,
GN_COMPARE_GREATER_OR_EQUAL, GN_COMPARE_ALWAYS
} gnCompareOperation;
typedef enum gnStencilOperation {
GN_STENCIL_KEEP, GN_STENCIL_ZERO, GN_STENCIL_REPLACE,
GN_STENCIL_INCREMENT_AND_CLAMP, GN_STENCIL_DECREMENT_AND_CLAMP,
GN_STENCIL_INVERT, GN_STENCIL_INCREMENT_AND_WRAP,
GN_STENCIL_DECREMENT_AND_WRAP,
} gnStencilOperation;
typedef struct gnCullMode_t {
enum gnCullFace_e face;
enum gnCullDirection_e direction;
} gnCullMode;
typedef enum gnBlendFactor_e {
GN_BLEND_FACTOR_ZERO,
GN_BLEND_FACTOR_ONE,
GN_BLEND_FACTOR_SRC_ALPHA,
GN_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
} gnBlendFactor;
typedef enum gnBlendOperation_e {
GN_OPERATION_ADD
} gnBlendOperation;
typedef struct gnColorBlending_t {
gnBool enable;
enum gnBlendFactor_e sourceColorBlendFactor;
enum gnBlendFactor_e sourceAlphaBlendFactor;
enum gnBlendFactor_e destinationColorBlendFactor;
enum gnBlendFactor_e destinationAlphaBlendFactor;
gnBlendFactor sourceColorBlendFactor;
gnBlendFactor sourceAlphaBlendFactor;
gnBlendFactor destinationColorBlendFactor;
gnBlendFactor destinationAlphaBlendFactor;
enum gnBlendOperation_e colorBlendOperation;
enum gnBlendOperation_e alphaBlendOperation;
gnBlendOperation colorBlendOperation;
gnBlendOperation alphaBlendOperation;
} gnColorBlending;
typedef struct gnStencilState {
gnStencilOperation failOperation, passOperation, depthFailOperation;
gnCompareOperation compareOperation;
uint32_t compareMask, writeMask, reference;
} gnStencilState;
typedef struct gnDepthStencilState {
gnBool depthTestEnable, depthWriteEnable;
gnCompareOperation operation;
gnBool stencilTestEnable;
gnStencilState front, back;
} gnDepthStencilState;
typedef struct gnGraphicsPipelineInfo_t {
struct gnDynamicStateInfo_t dynamicState;
enum gnPrimitiveType_e primitiveType;
struct gnViewport_t viewport;
struct gnScissor_t scissor;
enum gnFillMode_e fillMode;
struct gnCullMode_t cullMode;
struct gnColorBlending_t colorBlending;
gnDynamicStateInfo dynamicState;
gnPrimitiveType primitiveType;
gnViewport viewport;
gnScissor scissor;
gnFillMode fillMode;
gnCullMode cullMode;
gnColorBlending colorBlending;
gnDepthStencilState depthStencil;
uint32_t subpassIndex;
gnRenderPassDescriptorHandle renderPassDescriptor;
@@ -101,5 +128,5 @@ struct gnGraphicsPipeline_t {
};
#endif
gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnOutputDeviceHandle device, struct gnGraphicsPipelineInfo_t info);
gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnOutputDeviceHandle device, gnGraphicsPipelineInfo info);
void gnDestroyGraphicsPipeline(gnGraphicsPipelineHandle graphicsPipeline);