fix: rendering now works — three critical bugs fixed

1. VkColorComponentFlags: wrong bit values (0x10-0x80 instead of 0x01-0x08)
   → colorWriteMask was 0xF0 instead of 0x0F → no color channels written

2. VkClearValue: was Sequential layout instead of Explicit (union)
   → depthStencil clear value written at wrong offset → depth buffer
   cleared to 0.0 instead of 1.0 → all fragments failed depth test

3. Vulkan clip space correction in vertex shader:
   gl_Position.y = -gl_Position.y (Vulkan Y-down vs OpenGL Y-up)
   gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5 (Z [0,1] vs [-1,1])

Also:
- PushConstantSize fixed from 128 to 144 (two mat4 + vec4)
- Dynamic viewport/scissor state added to pipeline
- Push constants use column_major (default) to match System.Numerics row-major layout
- Camera.GetProjectionMatrix reverted to pure OpenGL-style (correction in shader)
- Screenshots show actual 3D geometry (calibration cubes visible)
- 66/66 tests pass
This commit is contained in:
emil28092005
2026-06-18 00:14:40 +03:00
parent 749fbc8df4
commit 46a04850e3
7 changed files with 45 additions and 19 deletions
+13 -4
View File
@@ -14,7 +14,7 @@ public sealed unsafe class VulkanPipeline : IDisposable
private readonly VulkanContext _ctx;
private bool _disposed;
public const int PushConstantSize = 128;
public const int PushConstantSize = 144;
public const int FrameUboSize = 16 + 16 + 16 * 4 * 8;
public VulkanPipeline(VulkanContext ctx, VkRenderPass renderPass)
@@ -84,8 +84,8 @@ public sealed unsafe class VulkanPipeline : IDisposable
primitiveRestartEnable = 0
};
var viewport = new VkViewport { x = 0, y = 0, width = 0, height = 0, minDepth = 0, maxDepth = 1 };
var scissor = new VkRect2D { offset = new VkOffset2D { x = 0, y = 0 }, extent = new VkExtent2D { width = 0, height = 0 } };
var viewport = new VkViewport { x = 0, y = 0, width = 1280, height = 720, minDepth = 0, maxDepth = 1 };
var scissor = new VkRect2D { offset = new VkOffset2D { x = 0, y = 0 }, extent = new VkExtent2D { width = 1280, height = 720 } };
VkPipelineViewportStateCreateInfo viewportState;
viewportState.sType = VkStructureType.PipelineViewportStateCreateInfo;
@@ -163,6 +163,15 @@ public sealed unsafe class VulkanPipeline : IDisposable
colorBlendState.attachmentCount = 1;
colorBlendState.pAttachments = &blendAttachment;
var dynamicStates = stackalloc VkDynamicState[2];
dynamicStates[0] = VkDynamicState.Viewport;
dynamicStates[1] = VkDynamicState.Scissor;
VkPipelineDynamicStateCreateInfo dynamicState = default;
dynamicState.sType = VkStructureType.PipelineDynamicStateCreateInfo;
dynamicState.dynamicStateCount = 2;
dynamicState.pDynamicStates = dynamicStates;
var uboBinding = new VkDescriptorSetLayoutBinding
{
binding = 0,
@@ -226,7 +235,7 @@ public sealed unsafe class VulkanPipeline : IDisposable
pipelineInfo.pMultisampleState = &multisampleState;
pipelineInfo.pDepthStencilState = &depthStencilState;
pipelineInfo.pColorBlendState = &colorBlendState;
pipelineInfo.pDynamicState = null;
pipelineInfo.pDynamicState = &dynamicState;
pipelineInfo.layout = pipeLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.subpass = 0;