feat: depth buffer + 3D model matrix — rotating cube now looks correct

- Depth image (D32_SFLOAT) + image view created in VulkanSwapchain
- VkPipelineDepthStencilStateCreateInfo: depth test + write enabled, CompareOp=Less
- Push constant changed from float angle (4B) to mat4 model (64B)
- 3D rotation: RotateY * RotateX in renderer, applied via push constant
- Vertex shader: gl_Position = vp * model * vec4(pos, 1.0)
- Depth attachment in VkRenderingInfo + depth clear (1.0)
- Depth image layout transition (Undefined → DepthStencilAttachmentOptimal)
- New Vulkan functions: vkCreateImage, vkDestroyImage, vkGetImageMemoryRequirements, vkBindImageMemory
- New structs: VkPipelineDepthStencilStateCreateInfo, VkStencilOpState, VkImageCreateInfo
- New enums: VkCompareOp, VkImageType, VkImageTiling
- 0 validation errors
This commit is contained in:
emil28092005
2026-06-18 02:14:54 +03:00
parent fde8b0f63a
commit d6bd1807cf
9 changed files with 265 additions and 18 deletions
+14 -2
View File
@@ -14,7 +14,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
private readonly VkDevice _device;
private bool _disposed;
public VulkanPipeline(VkDevice device, VkFormat colorFormat, byte[] vertSpv, byte[] fragSpv)
public VulkanPipeline(VkDevice device, VkFormat colorFormat, VkFormat depthFormat, byte[] vertSpv, byte[] fragSpv)
{
_device = device;
VertModule = CreateShaderModule(vertSpv);
@@ -115,6 +115,16 @@ internal sealed unsafe class VulkanPipeline : IDisposable
sampleShadingEnable = VkBool32.False,
};
var depthStencilState = new VkPipelineDepthStencilStateCreateInfo
{
sType = VkStructureType.PipelineDepthStencilStateCreateInfo,
depthTestEnable = VkBool32.True,
depthWriteEnable = VkBool32.True,
depthCompareOp = VkCompareOp.Less,
depthBoundsTestEnable = VkBool32.False,
stencilTestEnable = VkBool32.False,
};
var blendAttachment = new VkPipelineColorBlendAttachmentState
{
blendEnable = VkBool32.False,
@@ -144,7 +154,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
{
stageFlags = VkShaderStageFlags.Vertex,
offset = 0,
size = 4,
size = 64,
};
var descLayout = DescriptorSetLayout;
@@ -169,6 +179,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
sType = VkStructureType.PipelineRenderingCreateInfo,
colorAttachmentCount = 1,
pColorAttachmentFormats = &colorFormat,
depthAttachmentFormat = depthFormat,
};
var pipelineInfo = new VkGraphicsPipelineCreateInfo
@@ -182,6 +193,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
pViewportState = &viewportState,
pRasterizationState = &rasterizationState,
pMultisampleState = &multisampleState,
pDepthStencilState = &depthStencilState,
pColorBlendState = &colorBlendState,
pDynamicState = &dynamicState,
layout = PipelineLayout,