21#include <QElapsedTimer>
22#include <QLoggingCategory>
23#include <QtCore/qset.h>
24#include <QtCore/qvarlengtharray.h>
28#define QRHI_RES(t, x) static_cast<t *>(x)
29#define QRHI_RES_RHI(t) t *rhiD = static_cast<t *>(m_rhi)
45 QRhiBuffer::UsageFlags
usage,
48 const QSize &pixelSize,
50 QRhiRenderBuffer::Flags
flags,
53 const QSize &pixelSize,
57 QRhiTexture::Flags
flags) = 0;
66 QRhiTextureRenderTarget::Flags
flags) = 0;
79 const QColor &colorClearValue,
82 QRhiCommandBuffer::BeginPassFlags
flags) = 0;
90 int dynamicOffsetCount,
115 QRhiCommandBuffer::BeginPassFlags
flags) = 0;
149 QSize *blockDim)
const;
161 resources.insert(
res, ownsNativeResources);
166 resources.remove(
res);
172 pendingDeleteResources.insert(
res);
179 cleanupCallbacks.append(callback);
188 const quint32 ver = (QT_VERSION_MAJOR << 16) | (QT_VERSION_MINOR << 8) | (QT_VERSION_PATCH);
189 return (
quint32(implType) << 24) | ver;
194 pipelineCreationTimer.start();
199 accumulatedPipelineCreationTime += pipelineCreationTimer.elapsed();
204 return accumulatedPipelineCreationTime;
222 return a.d.binding <
b.d.binding;
227 static const int MAX_SHADER_CACHE_ENTRIES = 128;
229 bool debugMarkers =
false;
230 int currentFrameSlot = 0;
231 bool inFrame =
false;
238 int lastResUpdIdx = -1;
243 qint64 accumulatedPipelineCreationTime = 0;
255template<QRhiTargetRectBoundMode boundingMode,
typename T,
size_t N>
257 T *
x, T *
y, T *
w, T *
h)
268 const T outputWidth = outputSize.
width();
269 const T outputHeight = outputSize.
height();
270 const T inputWidth =
r[2];
271 const T inputHeight =
r[3];
273 if (inputWidth < 0 || inputHeight < 0)
277 *
y = outputHeight - (
r[1] + inputHeight);
282 const T widthOffset = *
x < 0 ? -*
x : 0;
283 const T heightOffset = *
y < 0 ? -*
y : 0;
284 *
w = *x < outputWidth ? qMax<T>(0, inputWidth - widthOffset) : 0;
285 *
h = *y < outputHeight ? qMax<T>(0, inputHeight - heightOffset) : 0;
288 *
x = qBound<T>(0, *
x, outputWidth - 1);
289 if (outputHeight > 0)
290 *
y = qBound<T>(0, *
y, outputHeight - 1);
292 if (*
x + *
w > outputWidth)
293 *
w = qMax<T>(0, outputWidth - *
x);
294 if (*
y + *
h > outputHeight)
295 *
h = qMax<T>(0, outputHeight - *
y);
352 }
else if (d->
ref != 1) {
396 const int effectiveSize =
size ?
size :
buf->size();
397 op.
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
406 const int effectiveSize =
size ?
size :
buf->size();
407 op->
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
416 const int effectiveSize =
size ?
size :
buf->size();
417 op.
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
426 const int effectiveSize =
size ?
size :
buf->size();
427 op->
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
468 for (
auto it =
desc.cbeginEntries(), itEnd =
desc.cendEntries();
it != itEnd; ++
it) {
469 if (
it->layer() > maxLayer)
470 maxLayer =
it->layer();
473 for (
auto it =
desc.cbeginEntries(), itEnd =
desc.cendEntries();
it != itEnd; ++
it)
529 void feed(
int binding, T resource) {
530 if (curBinding == -1 || binding > curBinding + 1) {
536 Q_ASSERT(binding == curBinding + 1);
539 curBinding = binding;
589#ifdef Q_ATOMIC_INT64_IS_SUPPORTED
629 const UsageState &
state);
652 const UsageState &
state);
686template<
typename T,
int GROW = 1024>
699 memcpy(nv,
v,
p *
sizeof(T));
723 template<
typename TexType,
typename RenderBufferType>
726 template<
typename TexType,
typename RenderBufferType>
732 return a.id ==
b.id &&
a.generation ==
b.generation;
740template<
typename TexType,
typename RenderBufferType>
743 const bool hasDepthStencil =
desc.depthStencilBuffer() ||
desc.depthTexture();
744 dst->resize(
desc.colorAttachmentCount() * 2 + (hasDepthStencil ? 1 : 0));
746 for (
auto it =
desc.cbeginColorAttachments(), itEnd =
desc.cendColorAttachments();
it != itEnd; ++
it, ++
n) {
750 (*dst)[
n] = { texD->globalResourceId(), texD->generation };
753 (*dst)[
n] = { rbD->globalResourceId(), rbD->generation };
755 (*dst)[
n] = { 0, 0 };
760 (*dst)[
n] = { texD->globalResourceId(), texD->generation };
762 (*dst)[
n] = { 0, 0 };
765 if (hasDepthStencil) {
766 if (
desc.depthTexture()) {
767 TexType *depthTexD =
QRHI_RES(TexType,
desc.depthTexture());
768 (*dst)[
n] = { depthTexD->globalResourceId(), depthTexD->generation };
769 }
else if (
desc.depthStencilBuffer()) {
770 RenderBufferType *depthRbD =
QRHI_RES(RenderBufferType,
desc.depthStencilBuffer());
771 (*dst)[
n] = { depthRbD->globalResourceId(), depthRbD->generation };
773 (*dst)[
n] = { 0, 0 };
778template<
typename TexType,
typename RenderBufferType>
790 updateResIdList<TexType, RenderBufferType>(
desc, &resIdList);
791 return resIdList == currentResIdList;
800 return static_cast<T *
>(pd->
reserved[objectIndex]);
The QColor class provides colors based on RGB, HSV or CMYK values.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
QRhiBackendCommandList()=default
~QRhiBackendCommandList()
void assign(const char *s, quint32 size)
QRhiBufferData(const QRhiBufferData &other)
QRhiBufferData & operator=(const QRhiBufferData &other)
const char * constData() const
Type
Specifies storage type of buffer resource.
QRhiRenderBuffer * renderBuffer() const
QRhiTexture * texture() const
QRhiTexture * resolveTexture() const
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, quint32>.
QPair< int, quint32 > DynamicOffset
Synonym for QPair<int, quint32>.
IndexFormat
Specifies the index data type.
virtual bool isClipDepthZeroToOne() const =0
virtual void endExternal(QRhiCommandBuffer *cb)=0
virtual QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags)=0
virtual QRhiComputePipeline * createComputePipeline()=0
virtual QRhiGraphicsPipeline * createGraphicsPipeline()=0
virtual void beginPass(QRhiCommandBuffer *cb, QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags)=0
virtual void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps)=0
virtual void releaseCachedResources()=0
virtual bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const =0
void unregisterResource(QRhiResource *res)
virtual QRhiDriverInfo driverInfo() const =0
static const QRhiShaderResourceBinding::Data * shaderResourceBindingData(const QRhiShaderResourceBinding &binding)
quint32 pipelineCacheRhiId() const
virtual QRhiSampler * createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w)=0
virtual QRhiTexture * createTexture(QRhiTexture::Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, QRhiTexture::Flags flags)=0
virtual bool isYUpInFramebuffer() const =0
virtual QList< int > supportedSampleCounts() const =0
virtual void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)=0
virtual void debugMarkEnd(QRhiCommandBuffer *cb)=0
virtual QRhi::FrameOpResult finish()=0
virtual QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags)=0
virtual void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)=0
virtual int ubufAlignment() const =0
virtual QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags)=0
virtual void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)=0
virtual void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags)=0
virtual void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c)=0
virtual void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name)=0
virtual int resourceLimit(QRhi::ResourceLimit limit) const =0
virtual void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets)=0
virtual void setPipelineCacheData(const QByteArray &data)=0
virtual QRhiBuffer * createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)=0
static bool sortedBindingLessThan(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b)
virtual bool isDeviceLost() const =0
virtual const QRhiNativeHandles * nativeHandles(QRhiCommandBuffer *cb)=0
virtual void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport)=0
virtual void beginExternal(QRhiCommandBuffer *cb)=0
virtual QMatrix4x4 clipSpaceCorrMatrix() const =0
virtual void dispatch(QRhiCommandBuffer *cb, int x, int y, int z)=0
virtual bool makeThreadLocalNativeContextCurrent()=0
void addDeleteLater(QRhiResource *res)
virtual void setVertexInput(QRhiCommandBuffer *cb, int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat)=0
void pipelineCreationStart()
virtual QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags)=0
void registerResource(QRhiResource *res, bool ownsNativeResources=true)
virtual void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue)=0
static QRhiShaderResourceBinding::Data * shaderResourceBindingData(QRhiShaderResourceBinding &binding)
virtual void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)=0
virtual double lastCompletedGpuTime(QRhiCommandBuffer *cb)=0
virtual QRhiRenderBuffer * createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint)=0
void addCleanupCallback(const QRhi::CleanupCallback &callback)
qint64 totalPipelineCreationTime() const
virtual bool isYUpInNDC() const =0
virtual void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance)=0
virtual QRhiShaderResourceBindings * createShaderResourceBindings()=0
virtual bool isFeatureSupported(QRhi::Feature feature) const =0
virtual void setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps)=0
virtual bool create(QRhi::Flags flags)=0
virtual void draw(QRhiCommandBuffer *cb, quint32 vertexCount, quint32 instanceCount, quint32 firstVertex, quint32 firstInstance)=0
virtual QByteArray pipelineCacheData()=0
virtual QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags)=0
void pipelineCreationEnd()
virtual QRhiStats statistics()=0
virtual void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor)=0
virtual QRhiSwapChain * createSwapChain()=0
virtual const QRhiNativeHandles * nativeHandles()=0
static TextureStage toPassTrackerTextureStage(QRhiShaderResourceBinding::StageFlags stages)
TextureIterator cendTextures() const
static BufferStage toPassTrackerBufferStage(QRhiShaderResourceBinding::StageFlags stages)
BufferIterator cbeginBuffers() const
BufferIterator cendBuffers() const
TextureIterator cbeginTextures() const
void registerBuffer(QRhiBuffer *buf, int slot, BufferAccess *access, BufferStage *stage, const UsageState &state)
void registerTexture(QRhiTexture *tex, TextureAccess *access, TextureStage *stage, const UsageState &state)
Type
Specifies the type of the renderbuffer.
QVarLengthArray< BufferOp, BUFFER_OPS_STATIC_ALLOC > bufferOps
bool hasOptimalCapacity() const
QVarLengthArray< TextureOp, TEXTURE_OPS_STATIC_ALLOC > textureOps
static const int BUFFER_OPS_STATIC_ALLOC
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
void merge(QRhiResourceUpdateBatchPrivate *other)
static const int TEXTURE_OPS_STATIC_ALLOC
Filter
Specifies the minification, magnification, or mipmap filtering.
AddressMode
Specifies the addressing mode.
Format
Specifies the texture format.
static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window)
Generates and returns a QRhiSwapChainProxyData struct containing opaque data specific to the backend ...
Implementation
Describes which graphics API-specific backend gets used by a QRhi instance.
ResourceLimit
Describes the resource limit to query.
Feature
Flag values to indicate what features are supported by the backend currently in use.
static const int MAX_MIP_LEVELS
FrameOpResult
Describes the result of operations that can have a soft failure.
std::function< void(QRhi *)> CleanupCallback
VariableType
Represents the type of a variable or block member.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
void resize(qsizetype sz)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
GLsizeiptr const void GLenum usage
static bool isCompressedFormat(QOpenGLTexture::TextureFormat internalFormat)
T * qrhi_objectFromProxyData(QRhiSwapChainProxyData *pd, QWindow *window, QRhi::Implementation impl, uint objectIndex)
bool operator!=(const QRhiRenderTargetAttachmentTracker::ResId &a, const QRhiRenderTargetAttachmentTracker::ResId &b)
bool operator==(const QRhiRenderTargetAttachmentTracker::ResId &a, const QRhiRenderTargetAttachmentTracker::ResId &b)
bool qrhi_toTopLeftRenderTargetRect(const QSize &outputSize, const std::array< T, N > &r, T *x, T *y, T *w, T *h)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
unsigned long long quint64
view viewport() -> scroll(dx, dy, deviceRect)
bool operator!=(const Batch &other) const
bool operator==(const Batch &other) const
QVarLengthArray< T, 4 > resources
void feed(int binding, T resource)
QVarLengthArray< Batch, 4 > batches
bool operator!=(const QRhiBatchedBindings< T > &other) const
bool operator==(const QRhiBatchedBindings< T > &other) const
char data[SMALL_DATA_SIZE]
static constexpr quint32 SMALL_DATA_SIZE
\variable QRhiReadbackResult::completed
UsageState stateAtPassBegin
UsageState stateAtPassBegin
static void updateResIdList(const QRhiTextureRenderTargetDescription &desc, ResIdList *dst)
static bool isUpToDate(const QRhiTextureRenderTargetDescription &desc, const ResIdList ¤tResIdList)
QRhiReadbackResult * result
static void changeToStaticUpload(BufferOp *op, QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
static BufferOp staticUpload(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
static BufferOp read(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result)
static BufferOp dynamicUpdate(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
static void changeToDynamicUpdate(BufferOp *op, QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
QRhiTextureCopyDescription desc
static TextureOp copy(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc)
std::array< QVector< QRhiTextureSubresourceUploadDescription >, QRhi::MAX_MIP_LEVELS > MipLevelUploadList
QRhiReadbackDescription rb
QVarLengthArray< MipLevelUploadList, 6 > subresDesc
static TextureOp upload(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
static TextureOp genMips(QRhiTexture *tex)
static TextureOp read(const QRhiReadbackDescription &rb, QRhiReadbackResult *result)
QRhiReadbackResult * result