61 #include "../shared/examplefw.h"
64 static float vertexData[] =
66 -0.5f, 0.5f, 0.0f, 0.0f,
67 -0.5f, -0.5f, 0.0f, 1.0f,
68 0.5f, -0.5f, 1.0f, 1.0f,
69 0.5f, 0.5f, 1.0f, 0.0f
77 static const int MAX_MIP_LEVELS = 20;
109 const int w =
d.texRgba->pixelSize().width() / 16;
110 const int h =
d.texRgba->pixelSize().height() / 16;
112 cb->beginComputePass();
114 cb->setComputePipeline(
d.computePipeline_load);
115 cb->setShaderResources();
116 cb->dispatch(
w,
h, 1);
118 cb->setComputePipeline(
d.computePipeline_prefilter);
121 const int mipW =
d.prefilterNumWorkGroups[
i][0];
122 const int mipH =
d.prefilterNumWorkGroups[
i][1];
124 cb->setShaderResources(
d.computeBindings_prefilter[
i], 1, &dynamicOffset);
125 cb->dispatch(mipW, mipH, 1);
128 cb->endComputePass();
134 qFatal(
"Compute is not supported");
137 qFatal(
"RGBA16F texture format is not supported");
149 d.releasePool <<
d.texRgba;
151 d.initialUpdates->uploadTexture(
d.texRgba,
image);
157 d.releasePool <<
d.texFloat16;
158 d.texFloat16->create();
163 d.computeUBuf_load->create();
164 d.releasePool <<
d.computeUBuf_load;
167 d.initialUpdates->updateDynamicBuffer(
d.computeUBuf_load, 0, 12, numWorkGroups);
170 d.computeBindings_load->setBindings({
175 d.computeBindings_load->create();
176 d.releasePool <<
d.computeBindings_load;
179 d.computePipeline_load->setShaderResourceBindings(
d.computeBindings_load);
181 d.computePipeline_load->create();
182 d.releasePool <<
d.computePipeline_load;
186 d.computeUBuf_prefilter->create();
187 d.releasePool <<
d.computeUBuf_prefilter;
189 int mipW =
image.width() >> 1;
190 int mipH =
image.height() >> 1;
193 d.prefilterNumWorkGroups[
i][0] =
quint32(mipW);
194 d.prefilterNumWorkGroups[
i][1] =
quint32(mipH);
195 d.prefilterNumWorkGroups[
i][2] = 0;
196 d.initialUpdates->updateDynamicBuffer(
d.computeUBuf_prefilter,
d.prefilterUBufElemSize *
i, 12,
d.prefilterNumWorkGroups[
i]);
197 mipW = mipW > 2 ? mipW >> 1 : 1;
198 mipH = mipH > 2 ? mipH >> 1 : 1;
201 d.computeBindings_prefilter[
i]->setBindings({
206 d.computeBindings_prefilter[
i]->create();
207 d.releasePool <<
d.computeBindings_prefilter[
i];
211 d.computePipeline_prefilter->setShaderResourceBindings(
d.computeBindings_prefilter[0]);
213 d.computePipeline_prefilter->create();
214 d.releasePool <<
d.computePipeline_prefilter;
220 d.releasePool <<
d.vbuf;
224 d.releasePool <<
d.ibuf;
228 d.releasePool <<
d.ubuf;
233 d.releasePool <<
d.sampler;
237 d.releasePool <<
d.srb;
245 d.releasePool <<
d.ps;
246 d.ps->setShaderStages({
252 { 4 *
sizeof(float) }
258 d.ps->setVertexInputLayout(inputLayout);
259 d.ps->setShaderResourceBindings(
d.srb);
260 d.ps->setRenderPassDescriptor(
m_rp);
263 d.initialUpdates->uploadStaticBuffer(
d.vbuf, vertexData);
264 d.initialUpdates->uploadStaticBuffer(
d.ibuf, indexData);
267 d.initialUpdates->updateDynamicBuffer(
d.ubuf, 64, 4, &flip);
273 d.releasePool.clear();
280 if (
d.initialUpdates) {
281 u->merge(
d.initialUpdates);
282 d.initialUpdates->release();
283 d.initialUpdates =
nullptr;
288 d.scale +=
d.scale_dir * 0.01f;
291 u->updateDynamicBuffer(
d.ubuf, 0, 64, mvp.
constData());
293 cb->resourceUpdate(
u);
298 if (!
d.computeDone) {
300 d.computeDone =
true;
303 const QSize outputSizeInPixels =
m_sc->currentPixelSize();
305 cb->setGraphicsPipeline(
d.ps);
306 cb->setViewport({ 0, 0, float(outputSizeInPixels.
width()), float(outputSizeInPixels.
height()) });
307 cb->setShaderResources();
small capitals from c petite p scientific f u
small capitals from c petite p scientific i
[1]
The QImage class provides a hardware-independent image representation that allows direct access to th...
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void scale(const QVector3D &vector)
const float * constData() const
QPair< QRhiBuffer *, quint32 > VertexInput
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags={}) const
int ubufAligned(int v) const
bool isFeatureSupported(QRhi::Feature feature) const
QRhiShaderResourceBindings * newShaderResourceBindings()
QRhiBuffer * newBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
QRhiComputePipeline * newComputePipeline()
QRhiSampler * newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode addressU, QRhiSampler::AddressMode addressV, QRhiSampler::AddressMode addressW=QRhiSampler::Repeat)
QRhiGraphicsPipeline * newGraphicsPipeline()
int mipLevelsForSize(const QSize &size) const
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, int size)
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
static QRhiShaderResourceBinding imageLoad(int binding, StageFlags stage, QRhiTexture *tex, int level)
static QRhiShaderResourceBinding imageStore(int binding, StageFlags stage, QRhiTexture *tex, int level)
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
The QSize class defines the size of a two-dimensional object using integer point precision.
constexpr int height() const noexcept
constexpr int width() const noexcept
std::unique_ptr< QRhiSwapChain > m_sc
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
virtual void customRender()
virtual void customInit()
qDeleteAll(list.begin(), list.end())
QShader getShader(const QString &name)
quint32 prefilterNumWorkGroups[MAX_MIP_LEVELS][3]
QRhiBuffer * computeUBuf_prefilter
QList< QRhiResource * > releasePool
void recordUploadThenFilterFloat16TextureWithCompute(QRhiCommandBuffer *cb)
QRhiComputePipeline * computePipeline_load
QRhiShaderResourceBindings * computeBindings_prefilter[MAX_MIP_LEVELS]
QRhiComputePipeline * computePipeline_prefilter
QRhiShaderResourceBindings * srb
QRhiBuffer * computeUBuf_load
QRhiShaderResourceBindings * computeBindings_load
QRhiGraphicsPipeline * ps
int prefilterUBufElemSize
QRhiResourceUpdateBatch * initialUpdates
std::pair< T1, T2 > QPair
bool qFuzzyIsNull(qfloat16 f) noexcept
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLenum GLenum GLenum scale
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)