You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ImGui与计算绘制正常,但三角形无法显示的问题排查

Vulkan开发三角形无法显示问题排查求助

我参考VkGuide做Vulkan开发,但未完全照搬现有实现,目前遇到三角形无法显示的问题:通过RenderDoc查看,网格视图中顶点绘制结果正确,但最终画面无任何内容。

已完成排查项:

  • 对照VkGuide检查代码,未发现流程遗漏
  • RenderDoc确认着色器已正确加入管线,且各着色器处于对应阶段
  • 顶点环绕顺序为CCW
  • 剔除模式设置为None

RenderDoc相关截图

  • 三角形网格视图:Triangle mesh in render doc
  • 绘制前纹理视图:Before drawing texture view
  • 绘制后纹理视图:After drawing texture view
  • 绘制命令管线状态:Draw pipeline state

顶点着色器

#pragma shader_stage(vertex)

struct VSOutput {
    float4 position: SV_POSITION;
    [[vk::location(0)]] float3 out_colour: COLOR0;
};

VSOutput main(uint VertexIndex : SV_VertexID)
{
  float3x3 positions = float3x3(
    float3(0, -0.5, 0.5),
    float3(-0.5, 0.5, 0.5),
    float3(0.5, 0.5, 0.5)
  );

  float3x3 colours = float3x3(
    float3(1, 0, 0),
    float3(0, 1, 0),
    float3(0, 0, 1)
  );

    VSOutput output;
    output.position = float4(positions[VertexIndex], 1.0);
    output.out_colour = colours[VertexIndex];
    return output;
}

片段着色器

#pragma shader_stage(fragment)

struct FSInput {
    [[vk::location(0)]] float3 colour: COLOR0;
};

struct FSOutput {
    [[vk::location(0)]] float4 colour: COLOR0;
};

FSOutput main(FSInput input)
{
  FSOutput output;
  output.colour = float4(input.colour , 1.0);
  return output;
}

命令缓冲区录制代码

void Engine2D::draw_geometry(vk::CommandBuffer command_buffer) {
    auto colour_attachment =
        init::attachment_info(swapchain.draw_image.image_view, nullptr,
                              vk::ImageLayout::eColorAttachmentOptimal);
    auto render_info =
        init::rendering_info(swapchain.extent, &colour_attachment, nullptr);
    command_buffer.beginRendering(&render_info);
    command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics,
                                triangle_pipeline.pipeline);

    auto view_port = vk::Viewport{}
                         .setX(0)
                         .setY(0)
                         .setWidth(swapchain.extent.width)
                         .setHeight(swapchain.extent.height)
                         .setMinDepth(0)
                         .setMaxDepth(1);
    command_buffer.setViewport(0, view_port);
    auto scissor = vk::Rect2D{}
                       .setOffset(vk::Offset2D{}.setX(0).setY(0))
                       .setExtent(swapchain.extent);
    command_buffer.setScissor(0, scissor);
    command_buffer.draw(3, 1, 0, 0);
    command_buffer.endRendering();
}

补充说明

已尝试以下操作但均未解决问题:

  • 使用VkGuide完全相同的管线设置
  • 反复核对代码逻辑
  • 直接使用并编译VkGuide同款OpenGL着色器
  • 修改着色器阶段数量

内容的提问来源于stack exchange,提问作者CyberFlow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 22:29:56