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);
184 keyedCleanupCallbacks[
key] = callback;
189 keyedCleanupCallbacks.remove(
key);
198 const quint32 ver = (QT_VERSION_MAJOR << 16) | (QT_VERSION_MINOR << 8) | (QT_VERSION_PATCH);
199 return (
quint32(implType) << 24) | ver;
204 pipelineCreationTimer.start();
209 accumulatedPipelineCreationTime += pipelineCreationTimer.elapsed();
214 return accumulatedPipelineCreationTime;
232 return a.d.binding <
b.d.binding;
235 int effectiveSampleCount(
int sampleCount)
const;
239 static const int MAX_SHADER_CACHE_ENTRIES = 128;
241 bool debugMarkers =
false;
242 int currentFrameSlot = 0;
243 bool inFrame =
false;
248 QVarLengthArray<QRhiResourceUpdateBatch *, 4> resUpdPool;
250 int lastResUpdIdx = -1;
251 QHash<QRhiResource *, bool> resources;
252 QSet<QRhiResource *> pendingDeleteResources;
253 QVarLengthArray<QRhi::CleanupCallback, 4> cleanupCallbacks;
254 QHash<const void *, QRhi::CleanupCallback> keyedCleanupCallbacks;
256 qint64 accumulatedPipelineCreationTime = 0;
268template<QRhiTargetRectBoundMode boundingMode,
typename T,
size_t N>
270 T *
x, T *
y, T *
w, T *
h)
281 const T outputWidth = outputSize.
width();
282 const T outputHeight = outputSize.
height();
283 const T inputWidth =
r[2];
284 const T inputHeight =
r[3];
286 if (inputWidth < 0 || inputHeight < 0)
290 *
y = outputHeight - (
r[1] + inputHeight);
295 const T widthOffset = *
x < 0 ? -*
x : 0;
296 const T heightOffset = *
y < 0 ? -*
y : 0;
297 *
w = *x < outputWidth ? qMax<T>(0, inputWidth - widthOffset) : 0;
298 *
h = *y < outputHeight ? qMax<T>(0, inputHeight - heightOffset) : 0;
301 *
x = qBound<T>(0, *
x, outputWidth - 1);
302 if (outputHeight > 0)
303 *
y = qBound<T>(0, *
y, outputHeight - 1);
305 if (*
x + *
w > outputWidth)
306 *
w = qMax<T>(0, outputWidth - *
x);
307 if (*
y + *
h > outputHeight)
308 *
h = qMax<T>(0, outputHeight - *
y);
365 }
else if (d->
ref != 1) {
409 const int effectiveSize =
size ?
size :
buf->size();
410 op.
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
419 const int effectiveSize =
size ?
size :
buf->size();
420 op->
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
429 const int effectiveSize =
size ?
size :
buf->size();
430 op.
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
439 const int effectiveSize =
size ?
size :
buf->size();
440 op->
data.
assign(
reinterpret_cast<const char *
>(
data), effectiveSize);
481 for (
auto it =
desc.cbeginEntries(), itEnd =
desc.cendEntries();
it != itEnd; ++
it) {
482 if (
it->layer() > maxLayer)
483 maxLayer =
it->layer();
486 for (
auto it =
desc.cbeginEntries(), itEnd =
desc.cendEntries();
it != itEnd; ++
it)
521 QVarLengthArray<BufferOp, BUFFER_OPS_STATIC_ALLOC>
bufferOps;
525 QVarLengthArray<TextureOp, TEXTURE_OPS_STATIC_ALLOC>
textureOps;
542 void feed(
int binding, T resource) {
543 if (curBinding == -1 || binding > curBinding + 1) {
549 Q_ASSERT(binding == curBinding + 1);
552 curBinding = binding;
602#ifdef Q_ATOMIC_INT64_IS_SUPPORTED
642 const UsageState &
state);
665 const UsageState &
state);
692 QHash<QRhiBuffer *, Buffer> m_buffers;
693 QHash<QRhiTexture *, Texture> m_textures;
699template<
typename T,
int GROW = 1024>
712 memcpy(nv,
v,
p *
sizeof(T));
736 template<
typename TexType,
typename RenderBufferType>
739 template<
typename TexType,
typename RenderBufferType>
745 return a.id ==
b.id &&
a.generation ==
b.generation;
753template<
typename TexType,
typename RenderBufferType>
756 const bool hasDepthStencil = desc.depthStencilBuffer() || desc.depthTexture();
757 dst->resize(desc.colorAttachmentCount() * 2 + (hasDepthStencil ? 1 : 0));
759 for (
auto it = desc.cbeginColorAttachments(), itEnd = desc.cendColorAttachments();
it != itEnd; ++
it, ++
n) {
763 (*dst)[
n] = { texD->globalResourceId(), texD->generation };
766 (*dst)[
n] = { rbD->globalResourceId(), rbD->generation };
768 (*dst)[
n] = { 0, 0 };
773 (*dst)[
n] = { texD->globalResourceId(), texD->generation };
775 (*dst)[
n] = { 0, 0 };
778 if (hasDepthStencil) {
779 if (desc.depthTexture()) {
780 TexType *depthTexD =
QRHI_RES(TexType, desc.depthTexture());
781 (*dst)[
n] = { depthTexD->globalResourceId(), depthTexD->generation };
782 }
else if (desc.depthStencilBuffer()) {
783 RenderBufferType *depthRbD =
QRHI_RES(RenderBufferType, desc.depthStencilBuffer());
784 (*dst)[
n] = { depthRbD->globalResourceId(), depthRbD->generation };
786 (*dst)[
n] = { 0, 0 };
791template<
typename TexType,
typename RenderBufferType>
803 updateResIdList<TexType, RenderBufferType>(desc, &resIdList);
804 return resIdList == currentResIdList;
813 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< int, quint32 > DynamicOffset
Synonym for QPair<int, quint32>.
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, 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
void removeCleanupCallback(const void *key)
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
void addCleanupCallback(const void *key, const QRhi::CleanupCallback &callback)
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.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
static constexpr int MAX_MIP_LEVELS
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.
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]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLenum GLsizei const GLchar * buf
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