Commit 52c77e47 authored by Laszlo Agocs's avatar Laszlo Agocs

Clean up qrhi.h

parent 55b6fd85
......@@ -67,20 +67,20 @@ void QRhiResource::releaseAndDestroy()
QRhiBuffer::QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, int size_)
: QRhiResource(rhi),
type(type_), usage(usage_), size(size_)
m_type(type_), m_usage(usage_), m_size(size_)
{
}
QRhiRenderBuffer::QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_,
int sampleCount_, Hints hints_)
: QRhiResource(rhi),
type(type_), pixelSize(pixelSize_), sampleCount(sampleCount_), hints(hints_)
m_type(type_), m_pixelSize(pixelSize_), m_sampleCount(sampleCount_), m_hints(hints_)
{
}
QRhiTexture::QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, Flags flags_)
: QRhiResource(rhi),
format(format_), pixelSize(pixelSize_), flags(flags_)
m_format(format_), m_pixelSize(pixelSize_), m_flags(flags_)
{
}
......@@ -88,8 +88,8 @@ QRhiSampler::QRhiSampler(QRhiImplementation *rhi,
Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
AddressMode u_, AddressMode v_, AddressMode w_)
: QRhiResource(rhi),
magFilter(magFilter_), minFilter(minFilter_), mipmapMode(mipmapMode_),
addressU(u_), addressV(v_), addressW(w_)
m_magFilter(magFilter_), m_minFilter(minFilter_), m_mipmapMode(mipmapMode_),
m_addressU(u_), m_addressV(v_), m_addressW(w_)
{
}
......@@ -112,8 +112,8 @@ QRhiTextureRenderTarget::QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_,
Flags flags_)
: QRhiRenderTarget(rhi),
desc(desc_),
flags(flags_)
m_desc(desc_),
m_flags(flags_)
{
}
......@@ -122,10 +122,10 @@ QRhiShaderResourceBindings::QRhiShaderResourceBindings(QRhiImplementation *rhi)
{
}
QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniformBuffer(
QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
int binding_, StageFlags stage_, QRhiBuffer *buf_)
{
Binding b;
QRhiShaderResourceBinding b;
b.binding = binding_;
b.stage = stage_;
b.type = UniformBuffer;
......@@ -135,11 +135,11 @@ QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniform
return b;
}
QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniformBuffer(
QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
int binding_, StageFlags stage_, QRhiBuffer *buf_, int offset_, int size_)
{
Q_ASSERT(size_ > 0);
Binding b;
QRhiShaderResourceBinding b;
b.binding = binding_;
b.stage = stage_;
b.type = UniformBuffer;
......@@ -149,10 +149,10 @@ QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniform
return b;
}
QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::sampledTexture(
QRhiShaderResourceBinding QRhiShaderResourceBinding::sampledTexture(
int binding_, StageFlags stage_, QRhiTexture *tex_, QRhiSampler *sampler_)
{
Binding b;
QRhiShaderResourceBinding b;
b.binding = binding_;
b.stage = stage_;
b.type = SampledTexture;
......@@ -265,7 +265,7 @@ void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, const void *da
d->staticBufferUploads.append({ buf, data });
}
void QRhiResourceUpdateBatch::uploadTexture(QRhiTexture *tex, const TextureUploadDescription &desc)
void QRhiResourceUpdateBatch::uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
{
d->textureUploads.append({ tex, desc });
}
......
This diff is collapsed.
......@@ -130,7 +130,7 @@ struct QRhiResourceUpdateBatchPrivate
struct StaticBufferUpload {
StaticBufferUpload() { }
StaticBufferUpload(QRhiBuffer *buf_, const void *data_)
: buf(buf_), data(reinterpret_cast<const char *>(data_), buf_->size)
: buf(buf_), data(reinterpret_cast<const char *>(data_), buf_->size())
{ }
QRhiBuffer *buf = nullptr;
......@@ -139,12 +139,12 @@ struct QRhiResourceUpdateBatchPrivate
struct TextureUpload {
TextureUpload() { }
TextureUpload(QRhiTexture *tex_, const QRhiResourceUpdateBatch::TextureUploadDescription &desc_)
TextureUpload(QRhiTexture *tex_, const QRhiTextureUploadDescription &desc_)
: tex(tex_), desc(desc_)
{ }
QRhiTexture *tex = nullptr;
QRhiResourceUpdateBatch::TextureUploadDescription desc;
QRhiTextureUploadDescription desc;
};
QVector<DynamicBufferUpdate> dynamicBufferUpdates;
......
This diff is collapsed.
......@@ -60,6 +60,7 @@ struct QD3D11Buffer : public QRhiBuffer
QByteArray dynBuf;
bool hasPendingDynamicUpdates = false;
uint generation = 0;
friend class QRhiD3D11;
};
struct QD3D11RenderBuffer : public QRhiRenderBuffer
......@@ -71,6 +72,7 @@ struct QD3D11RenderBuffer : public QRhiRenderBuffer
ID3D11Texture2D *tex = nullptr;
ID3D11DepthStencilView *dsv = nullptr;
friend class QRhiD3D11;
};
struct QD3D11Texture : public QRhiTexture
......@@ -83,6 +85,7 @@ struct QD3D11Texture : public QRhiTexture
ID3D11ShaderResourceView *srv = nullptr;
uint mipLevelCount = 0;
uint generation = 0;
friend class QRhiD3D11;
};
struct QD3D11Sampler : public QRhiSampler
......@@ -94,6 +97,7 @@ struct QD3D11Sampler : public QRhiSampler
ID3D11SamplerState *samplerState = nullptr;
uint generation = 0;
friend class QRhiD3D11;
};
struct QD3D11RenderPass : public QRhiRenderPass
......@@ -140,6 +144,7 @@ struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget
ID3D11RenderTargetView *rtv[QD3D11RenderPass::MAX_COLOR_ATTACHMENTS];
bool ownsDsv = false;
ID3D11DepthStencilView *dsv = nullptr;
friend class QRhiD3D11;
};
template<typename T>
......@@ -187,7 +192,7 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings
void release() override;
bool build() override;
QVector<Binding> sortedBindings;
QVector<QRhiShaderResourceBinding> sortedBindings;
uint generation = 0;
// Keep track of the generation number of each referenced QRhi* to be able
......@@ -220,6 +225,8 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings
QD3D11BatchedBindings<ID3D11SamplerState *> fssamplers;
QD3D11BatchedBindings<ID3D11ShaderResourceView *> fsshaderresources;
friend class QRhiD3D11;
};
struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline
......@@ -236,6 +243,7 @@ struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline
D3D11_PRIMITIVE_TOPOLOGY d3dTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
ID3D11RasterizerState *rastState = nullptr;
uint generation = 0;
friend class QRhiD3D11;
};
struct QD3D11SwapChain;
......
This diff is collapsed.
......@@ -66,6 +66,7 @@ struct QGles2Buffer : public QRhiBuffer
int changeEnd;
};
ChangeRange ubufChangeRange;
friend class QRhiGles2;
};
struct QGles2RenderBuffer : public QRhiRenderBuffer
......@@ -76,6 +77,7 @@ struct QGles2RenderBuffer : public QRhiRenderBuffer
bool build() override;
GLuint renderbuffer = 0;
friend class QRhiGles2;
};
struct QGles2Texture : public QRhiTexture
......@@ -89,6 +91,7 @@ struct QGles2Texture : public QRhiTexture
GLenum glintformat;
GLenum glformat;
GLenum gltype;
friend class QRhiGles2;
};
struct QGles2Sampler : public QRhiSampler
......@@ -103,6 +106,7 @@ struct QGles2Sampler : public QRhiSampler
GLenum glwraps;
GLenum glwrapt;
GLenum glwrapr;
friend class QRhiGles2;
};
struct QGles2RenderPass : public QRhiRenderPass
......@@ -142,6 +146,7 @@ struct QGles2TextureRenderTarget : public QRhiTextureRenderTarget
QGles2BasicRenderTargetData d;
GLuint framebuffer = 0;
friend class QRhiGles2;
};
struct QGles2ShaderResourceBindings : public QRhiShaderResourceBindings
......@@ -151,6 +156,7 @@ struct QGles2ShaderResourceBindings : public QRhiShaderResourceBindings
bool build() override;
uint generation = 0;
friend class QRhiGles2;
};
struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
......@@ -179,6 +185,8 @@ struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
int binding;
};
QVector<Sampler> samplers;
friend class QRhiGles2;
};
Q_DECLARE_TYPEINFO(QGles2GraphicsPipeline::Uniform, Q_MOVABLE_TYPE);
......
......@@ -236,8 +236,9 @@ void QRhiMetal::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
{
Q_ASSERT(inPass);
QMetalGraphicsPipeline *psD = QRHI_RES(QMetalGraphicsPipeline, ps);
if (!srb)
srb = ps->shaderResourceBindings;
srb = psD->m_shaderResourceBindings;
QMetalShaderResourceBindings *srbD = QRHI_RES(QMetalShaderResourceBindings, srb);
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
......@@ -247,8 +248,8 @@ void QRhiMetal::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
switch (b.type) {
case QRhiShaderResourceBindings::Binding::UniformBuffer:
{
Q_ASSERT(b.ubuf.buf->usage.testFlag(QRhiBuffer::UniformBuffer));
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b.ubuf.buf);
Q_ASSERT(bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer));
bufD->lastActiveFrameSlot = currentFrameSlot;
executeBufferHostWritesForCurrentFrame(bufD);
id<MTLBuffer> mtlbuf = bufD->d->buf[currentFrameSlot]; // ###
......@@ -268,7 +269,6 @@ void QRhiMetal::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
}
}
QMetalGraphicsPipeline *psD = QRHI_RES(QMetalGraphicsPipeline, ps);
if (cbD->currentPipeline != ps || cbD->currentPipelineGeneration != psD->generation
|| cbD->currentSrb != srb || cbD->currentSrbGeneration != srbD->generation)
{
......@@ -471,16 +471,16 @@ void QRhiMetal::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates)
QRhiResourceUpdateBatchPrivate *ud = QRhiResourceUpdateBatchPrivate::get(resourceUpdates);
for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : ud->dynamicBufferUpdates) {
//Q_ASSERT(u.buf->type == QRhiBuffer::Dynamic);
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, u.buf);
//Q_ASSERT(u.buf->type == QRhiBuffer::Dynamic);
for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i)
bufD->d->pendingSharedModeUpdates[i].append(u);
}
for (const QRhiResourceUpdateBatchPrivate::StaticBufferUpload &u : ud->staticBufferUploads) {
//Q_ASSERT(u.buf->type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == u.buf->size);
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, u.buf);
//Q_ASSERT(u.buf->type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == bufD->m_size);
for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i)
bufD->d->pendingSharedModeUpdates[i].append({ u.buf, 0, u.data.size(), u.data.constData() });
}
......@@ -619,7 +619,7 @@ bool QMetalBuffer::build()
if (d->buf[0])
release();
const int roundedSize = usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned(size, 256) : size;
const int roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned(m_size, 256) : m_size;
MTLResourceOptions opts = MTLResourceStorageModeShared; // ### for now everything host visible and double buffered
......@@ -766,8 +766,10 @@ bool QMetalShaderResourceBindings::build()
if (!sortedBindings.isEmpty())
release();
sortedBindings = bindings;
std::sort(sortedBindings.begin(), sortedBindings.end(), [](const Binding &a, const Binding &b) {
sortedBindings = m_bindings;
std::sort(sortedBindings.begin(), sortedBindings.end(),
[](const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b)
{
return a.binding < b.binding;
});
if (!sortedBindings.isEmpty())
......@@ -1053,16 +1055,16 @@ bool QMetalGraphicsPipeline::build()
QRHI_RES_RHI(QRhiMetal);
// same binding space for vertex and constant buffers - work it around
const int firstVertexBinding = QRHI_RES(QMetalShaderResourceBindings, shaderResourceBindings)->maxBinding + 1;
const int firstVertexBinding = QRHI_RES(QMetalShaderResourceBindings, m_shaderResourceBindings)->maxBinding + 1;
MTLVertexDescriptor *inputLayout = [MTLVertexDescriptor vertexDescriptor];
for (const QRhiVertexInputLayout::Attribute &attribute : vertexInputLayout.attributes) {
for (const QRhiVertexInputLayout::Attribute &attribute : m_vertexInputLayout.attributes) {
inputLayout.attributes[attribute.location].format = toMetalAttributeFormat(attribute.format);
inputLayout.attributes[attribute.location].offset = attribute.offset;
inputLayout.attributes[attribute.location].bufferIndex = firstVertexBinding + attribute.binding;
}
for (int i = 0; i < vertexInputLayout.bindings.count(); ++i) {
const QRhiVertexInputLayout::Binding &binding(vertexInputLayout.bindings[i]);
for (int i = 0; i < m_vertexInputLayout.bindings.count(); ++i) {
const QRhiVertexInputLayout::Binding &binding(m_vertexInputLayout.bindings[i]);
const int layoutIdx = firstVertexBinding + i;
inputLayout.layouts[layoutIdx].stepFunction =
binding.classification == QRhiVertexInputLayout::Binding::PerInstance
......@@ -1074,7 +1076,7 @@ bool QMetalGraphicsPipeline::build()
MTLRenderPipelineDescriptor *rpDesc = [[MTLRenderPipelineDescriptor alloc] init];
rpDesc.vertexDescriptor = inputLayout;
for (const QRhiGraphicsShaderStage &shaderStage : qAsConst(shaderStages)) {
for (const QRhiGraphicsShaderStage &shaderStage : qAsConst(m_shaderStages)) {
QString error;
QByteArray entryPoint;
id<MTLLibrary> lib = rhiD->d->compileMSLShaderSource(shaderStage.shader, &error, &entryPoint);
......@@ -1119,8 +1121,8 @@ bool QMetalGraphicsPipeline::build()
rpDesc.colorAttachments[0].writeMask = MTLColorWriteMaskAll;
rpDesc.colorAttachments[0].blendingEnabled = false;
for (int i = 0, ie = targetBlends.count(); i != ie; ++i) {
const QRhiGraphicsPipeline::TargetBlend &b(targetBlends[i]);
for (int i = 0, ie = m_targetBlends.count(); i != ie; ++i) {
const QRhiGraphicsPipeline::TargetBlend &b(m_targetBlends[i]);
rpDesc.colorAttachments[i].pixelFormat = MTLPixelFormatBGRA8Unorm;
rpDesc.colorAttachments[i].blendingEnabled = b.enable;
rpDesc.colorAttachments[i].sourceRGBBlendFactor = toMetalBlendFactor(b.srcColor);
......@@ -1154,32 +1156,32 @@ bool QMetalGraphicsPipeline::build()
[rpDesc release];
MTLDepthStencilDescriptor *dsDesc = [[MTLDepthStencilDescriptor alloc] init];
dsDesc.depthCompareFunction = depthTest ? toMetalCompareOp(depthOp) : MTLCompareFunctionAlways;
dsDesc.depthWriteEnabled = depthWrite;
if (stencilTest) {
dsDesc.depthCompareFunction = m_depthTest ? toMetalCompareOp(m_depthOp) : MTLCompareFunctionAlways;
dsDesc.depthWriteEnabled = m_depthWrite;
if (m_stencilTest) {
dsDesc.frontFaceStencil = [[MTLStencilDescriptor alloc] init];
dsDesc.frontFaceStencil.stencilFailureOperation = toMetalStencilOp(stencilFront.failOp);
dsDesc.frontFaceStencil.depthFailureOperation = toMetalStencilOp(stencilFront.depthFailOp);
dsDesc.frontFaceStencil.depthStencilPassOperation = toMetalStencilOp(stencilFront.passOp);
dsDesc.frontFaceStencil.stencilCompareFunction = toMetalCompareOp(stencilFront.compareOp);
dsDesc.frontFaceStencil.readMask = stencilReadMask;
dsDesc.frontFaceStencil.writeMask = stencilWriteMask;
dsDesc.frontFaceStencil.stencilFailureOperation = toMetalStencilOp(m_stencilFront.failOp);
dsDesc.frontFaceStencil.depthFailureOperation = toMetalStencilOp(m_stencilFront.depthFailOp);
dsDesc.frontFaceStencil.depthStencilPassOperation = toMetalStencilOp(m_stencilFront.passOp);
dsDesc.frontFaceStencil.stencilCompareFunction = toMetalCompareOp(m_stencilFront.compareOp);
dsDesc.frontFaceStencil.readMask = m_stencilReadMask;
dsDesc.frontFaceStencil.writeMask = m_stencilWriteMask;
dsDesc.backFaceStencil = [[MTLStencilDescriptor alloc] init];
dsDesc.backFaceStencil.stencilFailureOperation = toMetalStencilOp(stencilBack.failOp);
dsDesc.backFaceStencil.depthFailureOperation = toMetalStencilOp(stencilBack.depthFailOp);
dsDesc.backFaceStencil.depthStencilPassOperation = toMetalStencilOp(stencilBack.passOp);
dsDesc.backFaceStencil.stencilCompareFunction = toMetalCompareOp(stencilBack.compareOp);
dsDesc.backFaceStencil.readMask = stencilReadMask;
dsDesc.backFaceStencil.writeMask = stencilWriteMask;
dsDesc.backFaceStencil.stencilFailureOperation = toMetalStencilOp(m_stencilBack.failOp);
dsDesc.backFaceStencil.depthFailureOperation = toMetalStencilOp(m_stencilBack.depthFailOp);
dsDesc.backFaceStencil.depthStencilPassOperation = toMetalStencilOp(m_stencilBack.passOp);
dsDesc.backFaceStencil.stencilCompareFunction = toMetalCompareOp(m_stencilBack.compareOp);
dsDesc.backFaceStencil.readMask = m_stencilReadMask;
dsDesc.backFaceStencil.writeMask = m_stencilWriteMask;
}
d->ds = [rhiD->d->dev newDepthStencilStateWithDescriptor: dsDesc];
[dsDesc release];
d->primitiveType = toMetalPrimitiveType(topology);
d->winding = frontFace == CCW ? MTLWindingCounterClockwise : MTLWindingClockwise;
d->cullMode = toMetalCullMode(cullMode);
d->primitiveType = toMetalPrimitiveType(m_topology);
d->winding = m_frontFace == CCW ? MTLWindingCounterClockwise : MTLWindingClockwise;
d->cullMode = toMetalCullMode(m_cullMode);
lastActiveFrameSlot = -1;
generation += 1;
......
......@@ -63,6 +63,7 @@ struct QMetalBuffer : public QRhiBuffer
QMetalBufferData *d;
uint generation = 0;
int lastActiveFrameSlot = -1;
friend class QRhiMetal;
};
struct QMetalRenderBuffer : public QRhiRenderBuffer
......@@ -71,6 +72,8 @@ struct QMetalRenderBuffer : public QRhiRenderBuffer
int sampleCount, QRhiRenderBuffer::Hints hints);
void release() override;
bool build() override;
friend class QRhiMetal;
};
struct QMetalTexture : public QRhiTexture
......@@ -81,6 +84,7 @@ struct QMetalTexture : public QRhiTexture
uint generation = 0;
int lastActiveFrameSlot = -1;
friend class QRhiMetal;
};
struct QMetalSampler : public QRhiSampler
......@@ -92,6 +96,7 @@ struct QMetalSampler : public QRhiSampler
uint generation = 0;
int lastActiveFrameSlot = -1;
friend class QRhiMetal;
};
struct QMetalRenderPassData;
......@@ -134,6 +139,7 @@ struct QMetalTextureRenderTarget : public QRhiTextureRenderTarget
const QRhiRenderPass *renderPass() const override;
QMetalBasicRenderTargetData d;
friend class QRhiMetal;
};
struct QMetalShaderResourceBindings : public QRhiShaderResourceBindings
......@@ -145,6 +151,7 @@ struct QMetalShaderResourceBindings : public QRhiShaderResourceBindings
QVector<Binding> sortedBindings;
int maxBinding = -1;
uint generation = 0;
friend class QRhiMetal;
};
struct QMetalGraphicsPipelineData;
......@@ -159,6 +166,7 @@ struct QMetalGraphicsPipeline : public QRhiGraphicsPipeline
QMetalGraphicsPipelineData *d;
uint generation = 0;
int lastActiveFrameSlot = -1;
friend class QRhiMetal;
};
struct QMetalCommandBufferData;
......
This diff is collapsed.
......@@ -74,6 +74,7 @@ struct QVkBuffer : public QRhiBuffer
int lastActiveFrameSlot = -1;
int stagingFrameSlot = -1;
uint generation = 0;
friend class QRhiVulkan;
};
struct QVkRenderBuffer : public QRhiRenderBuffer
......@@ -87,6 +88,7 @@ struct QVkRenderBuffer : public QRhiRenderBuffer
VkImage image;
VkImageView imageView;
int lastActiveFrameSlot = -1;
friend class QRhiVulkan;
};
struct QVkTexture : public QRhiTexture
......@@ -105,6 +107,7 @@ struct QVkTexture : public QRhiTexture
int lastActiveFrameSlot = -1;
int stagingFrameSlot = -1;
uint generation = 0;
friend class QRhiVulkan;
};
struct QVkSampler : public QRhiSampler
......@@ -117,6 +120,7 @@ struct QVkSampler : public QRhiSampler
VkSampler sampler = VK_NULL_HANDLE;
int lastActiveFrameSlot = -1;
uint generation = 0;
friend class QRhiVulkan;
};
struct QVkRenderPass : public QRhiRenderPass
......@@ -162,6 +166,7 @@ struct QVkTextureRenderTarget : public QRhiTextureRenderTarget
QVkBasicRenderTargetData d;
VkImageView cubeFaceView[6];
int lastActiveFrameSlot = -1;
friend class QRhiVulkan;
};
struct QVkShaderResourceBindings : public QRhiShaderResourceBindings
......@@ -193,6 +198,8 @@ struct QVkShaderResourceBindings : public QRhiShaderResourceBindings
};
};
QVector<BoundResourceData> boundResourceData[QVK_FRAMES_IN_FLIGHT];
friend class QRhiVulkan;
};
Q_DECLARE_TYPEINFO(QVkShaderResourceBindings::BoundResourceData, Q_MOVABLE_TYPE);
......@@ -207,6 +214,7 @@ struct QVkGraphicsPipeline : public QRhiGraphicsPipeline
VkPipeline pipeline = VK_NULL_HANDLE;
int lastActiveFrameSlot = -1;
uint generation = 0;
friend class QRhiVulkan;
};
struct QVkCommandBuffer : public QRhiCommandBuffer
......
......@@ -144,7 +144,7 @@ void ExampleWindow::recreateSwapChain()
QRhiRenderBuffer::ToBeUsedWithSwapChainOnly);
} else {
m_ds->release();
m_ds->pixelSize = outputSize;
m_ds->setPixelSize(outputSize);
}
if (!m_ds)
......
......@@ -61,10 +61,9 @@ void QuadRenderer::initResources()
m_ubuf->build();
m_srb = m_r->createShaderResourceBindings();
const auto ubufVisibility = QRhiShaderResourceBindings::Binding::VertexStage | QRhiShaderResourceBindings::Binding::FragmentStage;
m_srb->bindings = {
QRhiShaderResourceBindings::Binding::uniformBuffer(0, ubufVisibility, m_ubuf)
};
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf)
});
m_srb->build();
}
......
......@@ -64,11 +64,10 @@ void TexturedCubeRenderer::initResources()
m_sampler->build();
m_srb = m_r->createShaderResourceBindings();
const auto ubufVisibility = QRhiShaderResourceBindings::Binding::VertexStage | QRhiShaderResourceBindings::Binding::FragmentStage;
m_srb->bindings = {
QRhiShaderResourceBindings::Binding::uniformBuffer(0, ubufVisibility, m_ubuf),
QRhiShaderResourceBindings::Binding::sampledTexture(1, QRhiShaderResourceBindings::Binding::FragmentStage, m_tex, m_sampler)
};
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf),
QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, m_tex, m_sampler)
});
m_srb->build();
}
......@@ -76,23 +75,23 @@ void TexturedCubeRenderer::initOutputDependentResources(const QRhiRenderPass *rp
{
m_ps = m_r->createGraphicsPipeline();
m_ps->depthTest = true;
m_ps->depthWrite = true;
m_ps->depthOp = QRhiGraphicsPipeline::Less;
m_ps->setDepthTest(true);
m_ps->setDepthWrite(true);
m_ps->setDepthOp(QRhiGraphicsPipeline::Less);
m_ps->cullMode = QRhiGraphicsPipeline::Back;
m_ps->frontFace = QRhiGraphicsPipeline::CCW;
m_ps->setCullMode(QRhiGraphicsPipeline::Back);
m_ps->setFrontFace(QRhiGraphicsPipeline::CCW);
m_ps->sampleCount = m_sampleCount;
m_ps->setSampleCount(m_sampleCount);
QBakedShader vs = getShader(QLatin1String(":/texture.vert.qsb"));
Q_ASSERT(vs.isValid());
QBakedShader fs = getShader(QLatin1String(":/texture.frag.qsb"));
Q_ASSERT(fs.isValid());
m_ps->shaderStages = {
m_ps->setShaderStages({
{ QRhiGraphicsShaderStage::Vertex, vs },
{ QRhiGraphicsShaderStage::Fragment, fs }
};
});
QRhiVertexInputLayout inputLayout;
inputLayout.bindings = {
......@@ -104,9 +103,9 @@ void TexturedCubeRenderer::initOutputDependentResources(const QRhiRenderPass *rp
{ 1, 1, QRhiVertexInputLayout::Attribute::Float2, 0 }
};
m_ps->vertexInputLayout = inputLayout;
m_ps->shaderResourceBindings = m_srb;
m_ps->renderPass = rp;
m_ps->setVertexInputLayout(inputLayout);
m_ps->setShaderResourceBindings(m_srb);
m_ps->setRenderPass(rp);
m_ps->build();
......@@ -162,8 +161,8 @@ void TexturedCubeRenderer::queueResourceUpdates(QRhiResourceUpdateBatch *resourc
if (!m_image.isNull()) {
if (MIPMAP) {
QRhiResourceUpdateBatch::TextureUploadDescription desc;
desc.layers.append(QRhiResourceUpdateBatch::TextureUploadDescription::Layer());
QRhiTextureUploadDescription desc;
desc.layers.append(QRhiTextureUploadDescription::Layer());
// the ghetto mipmap generator...
for (int i = 0, ie = m_r->mipLevelsForSize(m_image.size()); i != ie; ++i) {
QImage image = m_image.scaled(m_r->sizeForMipLevel(i, m_image.size()));
......
......@@ -77,11 +77,10 @@ void TriangleOnCubeRenderer::initResources()
m_sampler->build();
m_srb = m_r->createShaderResourceBindings();
const auto ubufVisibility = QRhiShaderResourceBindings::Binding::VertexStage | QRhiShaderResourceBindings::Binding::FragmentStage;
m_srb->bindings = {
QRhiShaderResourceBindings::Binding::uniformBuffer(0, ubufVisibility, m_ubuf),
QRhiShaderResourceBindings::Binding::sampledTexture(1, QRhiShaderResourceBindings::Binding::FragmentStage, m_tex, m_sampler)
};
m_srb->setBindings({
QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, m_ubuf),
QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, m_tex, m_sampler)
});
m_srb->build();
if (DEPTH_TEXTURE) {
......@@ -117,23 +116,23 @@ void TriangleOnCubeRenderer::initOutputDependentResources(const QRhiRenderPass *
{
m_ps = m_r->createGraphicsPipeline();
m_ps->depthTest = true;
m_ps->depthWrite = true;
m_ps->depthOp = QRhiGraphicsPipeline::Less;
m_ps->setDepthTest(true);
m_ps->setDepthWrite(true);
m_ps->setDepthOp(QRhiGraphicsPipeline::Less);
m_ps->cullMode = QRhiGraphicsPipeline::Back;
m_ps->frontFace = QRhiGraphicsPipeline::CCW;
m_ps->setCullMode(QRhiGraphicsPipeline::Back);
m_ps->setFrontFace(QRhiGraphicsPipeline::CCW);
m_ps->sampleCount = m_sampleCount;
m_ps->setSampleCount(m_sampleCount);