I can't draw a triangle when I use TRIANGLE_LIST, but LINE_LIST is right


#1

void TKPipeline::initAssembleStateCreateInfo(){
m_assembleState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
m_assembleState.pNext = nullptr;
m_assembleState.flags = 0;
m_assembleState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
//m_assembleState.topology = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
//m_assembleState.primitiveRestartEnable = VK_FALSE;
}

vkRenderPassCreate as follow:
bool TKRenderPass::initRenderPass(VkFormat format, VkDevice device){
std::vector<VkAttachmentReference> inputAttachRef(1);
inputAttachRef[0].attachment = 0;
inputAttachRef[0].layout = VK_IMAGE_LAYOUT_UNDEFINED;

std::vector&lt;VkAttachmentReference&gt; colorAttachRef(1);
colorAttachRef[0].attachment = 0;
colorAttachRef[0].layout     = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

std::vector&lt;VkAttachmentReference&gt; depthAttachRef(1);
depthAttachRef[0].attachment = 0;
depthAttachRef[0].layout     = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;

std::vector&lt;VkSubpassDescription&gt; subPassDesc(1);
subPassDesc[0].flags                   = 0;
subPassDesc[0].pipelineBindPoint       = VK_PIPELINE_BIND_POINT_GRAPHICS;
//subPassDesc[0].inputAttachmentCount    = 0;
//subPassDesc[0].pInputAttachments       = inputAttachRef.data();
subPassDesc[0].colorAttachmentCount    = colorAttachRef.size();
subPassDesc[0].pColorAttachments       = colorAttachRef.data();
//subPassDesc[0].pDepthStencilAttachment = nullptr;
//subPassDesc[0].pResolveAttachments     = nullptr;
//subPassDesc[0].preserveAttachmentCount = 0;
//subPassDesc[0].pPreserveAttachments    = nullptr;
/*
subPassDesc[1].flags                   = 0;
subPassDesc[1].pipelineBindPoint       = VK_PIPELINE_BIND_POINT_GRAPHICS;
subPassDesc[1].inputAttachmentCount    = 0;
subPassDesc[1].pInputAttachments       = nullptr;
subPassDesc[1].colorAttachmentCount    = 0;
subPassDesc[1].pColorAttachments       = nullptr;
subPassDesc[1].pDepthStencilAttachment = depthAttachRef.data();
subPassDesc[1].pResolveAttachments     = nullptr;
subPassDesc[1].preserveAttachmentCount = 0;
subPassDesc[1].pPreserveAttachments    = nullptr;
*/

TKLog("render pass format 0x%x

", format);

std::vector&lt;VkAttachmentDescription&gt; attachDesc(1);

attachDesc[0].flags             = 0;
attachDesc[0].format            = format;
attachDesc[0].loadOp            = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachDesc[0].storeOp           = VK_ATTACHMENT_STORE_OP_STORE;
attachDesc[0].stencilLoadOp     = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachDesc[0].stencilStoreOp    = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachDesc[0].initialLayout     = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
attachDesc[0].finalLayout       = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; 
attachDesc[0].samples           = VK_SAMPLE_COUNT_1_BIT; 
/*
attachDesc[1].flags             = 0;
attachDesc[1].format            = VK_FORMAT_D32_SFLOAT_S8_UINT;
attachDesc[1].loadOp            = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachDesc[1].storeOp           = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachDesc[1].samples           = VK_SAMPLE_COUNT_1_BIT;
attachDesc[1].initialLayout     = VK_IMAGE_LAYOUT_UNDEFINED;
attachDesc[1].finalLayout       = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; 
attachDesc[1].stencilLoadOp     = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachDesc[1].stencilStoreOp    = VK_ATTACHMENT_STORE_OP_STORE;
*/

VkSubpassDependency dependency;
dependency.dependencyFlags = 0;
dependency.srcSubpass = 0;
dependency.dstSubpass = 1;
dependency.srcStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
dependency.dstStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
dependency.srcAccessMask =
    VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
dependency.dstAccessMask =
    VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
    
VkRenderPassCreateInfo info;
info.sType           = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
info.pNext           = nullptr;
info.flags           = 0;
info.attachmentCount = attachDesc.size();
info.pAttachments    = attachDesc.data();

info.subpassCount    = subPassDesc.size();
info.pSubpasses      = subPassDesc.data();

info.dependencyCount = 0;
info.pDependencies   = nullptr;//&dependency;
int ret = vkCreateRenderPass(device, &info, nullptr, &m_renderPass);
if(ret != VK_SUCCESS){
    return false;
}
TKLog("init render pass success!

");
return true;

}
I’ve struggle with this question for several days, I cant’t find the reason.

The question is when I set assemble toplogy with VK_PRIMITIVE_TOPLOGY_LINE_LIST/STRIP, it run mormally,
but when I changed the assemble toplogy to VK_PRIMITIVE_TOPLOGY_TRIANGLE_LIST/FAN/STRIP, it display nothing.

I use GTX1070, the PC system is Ubuntu 18.04


#2

I’ve find the point. the point was in the VkPipeline create.

void TKPipeline::initRasterStateCreateInfo(){
m_rasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
m_rasterState.pNext = nullptr;
m_rasterState.flags = 0;
//m_rasterState.depthClampEnable = VK_FALSE;
//m_rasterState.rasterizerDiscardEnable = VK_FALSE;
m_rasterState.polygonMode = VK_POLYGON_MODE_FILL;
m_rasterState.cullMode = VK_CULL_MODE_NONE;
m_rasterState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
//m_rasterState.depthBiasEnable = VK_FALSE;
//m_rasterState.depthBiasConstantFactor = 0.0f;
//m_rasterState.depthBiasClamp = 0.0f;
//m_rasterState.depthBiasSlopeFactor = 0.0f;
m_rasterState.lineWidth = 1.0f;
}
when I set the CULL_MODE to VK_CULL_MODE_FRONT_BIT or others which are not VK_CULL_MODE_NONE, I can’t draw a solid triangle.
May be ther are some special properties I don’t konw about Nvidia GPU .