109 QRhiSampler* m_sampler{};
114 QRhi& rhi,
const RenderState& state, QRhiTexture* inputRGBA,
int width,
115 int height,
const QString& colorConversion)
override
120 m_sampler = rhi.newSampler(
121 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
122 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
129 m_yTexture = rhi.newTexture(
130 QRhiTexture::R8, QSize{width, height}, 1,
131 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
132 m_yTexture->create();
134 m_yRT = rhi.newTextureRenderTarget({m_yTexture});
135 m_yRP = m_yRT->newCompatibleRenderPassDescriptor();
136 m_yRT->setRenderPassDescriptor(m_yRP);
139 m_ySRB = rhi.newShaderResourceBindings();
140 m_ySRB->setBindings({
141 QRhiShaderResourceBinding::sampledTexture(
142 3, QRhiShaderResourceBinding::FragmentStage, inputRGBA, m_sampler),
147 state, vertSrc, QString::fromLatin1(y_frag).arg(colorConversion));
148 m_yPipeline = rhi.newGraphicsPipeline();
149 m_yPipeline->setShaderStages({
150 {QRhiShaderStage::Vertex, vs},
151 {QRhiShaderStage::Fragment, fs},
153 m_yPipeline->setVertexInputLayout({});
154 m_yPipeline->setShaderResourceBindings(m_ySRB);
155 m_yPipeline->setRenderPassDescriptor(m_yRP);
156 m_yPipeline->create();
162 m_uvTexture = rhi.newTexture(
163 QRhiTexture::R8, QSize{width, height / 2}, 1,
164 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
165 m_uvTexture->create();
167 m_uvRT = rhi.newTextureRenderTarget({m_uvTexture});
168 m_uvRP = m_uvRT->newCompatibleRenderPassDescriptor();
169 m_uvRT->setRenderPassDescriptor(m_uvRP);
172 m_uvSRB = rhi.newShaderResourceBindings();
173 m_uvSRB->setBindings({
174 QRhiShaderResourceBinding::sampledTexture(
175 3, QRhiShaderResourceBinding::FragmentStage, inputRGBA, m_sampler),
179 const char* uv_src = uv_frag;
181 =
makeShaders(state, vertSrc, QString::fromLatin1(uv_src).arg(colorConversion));
182 m_uvPipeline = rhi.newGraphicsPipeline();
183 m_uvPipeline->setShaderStages({
184 {QRhiShaderStage::Vertex, vs},
185 {QRhiShaderStage::Fragment, fs},
188 m_uvPipeline->setShaderResourceBindings(m_uvSRB);
189 m_uvPipeline->setRenderPassDescriptor(m_uvRP);
190 m_uvPipeline->create();
194 void exec(QRhi& rhi, QRhiCommandBuffer& cb)
override
197 cb.beginPass(m_yRT, Qt::black, {0.0f, 0});
198 cb.setGraphicsPipeline(m_yPipeline);
199 cb.setShaderResources(m_ySRB);
200 cb.setViewport(QRhiViewport(0, 0, m_width, m_height));
203 auto* yReadbackBatch = rhi.nextResourceUpdateBatch();
204 yReadbackBatch->readBackTexture(QRhiReadbackDescription{m_yTexture}, &m_yReadback);
205 cb.endPass(yReadbackBatch);
209 cb.beginPass(m_uvRT, Qt::black, {0.0f, 0});
210 cb.setGraphicsPipeline(m_uvPipeline);
211 cb.setShaderResources(m_uvSRB);
212 cb.setViewport(QRhiViewport(0, 0, m_width, m_height / 2));