76 QRhiSampler* m_sampler{};
81 QRhi& rhi,
const RenderState& state, QRhiTexture* inputRGBA,
int width,
82 int height,
const QString& colorConversion = colorMatrixOut())
override
87 m_sampler = rhi.newSampler(
88 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
89 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
96 m_yTexture = rhi.newTexture(
97 QRhiTexture::R8, QSize{width, height}, 1,
98 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
101 m_yRT = rhi.newTextureRenderTarget({m_yTexture});
102 m_yRP = m_yRT->newCompatibleRenderPassDescriptor();
103 m_yRT->setRenderPassDescriptor(m_yRP);
106 m_ySRB = rhi.newShaderResourceBindings();
107 m_ySRB->setBindings({
108 QRhiShaderResourceBinding::sampledTexture(
109 3, QRhiShaderResourceBinding::FragmentStage, inputRGBA, m_sampler),
114 state, vertSrc, QString::fromLatin1(y_frag).arg(colorConversion));
115 m_yPipeline = rhi.newGraphicsPipeline();
116 m_yPipeline->setShaderStages({
117 {QRhiShaderStage::Vertex, vs},
118 {QRhiShaderStage::Fragment, fs},
120 m_yPipeline->setVertexInputLayout({});
121 m_yPipeline->setShaderResourceBindings(m_ySRB);
122 m_yPipeline->setRenderPassDescriptor(m_yRP);
123 m_yPipeline->create();
128 m_uvTexture = rhi.newTexture(
129 QRhiTexture::RG8, QSize{width / 2, height / 2}, 1,
130 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
131 m_uvTexture->create();
133 m_uvRT = rhi.newTextureRenderTarget({m_uvTexture});
134 m_uvRP = m_uvRT->newCompatibleRenderPassDescriptor();
135 m_uvRT->setRenderPassDescriptor(m_uvRP);
138 m_uvSRB = rhi.newShaderResourceBindings();
139 m_uvSRB->setBindings({
140 QRhiShaderResourceBinding::sampledTexture(
141 3, QRhiShaderResourceBinding::FragmentStage, inputRGBA, m_sampler),
146 =
makeShaders(state, vertSrc, QString::fromLatin1(uv_frag).arg(colorConversion));
147 m_uvPipeline = rhi.newGraphicsPipeline();
148 m_uvPipeline->setShaderStages({
149 {QRhiShaderStage::Vertex, vs},
150 {QRhiShaderStage::Fragment, fs},
153 m_uvPipeline->setShaderResourceBindings(m_uvSRB);
154 m_uvPipeline->setRenderPassDescriptor(m_uvRP);
155 m_uvPipeline->create();
159 void exec(QRhi& rhi, QRhiCommandBuffer& cb)
override
162 cb.beginPass(m_yRT, Qt::black, {1.0f, 0});
163 cb.setGraphicsPipeline(m_yPipeline);
164 cb.setShaderResources(m_ySRB);
165 cb.setViewport(QRhiViewport(0, 0, m_width, m_height));
168 auto* yReadbackBatch = rhi.nextResourceUpdateBatch();
169 yReadbackBatch->readBackTexture(QRhiReadbackDescription{m_yTexture}, &m_yReadback);
170 cb.endPass(yReadbackBatch);
173 cb.beginPass(m_uvRT, Qt::black, {1.0f, 0});
174 cb.setGraphicsPipeline(m_uvPipeline);
175 cb.setShaderResources(m_uvSRB);
176 cb.setViewport(QRhiViewport(0, 0, m_width / 2, m_height / 2));