Recently while learning the Qt RHI graphics rendering framework I encountered a strange problem: QRhiGraphicsPipeline inexplicably returned false on create! During the time this problem appeared, I was debugging the fragment shader, specifically studying HDR display shaders, and frequently toggling Windows HDR on and off. At one point I thought it was a system issue, so I tried switching to SDR, but the error persisted.
Later, after spending some time reverting modifications, I finally isolated the cause…
First, note that the program framework was basically copied from the Qt official documentation example: https://doc.qt.io/qt-6/qtgui-rhiwindow-example.html. The error occurs at the following code location:
m_colorTriSrb.reset(m_rhi->newShaderResourceBindings());
static const QRhiShaderResourceBinding::StageFlags visibility =
QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage;
m_colorTriSrb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, visibility, m_ubuf.get())
});
m_colorTriSrb->create();
m_colorPipeline.reset(m_rhi->newGraphicsPipeline());
// Enable depth testing; not quite needed for a simple triangle, but we
// have a depth-stencil buffer so why not.
m_colorPipeline->setDepthTest(true);
m_colorPipeline->setDepthWrite(true);
// Blend factors default to One, OneOneMinusSrcAlpha, which is convenient.
QRhiGraphicsPipeline::TargetBlend premulAlphaBlend;
premulAlphaBlend.enable = true;
m_colorPipeline->setTargetBlends({ premulAlphaBlend });
m_colorPipeline->setShaderStages({
{ QRhiShaderStage::Vertex, getShader(QLatin1String(":/color.vert.qsb")) },
{ QRhiShaderStage::Fragment, getShader(QLatin1String(":/color.frag.qsb")) }
});
QRhiVertexInputLayout inputLayout;
inputLayout.setBindings({
{ 5 * sizeof(float) }
});
inputLayout.setAttributes({
{ 0, 0, QRhiVertexInputAttribute::Float2, 0 },
{ 0, 1, QRhiVertexInputAttribute::Float3, 2 * sizeof(float) }
});
m_colorPipeline->setVertexInputLayout(inputLayout);
m_colorPipeline->setShaderResourceBindings(m_colorTriSrb.get());
m_colorPipeline->setRenderPassDescriptor(m_rp.get());
m_colorPipeline->create();
The failure happens at the final create. You can see that this pipeline also includes shader setup, and the problem was in the shader. Because I was constantly modifying the shader, at one point while referencing information provided by AI, I didn’t copy completely and ended up with this shader code:
void render_10bit_hdr()
{
vec3 rgb = decode_10bit_rgb_from_rg8();
vec3 color;
if (ubuf.color_transfer == 18)
{
//color = hlgToLinear(rgb);
color = BT2020toBT709(color);
//color *= 2.5375 * 4.5;
}
else
{
color = PQToScRGB(rgb);
color = BT2020toBT709(color);
color *= 125.0;
}
//color = tonemapping(color);
//color = hableMap(color);
//color = LineartoGamma(color);
fragColor = vec4(color, 1);
}
color = BT2020toBT709(color); For debugging, I temporarily commented out the line above, which meant that color was never initialized (likely the underlying reason). Syntactically, this shader code had no issues, and Qt’s qsb compilation produced no errors. But as long as the shader was compiled in this state, m_colorPipeline.create would return false!
博主友情提示:
如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。