Commit 12111880 authored by Laszlo Agocs's avatar Laszlo Agocs

Rename api pattern to new-build-release

While we are at it, rename QRhiRenderPass to QRhiRenderPassDescriptor
because renderpass on its own is a somwhat misleading naming.
parent 0d7b84af
......@@ -147,7 +147,7 @@ protected:
bool m_hasSwapChain = false;
QRhiSwapChain *m_sc = nullptr;
QRhiRenderBuffer *m_ds = nullptr;
QRhiRenderPass *m_rp = nullptr;
QRhiRenderPassDescriptor *m_rp = nullptr;
QRhiBuffer *m_vbuf = nullptr;
bool m_vbufReady = false;
QRhiBuffer *m_ubuf = nullptr;
......@@ -287,31 +287,31 @@ void Window::init()
// now onto the backend-independent init
m_sc = m_r->createSwapChain();
m_sc = m_r->newSwapChain();
// allow depth-stencil, although we do not actually enable depth test/write for the triangle
m_ds = m_r->createRenderBuffer(QRhiRenderBuffer::DepthStencil,
QSize(), // we don't know the size yet, this is fine
1,
QRhiRenderBuffer::ToBeUsedWithSwapChainOnly);
m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
QSize(), // we don't know the size yet, this is fine
1,
QRhiRenderBuffer::ToBeUsedWithSwapChainOnly);
m_sc->setWindow(this);
m_sc->setDepthStencil(m_ds);
m_rp = m_sc->buildCompatibleRenderPass();
m_sc->setRenderPass(m_rp);
m_rp = m_sc->newCompatibleRenderPassDescriptor();
m_sc->setRenderPassDescriptor(m_rp);
m_vbuf = m_r->createBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
m_vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
m_vbuf->build();
m_vbufReady = false;
m_ubuf = m_r->createBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68);
m_ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68);
m_ubuf->build();
m_srb = m_r->createShaderResourceBindings();
m_srb = m_r->newShaderResourceBindings();
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf)
});
m_srb->build();
m_ps = m_r->createGraphicsPipeline();
m_ps = m_r->newGraphicsPipeline();
QRhiGraphicsPipeline::TargetBlend premulAlphaBlend;
premulAlphaBlend.enable = true;
......@@ -340,7 +340,7 @@ void Window::init()
m_ps->setVertexInputLayout(inputLayout);
m_ps->setShaderResourceBindings(m_srb);
m_ps->setRenderPass(m_rp);
m_ps->setRenderPassDescriptor(m_rp);
m_ps->build();
}
......
......@@ -98,20 +98,20 @@ bool ExampleWindow::event(QEvent *e)
void ExampleWindow::init()
{
m_sc = m_r->createSwapChain();
m_sc = m_r->newSwapChain();
if (!m_sc)
return;
// allow depth-stencil, although we do not actually enable depth test/write for the triangle
m_ds = m_r->createRenderBuffer(QRhiRenderBuffer::DepthStencil,
QSize(), // we don't know the size yet, this is fine
m_sampleCount,
QRhiRenderBuffer::ToBeUsedWithSwapChainOnly);
m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
QSize(), // we don't know the size yet, this is fine
m_sampleCount,
QRhiRenderBuffer::ToBeUsedWithSwapChainOnly);
m_sc->setWindow(this);
m_sc->setDepthStencil(m_ds);
m_sc->setSampleCount(m_sampleCount);
m_scrp = m_sc->buildCompatibleRenderPass();
m_sc->setRenderPass(m_scrp);
m_scrp = m_sc->newCompatibleRenderPassDescriptor();
m_sc->setRenderPassDescriptor(m_scrp);
m_triRenderer.setRhi(m_r);
m_triRenderer.setSampleCount(m_sampleCount);
......
......@@ -84,7 +84,7 @@ protected:
bool m_hasSwapChain = false;
bool m_resizedSwapChain = false;
QRhiSwapChain *m_sc = nullptr;
QRhiRenderPass *m_scrp = nullptr;
QRhiRenderPassDescriptor *m_scrp = nullptr;
QRhiRenderBuffer *m_ds = nullptr;
TriangleRenderer m_triRenderer;
......
......@@ -70,19 +70,19 @@ static quint16 indexData[] =
0, 1, 2, 0, 2, 3
};
void QuadRenderer::initResources(QRhiRenderPass *)
void QuadRenderer::initResources(QRhiRenderPassDescriptor *)
{
m_vbuf = m_r->createBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
m_vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
m_vbuf->build();
m_vbufReady = false;
m_ibuf = m_r->createBuffer(QRhiBuffer::Immutable, QRhiBuffer::IndexBuffer, sizeof(indexData));
m_ibuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::IndexBuffer, sizeof(indexData));
m_ibuf->build();
m_ubuf = m_r->createBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68);
m_ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68);
m_ubuf->build();
m_srb = m_r->createShaderResourceBindings();
m_srb = m_r->newShaderResourceBindings();
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf)
});
......
......@@ -60,7 +60,7 @@ public:
void setSampleCount(int samples) { m_sampleCount = samples; }
int sampleCount() const { return m_sampleCount; }
void setTranslation(const QVector3D &v) { m_translation = v; }
void initResources(QRhiRenderPass *rp);
void initResources(QRhiRenderPassDescriptor *rp);
void releaseResources();
void setPipeline(QRhiGraphicsPipeline *ps);
void resize(const QSize &pixelSize);
......
......@@ -65,34 +65,34 @@ static QBakedShader getShader(const QString &name)
return QBakedShader();
}
void TexturedCubeRenderer::initResources(QRhiRenderPass *rp)
void TexturedCubeRenderer::initResources(QRhiRenderPassDescriptor *rp)
{
m_vbuf = m_r->createBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube));
m_vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube));
m_vbuf->build();
m_vbufReady = false;
m_ubuf = m_r->createBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4);
m_ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4);
m_ubuf->build();
m_image = QImage(QLatin1String(":/qt256.png")).convertToFormat(QImage::Format_RGBA8888);
QRhiTexture::Flags texFlags = 0;
if (MIPMAP)
texFlags |= QRhiTexture::MipMapped;
m_tex = m_r->createTexture(QRhiTexture::RGBA8, QSize(m_image.width(), m_image.height()), texFlags);
m_tex = m_r->newTexture(QRhiTexture::RGBA8, QSize(m_image.width(), m_image.height()), texFlags);
m_tex->build();
m_sampler = m_r->createSampler(QRhiSampler::Linear, QRhiSampler::Linear, MIPMAP ? QRhiSampler::Linear : QRhiSampler::None,
QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
m_sampler = m_r->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, MIPMAP ? QRhiSampler::Linear : QRhiSampler::None,
QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
m_sampler->build();
m_srb = m_r->createShaderResourceBindings();
m_srb = m_r->newShaderResourceBindings();
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf),
QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, m_tex, m_sampler)
});
m_srb->build();
m_ps = m_r->createGraphicsPipeline();
m_ps = m_r->newGraphicsPipeline();
m_ps->setDepthTest(true);
m_ps->setDepthWrite(true);
......@@ -124,7 +124,7 @@ void TexturedCubeRenderer::initResources(QRhiRenderPass *rp)
m_ps->setVertexInputLayout(inputLayout);
m_ps->setShaderResourceBindings(m_srb);
m_ps->setRenderPass(rp);
m_ps->setRenderPassDescriptor(rp);
m_ps->build();
}
......
......@@ -59,7 +59,7 @@ public:
void setRhi(QRhi *r) { m_r = r; }
void setSampleCount(int samples) { m_sampleCount = samples; }
void setTranslation(const QVector3D &v) { m_translation = v; }
void initResources(QRhiRenderPass *rp);
void initResources(QRhiRenderPassDescriptor *rp);
void releaseResources();
void resize(const QSize &pixelSize);
void queueResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates);
......
......@@ -72,13 +72,13 @@ static QBakedShader getShader(const QString &name)
static const QSize OFFSCREEN_SIZE(512, 512);
void TriangleOnCubeRenderer::initResources(QRhiRenderPass *rp)
void TriangleOnCubeRenderer::initResources(QRhiRenderPassDescriptor *rp)
{
m_vbuf = m_r->createBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube));
m_vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube));
m_vbuf->build();
m_vbufReady = false;
m_ubuf = m_r->createBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4);
m_ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4);
m_ubuf->build();
if (IMAGE_UNDER_OFFSCREEN_RENDERING) {
......@@ -87,25 +87,25 @@ void TriangleOnCubeRenderer::initResources(QRhiRenderPass *rp)
m_image = m_image.mirrored(); // just cause we'll flip texcoord Y when y up so accomodate our static background image as well
}
m_tex = m_r->createTexture(QRhiTexture::RGBA8, OFFSCREEN_SIZE, QRhiTexture::RenderTarget);
m_tex = m_r->newTexture(QRhiTexture::RGBA8, OFFSCREEN_SIZE, QRhiTexture::RenderTarget);
m_tex->build();
if (MRT) {
m_tex2 = m_r->createTexture(QRhiTexture::RGBA8, OFFSCREEN_SIZE, QRhiTexture::RenderTarget);
m_tex2 = m_r->newTexture(QRhiTexture::RGBA8, OFFSCREEN_SIZE, QRhiTexture::RenderTarget);
m_tex2->build();
}
m_sampler = m_r->createSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
m_sampler = m_r->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
m_sampler->build();
m_srb = m_r->createShaderResourceBindings();
m_srb = m_r->newShaderResourceBindings();
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf),
QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, m_tex, m_sampler)
});
m_srb->build();
m_ps = m_r->createGraphicsPipeline();
m_ps = m_r->newGraphicsPipeline();
m_ps->setDepthTest(true);
m_ps->setDepthWrite(true);
......@@ -137,13 +137,13 @@ void TriangleOnCubeRenderer::initResources(QRhiRenderPass *rp)
m_ps->setVertexInputLayout(inputLayout);
m_ps->setShaderResourceBindings(m_srb);
m_ps->setRenderPass(rp);
m_ps->setRenderPassDescriptor(rp);
m_ps->build();
if (DEPTH_TEXTURE) {
m_offscreenTriangle.setDepthWrite(true);
m_depthTex = m_r->createTexture(QRhiTexture::D32, OFFSCREEN_SIZE, QRhiTexture::RenderTarget);
m_depthTex = m_r->newTexture(QRhiTexture::D32, OFFSCREEN_SIZE, QRhiTexture::RenderTarget);
m_depthTex->build();
}
......@@ -152,18 +152,18 @@ void TriangleOnCubeRenderer::initResources(QRhiRenderPass *rp)
rtFlags |= QRhiTextureRenderTarget::PreserveColorContents;
if (DEPTH_TEXTURE) {
m_rt = m_r->createTextureRenderTarget({ nullptr, m_depthTex }, rtFlags);
m_rt = m_r->newTextureRenderTarget({ nullptr, m_depthTex }, rtFlags);
} else {
QRhiTextureRenderTargetDescription desc { m_tex };
if (MRT) {
m_offscreenTriangle.setColorAttCount(2);
desc.colorAttachments.append(m_tex2);
}
m_rt = m_r->createTextureRenderTarget(desc, rtFlags);
m_rt = m_r->newTextureRenderTarget(desc, rtFlags);
}
m_rp = m_rt->buildCompatibleRenderPass();
m_rt->setRenderPass(m_rp);
m_rp = m_rt->newCompatibleRenderPassDescriptor();
m_rt->setRenderPassDescriptor(m_rp);
m_rt->build();
......
......@@ -59,7 +59,7 @@ public:
void setRhi(QRhi *r) { m_r = r; }
void setSampleCount(int samples) { m_sampleCount = samples; }
void setTranslation(const QVector3D &v) { m_translation = v; }
void initResources(QRhiRenderPass *rp);
void initResources(QRhiRenderPassDescriptor *rp);
void releaseResources();
void resize(const QSize &pixelSize);
void queueResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates);
......@@ -77,7 +77,7 @@ private:
QRhiTexture *m_depthTex = nullptr;
QRhiSampler *m_sampler = nullptr;
QRhiTextureRenderTarget *m_rt = nullptr;
QRhiRenderPass *m_rp = nullptr;
QRhiRenderPassDescriptor *m_rp = nullptr;
QRhiShaderResourceBindings *m_srb = nullptr;
QRhiGraphicsPipeline *m_ps = nullptr;
......
......@@ -69,26 +69,26 @@ static QBakedShader getShader(const QString &name)
return QBakedShader();
}
void TriangleRenderer::initResources(QRhiRenderPass *rp)
void TriangleRenderer::initResources(QRhiRenderPassDescriptor *rp)
{
#ifdef VBUF_IS_DYNAMIC
m_vbuf = m_r->createBuffer(QRhiBuffer::Dynamic, QRhiBuffer::VertexBuffer, sizeof(vertexData));
m_vbuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::VertexBuffer, sizeof(vertexData));
#else
m_vbuf = m_r->createBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
m_vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertexData));
#endif
m_vbuf->build();
m_vbufReady = false;
m_ubuf = m_r->createBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68);
m_ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68);
m_ubuf->build();
m_srb = m_r->createShaderResourceBindings();
m_srb = m_r->newShaderResourceBindings();
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf)
});
m_srb->build();
m_ps = m_r->createGraphicsPipeline();
m_ps = m_r->newGraphicsPipeline();
QRhiGraphicsPipeline::TargetBlend premulAlphaBlend; // convenient defaults...
premulAlphaBlend.enable = true;
......@@ -125,7 +125,7 @@ void TriangleRenderer::initResources(QRhiRenderPass *rp)
m_ps->setVertexInputLayout(inputLayout);
m_ps->setShaderResourceBindings(m_srb);
m_ps->setRenderPass(rp);
m_ps->setRenderPassDescriptor(rp);
m_ps->build();
}
......
......@@ -64,7 +64,7 @@ public:
void setDepthWrite(bool enable) { m_depthWrite = enable; }
void setColorAttCount(int count) { m_colorAttCount = count; }
QRhiGraphicsPipeline *pipeline() const { return m_ps; }
void initResources(QRhiRenderPass *rp);
void initResources(QRhiRenderPassDescriptor *rp);
void releaseResources();
void resize(const QSize &pixelSize);
void queueResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates);
......
......@@ -75,7 +75,7 @@ void Renderer::initResources()
m_triRenderer.setSampleCount(SAMPLES);
m_initPending = true;
m_sc = m_r->createSwapChain();
m_sc = m_r->newSwapChain();
}
void Renderer::initSwapChainResources()
......@@ -86,7 +86,7 @@ void Renderer::initSwapChainResources()
if (m_initPending) {
m_initPending = false;
// had to defer init until we can query the imported renderpass
m_triRenderer.initResources(m_sc->renderPass());
m_triRenderer.initResources(m_sc->renderPassDescriptor());
}
m_triRenderer.resize(m_sc->effectiveSizeInPixels());
}
......
......@@ -93,7 +93,7 @@ QRhiSampler::QRhiSampler(QRhiImplementation *rhi,
{
}
QRhiRenderPass::QRhiRenderPass(QRhiImplementation *rhi)
QRhiRenderPassDescriptor::QRhiRenderPassDescriptor(QRhiImplementation *rhi)
: QRhiResource(rhi)
{
}
......@@ -344,52 +344,52 @@ QMatrix4x4 QRhi::clipSpaceCorrMatrix() const
return d->clipSpaceCorrMatrix();
}
QRhiGraphicsPipeline *QRhi::createGraphicsPipeline()
QRhiGraphicsPipeline *QRhi::newGraphicsPipeline()
{
return d->createGraphicsPipeline();
}
QRhiShaderResourceBindings *QRhi::createShaderResourceBindings()
QRhiShaderResourceBindings *QRhi::newShaderResourceBindings()
{
return d->createShaderResourceBindings();
}
QRhiBuffer *QRhi::createBuffer(QRhiBuffer::Type type,
QRhiBuffer::UsageFlags usage,
int size)
QRhiBuffer *QRhi::newBuffer(QRhiBuffer::Type type,
QRhiBuffer::UsageFlags usage,
int size)
{
return d->createBuffer(type, usage, size);
}
QRhiRenderBuffer *QRhi::createRenderBuffer(QRhiRenderBuffer::Type type,
const QSize &pixelSize,
int sampleCount,
QRhiRenderBuffer::Hints hints)
QRhiRenderBuffer *QRhi::newRenderBuffer(QRhiRenderBuffer::Type type,
const QSize &pixelSize,
int sampleCount,
QRhiRenderBuffer::Hints hints)
{
return d->createRenderBuffer(type, pixelSize, sampleCount, hints);
}
QRhiTexture *QRhi::createTexture(QRhiTexture::Format format,
const QSize &pixelSize,
QRhiTexture::Flags flags)
QRhiTexture *QRhi::newTexture(QRhiTexture::Format format,
const QSize &pixelSize,
QRhiTexture::Flags flags)
{
return d->createTexture(format, pixelSize, flags);
}
QRhiSampler *QRhi::createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
QRhiSampler::Filter mipmapMode,
QRhiSampler:: AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w)
QRhiSampler *QRhi::newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
QRhiSampler::Filter mipmapMode,
QRhiSampler:: AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w)
{
return d->createSampler(magFilter, minFilter, mipmapMode, u, v, w);
}
QRhiTextureRenderTarget *QRhi::createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
QRhiTextureRenderTarget::Flags flags)
QRhiTextureRenderTarget *QRhi::newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
QRhiTextureRenderTarget::Flags flags)
{
return d->createTextureRenderTarget(desc, flags);
}
QRhiSwapChain *QRhi::createSwapChain()
QRhiSwapChain *QRhi::newSwapChain()
{
return d->createSwapChain();
}
......
......@@ -56,6 +56,22 @@ class QRhiTexture;
class QRhiSampler;
struct QRhiResourceUpdateBatchPrivate;
// C++ object ownership rules:
// 1. new*() and create() return value owned by the caller.
// 2. next*() return value not owned by the caller.
// 3. Passing a pointer via set*() or the structs does not transfer ownership.
// 4. release() does not destroy the C++ object. releaseAndDestroy() does, and is equivalent to o->release(); delete o;
//
// Graphics resource ownership rules:
// 1. new*() does not create underlying graphics resources. build() does.
// 2. release() schedules graphics resources for destruction. The C++ object is reusable immediately via build(), or can be destroyed.
// 3. build() on an already built object calls release() implicitly. Except swapchains. (buildOrResize - special semantics)
// 4. newCompatible*() implicitly "builds". (no build() for QRhiRenderPassDescriptor)
// 5. Ownership of resources imported via QRhi*InitParams is not taken.
//
// Other:
// 1. QRhiResourceUpdateBatch manages no graphics resources underneath. beginPass() implicitly calls release() on the batch.
struct Q_RHI_EXPORT QRhiColorClearValue
{
QRhiColorClearValue() : rgba(0, 0, 0, 1) { }
......@@ -441,10 +457,10 @@ protected:
void *m_reserved;
};
class Q_RHI_EXPORT QRhiRenderPass : public QRhiResource
class Q_RHI_EXPORT QRhiRenderPassDescriptor : public QRhiResource
{
protected:
QRhiRenderPass(QRhiImplementation *rhi);
QRhiRenderPassDescriptor(QRhiImplementation *rhi);
void *m_reserved;
};
......@@ -459,12 +475,12 @@ public:
virtual Type type() const = 0;
virtual QSize sizeInPixels() const = 0;
QRhiRenderPass *renderPass() const { return m_renderPass; }
void setRenderPass(QRhiRenderPass *renderPass) { m_renderPass = renderPass; }
QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
protected:
QRhiRenderTarget(QRhiImplementation *rhi);
QRhiRenderPass *m_renderPass = nullptr;
QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
void *m_reserved;
};
......@@ -483,8 +499,8 @@ public:
void setFlags(Flags f) { m_flags = f; }
// To be called before build() with description and flags set.
// Note setRenderPass() in the base class, that must still be called afterwards.
virtual QRhiRenderPass *buildCompatibleRenderPass() = 0;
// Note setRenderPassDescriptor() in the base class, that must still be called afterwards.
virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
// as usual, textures in desc must be built before calling build() on the rt
virtual bool build() = 0;
......@@ -669,8 +685,8 @@ public:
QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; }
void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
QRhiRenderPass *renderPass() const { return m_renderPass; }
void setRenderPass(QRhiRenderPass *pass) { m_renderPass = pass; }
QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
virtual bool build() = 0;
......@@ -693,7 +709,7 @@ protected:
QVector<QRhiGraphicsShaderStage> m_shaderStages;
QRhiVertexInputLayout m_vertexInputLayout;
QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; // must be built by the time ps' build() is called
QRhiRenderPass *m_renderPass = nullptr;
QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
void *m_reserved;
};
......@@ -732,8 +748,8 @@ public:
int sampleCount() const { return m_sampleCount; }
void setSampleCount(int samples) { m_sampleCount = samples; }
QRhiRenderPass *renderPass() const { return m_renderPass; }
void setRenderPass(QRhiRenderPass *renderPass) { m_renderPass = renderPass; }
QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
// Alternatively, integrate with an existing swapchain, f.ex.
// QVulkanWindow. Other settings have no effect when this is set.
......@@ -752,15 +768,15 @@ public:
// To be called before build() with relevant parameters like depthStencil and sampleCount set.
// (things like the window or the size of depthStencil are irrelevant here)
// Note setRenderPass(), that must still be called afterwards (but before buildOrResize).
virtual QRhiRenderPass *buildCompatibleRenderPass() = 0;
// As an exception to the typical build+release pattern, note that
// buildOrResize - buildOrResize is not the same as buildOrResize - release
// - buildOrResize. A swapchain is often able to, depending on the
// underlying APIs, accomodate changed output sizes in a manner that is
// more efficient than a full destroy - create. So use the former when a
// window is resized.
// Note setRenderPassDescriptor(), that must still be called afterwards (but before buildOrResize).
virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
// As the name suggests, this is slightly different from the typical
// build+release pattern: buildOrResize - buildOrResize is not the same as
// buildOrResize - release - buildOrResize. A swapchain is often able to,
// depending on the underlying APIs, accomodate changed output sizes in a
// manner that is more efficient than a full destroy - create. So use the
// former when a window is resized.
virtual bool buildOrResize() = 0;
protected:
......@@ -770,7 +786,7 @@ protected:
SurfaceImportFlags m_flags;
QRhiRenderBuffer *m_depthStencil = nullptr;
int m_sampleCount = 1;
QRhiRenderPass *m_renderPass = nullptr;
QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
QObject *m_target = nullptr;
void *m_reserved;
};
......@@ -849,8 +865,8 @@ public:
when invoked on an object with valid resources underneath.
*/
QRhiGraphicsPipeline *createGraphicsPipeline();
QRhiShaderResourceBindings *createShaderResourceBindings();
QRhiGraphicsPipeline *newGraphicsPipeline();
QRhiShaderResourceBindings *newShaderResourceBindings();
// Buffers are immutable like other resources but the underlying data can
// change. (its size cannot) Having multiple frames in flight is handled
......@@ -859,30 +875,30 @@ public:
// buffers. For best performance, static buffers may be copied to device
// local (not necessarily host visible) memory via a staging (host visible)
// buffer. Hence separate update-dynamic and upload-static operations.
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
QRhiBuffer::UsageFlags usage,
int size);
QRhiBuffer *newBuffer(QRhiBuffer::Type type,
QRhiBuffer::UsageFlags usage,
int size);
// To be used for depth-stencil when no access is needed afterwards.
// Transient image, backed by lazily allocated memory (on Vulkan at least,
// ideal for tiled GPUs). May also be a dummy internally depending on the
// backend and the hints (OpenGL, where the winsys interface provides the
// depth-stencil buffer via the window surface).
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
const QSize &pixelSize,
int sampleCount = 1,
QRhiRenderBuffer::Hints hints = QRhiRenderBuffer::Hints());
QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
const QSize &pixelSize,
int sampleCount = 1,
QRhiRenderBuffer::Hints hints = QRhiRenderBuffer::Hints());
QRhiTexture *createTexture(QRhiTexture::Format format,
const QSize &pixelSize,
QRhiTexture::Flags flags = QRhiTexture::Flags());
QRhiTexture *newTexture(QRhiTexture::Format format,
const QSize &pixelSize,
QRhiTexture::Flags flags = QRhiTexture::Flags());
QRhiSampler *createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
QRhiSampler::Filter mipmapMode,
QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w = QRhiSampler::ClampToEdge);
QRhiSampler *newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
QRhiSampler::Filter mipmapMode,
QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w = QRhiSampler::ClampToEdge);
QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
QRhiTextureRenderTarget::Flags flags = QRhiTextureRenderTarget::Flags());
QRhiTextureRenderTarget *newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
QRhiTextureRenderTarget::Flags flags = QRhiTextureRenderTarget::Flags());
/*
Render to a QWindow (must be Vulkan/Metal/OpenGLSurface as appropriate):
......@@ -900,7 +916,7 @@ public:
Also works with a QVulkanWindow from startNextFrame(). Use the overload of build() in initSwapChainResources().
*/
QRhiSwapChain *createSwapChain();
QRhiSwapChain *newSwapChain();
FrameOpResult beginFrame(QRhiSwapChain *swapChain);
FrameOpResult endFrame(QRhiSwapChain *swapChain);
......
......@@ -1171,12 +1171,12 @@ bool QD3D11Sampler::build()
}
// dummy, no Vulkan-style RenderPass+Framebuffer concept here
QD3D11RenderPass::QD3D11RenderPass(QRhiImplementation *rhi)
: QRhiRenderPass(rhi)
QD3D11RenderPassDescriptor::QD3D11RenderPassDescriptor(QRhiImplementation *rhi)
: QRhiRenderPassDescriptor(rhi)
{
}
void QD3D11RenderPass::release()
void QD3D11RenderPassDescriptor::release()
{
// nothing to do here
}
......@@ -1231,9 +1231,9 @@ void QD3D11TextureRenderTarget::release()
}
}
QRhiRenderPass *QD3D11TextureRenderTarget::buildCompatibleRenderPass()
QRhiRenderPassDescriptor *QD3D11TextureRenderTarget::newCompatibleRenderPassDescriptor()
{
return new QD3D11RenderPass(rhi);
return new QD3D11RenderPassDescriptor(rhi);
}
bool QD3D11TextureRenderTarget::build()
......@@ -1301,7 +1301,7 @@ bool QD3D11TextureRenderTarget::build()
d.rtv[i] = i < d.colorAttCount ? rtv[i] : nullptr;
d.dsv = dsv;
d.rp = QRHI_RES(QD3D11RenderPass, m_renderPass);
d.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc);
return true;
}
......@@ -1818,9 +1818,9 @@ QSize QD3D11SwapChain::effectiveSizeInPixels() const
return pixelSize;
}
QRhiRenderPass *QD3D11SwapChain::buildCompatibleRenderPass()
QRhiRenderPassDescriptor *QD3D11SwapChain::newCompatibleRenderPassDescriptor()
{
return new QD3D11RenderPass(rhi);
return new QD3D11RenderPassDescriptor(rhi);
}
bool QD3D11SwapChain::buildOrResize()
......@@ -1903,7 +1903,7 @@ bool QD3D11SwapChain::buildOrResize()
ds = m_depthStencil ? QRHI_RES(QD3D11RenderBuffer, m_depthStencil) : nullptr;
QD3D11ReferenceRenderTarget *rtD = QRHI_RES(QD3D11ReferenceRenderTarget, &rt);