| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QRHI_H |
| 5 | #define QRHI_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is part of the RHI API, with limited compatibility guarantees. |
| 12 | // Usage of this API may make your code source and binary incompatible with |
| 13 | // future versions of Qt. |
| 14 | // |
| 15 | |
| 16 | #include <QtGui/qtguiglobal.h> |
| 17 | #include <QtCore/qsize.h> |
| 18 | #include <QtCore/qlist.h> |
| 19 | #include <QtCore/qvarlengtharray.h> |
| 20 | #include <QtCore/qthread.h> |
| 21 | #include <QtGui/qmatrix4x4.h> |
| 22 | #include <QtGui/qcolor.h> |
| 23 | #include <QtGui/qimage.h> |
| 24 | #include <functional> |
| 25 | #include <array> |
| 26 | |
| 27 | #include <rhi/qshader.h> |
| 28 | |
| 29 | QT_BEGIN_NAMESPACE |
| 30 | |
| 31 | class QWindow; |
| 32 | class QRhi; |
| 33 | class QRhiImplementation; |
| 34 | class QRhiBuffer; |
| 35 | class QRhiRenderBuffer; |
| 36 | class QRhiTexture; |
| 37 | class QRhiSampler; |
| 38 | class QRhiCommandBuffer; |
| 39 | class QRhiResourceUpdateBatch; |
| 40 | class QRhiResourceUpdateBatchPrivate; |
| 41 | class QRhiSwapChain; |
| 42 | class QRhiShadingRateMap; |
| 43 | |
| 44 | class Q_GUI_EXPORT QRhiDepthStencilClearValue |
| 45 | { |
| 46 | public: |
| 47 | QRhiDepthStencilClearValue() = default; |
| 48 | QRhiDepthStencilClearValue(float d, quint32 s); |
| 49 | |
| 50 | float depthClearValue() const { return m_d; } |
| 51 | void setDepthClearValue(float d) { m_d = d; } |
| 52 | |
| 53 | quint32 stencilClearValue() const { return m_s; } |
| 54 | void setStencilClearValue(quint32 s) { m_s = s; } |
| 55 | |
| 56 | private: |
| 57 | float m_d = 1.0f; |
| 58 | quint32 m_s = 0; |
| 59 | |
| 60 | friend bool operator==(const QRhiDepthStencilClearValue &a, const QRhiDepthStencilClearValue &b) noexcept |
| 61 | { |
| 62 | return a.m_d == b.m_d && a.m_s == b.m_s; |
| 63 | } |
| 64 | |
| 65 | friend bool operator!=(const QRhiDepthStencilClearValue &a, const QRhiDepthStencilClearValue &b) noexcept |
| 66 | { |
| 67 | return !(a == b); |
| 68 | } |
| 69 | |
| 70 | friend size_t qHash(const QRhiDepthStencilClearValue &v, size_t seed = 0) noexcept |
| 71 | { |
| 72 | QtPrivate::QHashCombine hash(seed); |
| 73 | seed = hash(seed, v.m_d); |
| 74 | seed = hash(seed, v.m_s); |
| 75 | return seed; |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | Q_DECLARE_TYPEINFO(QRhiDepthStencilClearValue, Q_RELOCATABLE_TYPE); |
| 80 | |
| 81 | #ifndef QT_NO_DEBUG_STREAM |
| 82 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiDepthStencilClearValue &); |
| 83 | #endif |
| 84 | |
| 85 | class Q_GUI_EXPORT QRhiViewport |
| 86 | { |
| 87 | public: |
| 88 | QRhiViewport() = default; |
| 89 | QRhiViewport(float x, float y, float w, float h, float minDepth = 0.0f, float maxDepth = 1.0f); |
| 90 | |
| 91 | std::array<float, 4> viewport() const { return m_rect; } |
| 92 | void setViewport(float x, float y, float w, float h) { |
| 93 | m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h; |
| 94 | } |
| 95 | |
| 96 | float minDepth() const { return m_minDepth; } |
| 97 | void setMinDepth(float minDepth) { m_minDepth = minDepth; } |
| 98 | |
| 99 | float maxDepth() const { return m_maxDepth; } |
| 100 | void setMaxDepth(float maxDepth) { m_maxDepth = maxDepth; } |
| 101 | |
| 102 | private: |
| 103 | std::array<float, 4> m_rect { ._M_elems: { 0.0f, 0.0f, 0.0f, 0.0f } }; |
| 104 | float m_minDepth = 0.0f; |
| 105 | float m_maxDepth = 1.0f; |
| 106 | |
| 107 | friend bool operator==(const QRhiViewport &a, const QRhiViewport &b) noexcept |
| 108 | { |
| 109 | return a.m_rect == b.m_rect |
| 110 | && a.m_minDepth == b.m_minDepth |
| 111 | && a.m_maxDepth == b.m_maxDepth; |
| 112 | } |
| 113 | |
| 114 | friend bool operator!=(const QRhiViewport &a, const QRhiViewport &b) noexcept |
| 115 | { |
| 116 | return !(a == b); |
| 117 | } |
| 118 | |
| 119 | friend size_t qHash(const QRhiViewport &v, size_t seed = 0) noexcept |
| 120 | { |
| 121 | QtPrivate::QHashCombine hash(seed); |
| 122 | seed = hash(seed, v.m_rect[0]); |
| 123 | seed = hash(seed, v.m_rect[1]); |
| 124 | seed = hash(seed, v.m_rect[2]); |
| 125 | seed = hash(seed, v.m_rect[3]); |
| 126 | seed = hash(seed, v.m_minDepth); |
| 127 | seed = hash(seed, v.m_maxDepth); |
| 128 | return seed; |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | Q_DECLARE_TYPEINFO(QRhiViewport, Q_RELOCATABLE_TYPE); |
| 133 | |
| 134 | #ifndef QT_NO_DEBUG_STREAM |
| 135 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiViewport &); |
| 136 | #endif |
| 137 | |
| 138 | class Q_GUI_EXPORT QRhiScissor |
| 139 | { |
| 140 | public: |
| 141 | QRhiScissor() = default; |
| 142 | QRhiScissor(int x, int y, int w, int h); |
| 143 | |
| 144 | std::array<int, 4> scissor() const { return m_rect; } |
| 145 | void setScissor(int x, int y, int w, int h) { |
| 146 | m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h; |
| 147 | } |
| 148 | |
| 149 | private: |
| 150 | std::array<int, 4> m_rect { ._M_elems: { 0, 0, 0, 0 } }; |
| 151 | |
| 152 | friend bool operator==(const QRhiScissor &a, const QRhiScissor &b) noexcept |
| 153 | { |
| 154 | return a.m_rect == b.m_rect; |
| 155 | } |
| 156 | |
| 157 | friend bool operator!=(const QRhiScissor &a, const QRhiScissor &b) noexcept |
| 158 | { |
| 159 | return !(a == b); |
| 160 | } |
| 161 | |
| 162 | friend size_t qHash(const QRhiScissor &v, size_t seed = 0) noexcept |
| 163 | { |
| 164 | QtPrivate::QHashCombine hash(seed); |
| 165 | seed = hash(seed, v.m_rect[0]); |
| 166 | seed = hash(seed, v.m_rect[1]); |
| 167 | seed = hash(seed, v.m_rect[2]); |
| 168 | seed = hash(seed, v.m_rect[3]); |
| 169 | return seed; |
| 170 | } |
| 171 | }; |
| 172 | |
| 173 | Q_DECLARE_TYPEINFO(QRhiScissor, Q_RELOCATABLE_TYPE); |
| 174 | |
| 175 | #ifndef QT_NO_DEBUG_STREAM |
| 176 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiScissor &); |
| 177 | #endif |
| 178 | |
| 179 | class Q_GUI_EXPORT QRhiVertexInputBinding |
| 180 | { |
| 181 | public: |
| 182 | enum Classification { |
| 183 | PerVertex, |
| 184 | PerInstance |
| 185 | }; |
| 186 | |
| 187 | QRhiVertexInputBinding() = default; |
| 188 | QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, quint32 stepRate = 1); |
| 189 | |
| 190 | quint32 stride() const { return m_stride; } |
| 191 | void setStride(quint32 s) { m_stride = s; } |
| 192 | |
| 193 | Classification classification() const { return m_classification; } |
| 194 | void setClassification(Classification c) { m_classification = c; } |
| 195 | |
| 196 | quint32 instanceStepRate() const { return m_instanceStepRate; } |
| 197 | void setInstanceStepRate(quint32 rate) { m_instanceStepRate = rate; } |
| 198 | |
| 199 | private: |
| 200 | quint32 m_stride = 0; |
| 201 | Classification m_classification = PerVertex; |
| 202 | quint32 m_instanceStepRate = 1; |
| 203 | |
| 204 | friend bool operator==(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b) noexcept |
| 205 | { |
| 206 | return a.m_stride == b.m_stride |
| 207 | && a.m_classification == b.m_classification |
| 208 | && a.m_instanceStepRate == b.m_instanceStepRate; |
| 209 | } |
| 210 | |
| 211 | friend bool operator!=(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b) noexcept |
| 212 | { |
| 213 | return !(a == b); |
| 214 | } |
| 215 | |
| 216 | friend size_t qHash(const QRhiVertexInputBinding &v, size_t seed = 0) noexcept |
| 217 | { |
| 218 | QtPrivate::QHashCombine hash(seed); |
| 219 | seed = hash(seed, v.m_stride); |
| 220 | seed = hash(seed, v.m_classification); |
| 221 | seed = hash(seed, v.m_instanceStepRate); |
| 222 | return seed; |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | Q_DECLARE_TYPEINFO(QRhiVertexInputBinding, Q_RELOCATABLE_TYPE); |
| 227 | |
| 228 | #ifndef QT_NO_DEBUG_STREAM |
| 229 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputBinding &); |
| 230 | #endif |
| 231 | |
| 232 | class Q_GUI_EXPORT QRhiVertexInputAttribute |
| 233 | { |
| 234 | public: |
| 235 | enum Format { |
| 236 | Float4, |
| 237 | Float3, |
| 238 | Float2, |
| 239 | Float, |
| 240 | UNormByte4, |
| 241 | UNormByte2, |
| 242 | UNormByte, |
| 243 | UInt4, |
| 244 | UInt3, |
| 245 | UInt2, |
| 246 | UInt, |
| 247 | SInt4, |
| 248 | SInt3, |
| 249 | SInt2, |
| 250 | SInt, |
| 251 | Half4, |
| 252 | Half3, |
| 253 | Half2, |
| 254 | Half, |
| 255 | UShort4, |
| 256 | UShort3, |
| 257 | UShort2, |
| 258 | UShort, |
| 259 | SShort4, |
| 260 | SShort3, |
| 261 | SShort2, |
| 262 | SShort, |
| 263 | }; |
| 264 | |
| 265 | QRhiVertexInputAttribute() = default; |
| 266 | QRhiVertexInputAttribute(int binding, int location, Format format, quint32 offset, int matrixSlice = -1); |
| 267 | |
| 268 | int binding() const { return m_binding; } |
| 269 | void setBinding(int b) { m_binding = b; } |
| 270 | |
| 271 | int location() const { return m_location; } |
| 272 | void setLocation(int loc) { m_location = loc; } |
| 273 | |
| 274 | Format format() const { return m_format; } |
| 275 | void setFormat(Format f) { m_format = f; } |
| 276 | |
| 277 | quint32 offset() const { return m_offset; } |
| 278 | void setOffset(quint32 ofs) { m_offset = ofs; } |
| 279 | |
| 280 | int matrixSlice() const { return m_matrixSlice; } |
| 281 | void setMatrixSlice(int slice) { m_matrixSlice = slice; } |
| 282 | |
| 283 | private: |
| 284 | int m_binding = 0; |
| 285 | int m_location = 0; |
| 286 | Format m_format = Float4; |
| 287 | quint32 m_offset = 0; |
| 288 | int m_matrixSlice = -1; |
| 289 | |
| 290 | friend bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b) noexcept |
| 291 | { |
| 292 | return a.m_binding == b.m_binding |
| 293 | && a.m_location == b.m_location |
| 294 | && a.m_format == b.m_format |
| 295 | && a.m_offset == b.m_offset; |
| 296 | // matrixSlice excluded intentionally |
| 297 | } |
| 298 | |
| 299 | friend bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b) noexcept |
| 300 | { |
| 301 | return !(a == b); |
| 302 | } |
| 303 | |
| 304 | friend size_t qHash(const QRhiVertexInputAttribute &v, size_t seed = 0) noexcept |
| 305 | { |
| 306 | QtPrivate::QHashCombine hash(seed); |
| 307 | seed = hash(seed, v.m_binding); |
| 308 | seed = hash(seed, v.m_location); |
| 309 | seed = hash(seed, v.m_format); |
| 310 | seed = hash(seed, v.m_offset); |
| 311 | return seed; |
| 312 | } |
| 313 | }; |
| 314 | |
| 315 | Q_DECLARE_TYPEINFO(QRhiVertexInputAttribute, Q_RELOCATABLE_TYPE); |
| 316 | |
| 317 | #ifndef QT_NO_DEBUG_STREAM |
| 318 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputAttribute &); |
| 319 | #endif |
| 320 | |
| 321 | class Q_GUI_EXPORT QRhiVertexInputLayout |
| 322 | { |
| 323 | public: |
| 324 | QRhiVertexInputLayout() = default; |
| 325 | |
| 326 | void setBindings(std::initializer_list<QRhiVertexInputBinding> list) { m_bindings = list; } |
| 327 | template<typename InputIterator> |
| 328 | void setBindings(InputIterator first, InputIterator last) |
| 329 | { |
| 330 | m_bindings.clear(); |
| 331 | std::copy(first, last, std::back_inserter(x&: m_bindings)); |
| 332 | } |
| 333 | const QRhiVertexInputBinding *cbeginBindings() const { return m_bindings.cbegin(); } |
| 334 | const QRhiVertexInputBinding *cendBindings() const { return m_bindings.cend(); } |
| 335 | const QRhiVertexInputBinding *bindingAt(qsizetype index) const { return &m_bindings.at(idx: index); } |
| 336 | qsizetype bindingCount() const { return m_bindings.count(); } |
| 337 | |
| 338 | void setAttributes(std::initializer_list<QRhiVertexInputAttribute> list) { m_attributes = list; } |
| 339 | template<typename InputIterator> |
| 340 | void setAttributes(InputIterator first, InputIterator last) |
| 341 | { |
| 342 | m_attributes.clear(); |
| 343 | std::copy(first, last, std::back_inserter(x&: m_attributes)); |
| 344 | } |
| 345 | const QRhiVertexInputAttribute *cbeginAttributes() const { return m_attributes.cbegin(); } |
| 346 | const QRhiVertexInputAttribute *cendAttributes() const { return m_attributes.cend(); } |
| 347 | const QRhiVertexInputAttribute *attributeAt(qsizetype index) const { return &m_attributes.at(idx: index); } |
| 348 | qsizetype attributeCount() const { return m_attributes.count(); } |
| 349 | |
| 350 | private: |
| 351 | QVarLengthArray<QRhiVertexInputBinding, 8> m_bindings; |
| 352 | QVarLengthArray<QRhiVertexInputAttribute, 8> m_attributes; |
| 353 | |
| 354 | friend bool operator==(const QRhiVertexInputLayout &a, const QRhiVertexInputLayout &b) noexcept |
| 355 | { |
| 356 | return a.m_bindings == b.m_bindings && a.m_attributes == b.m_attributes; |
| 357 | } |
| 358 | |
| 359 | friend bool operator!=(const QRhiVertexInputLayout &a, const QRhiVertexInputLayout &b) noexcept |
| 360 | { |
| 361 | return !(a == b); |
| 362 | } |
| 363 | |
| 364 | friend size_t qHash(const QRhiVertexInputLayout &v, size_t seed = 0) noexcept |
| 365 | { |
| 366 | QtPrivate::QHashCombine hash(seed); |
| 367 | seed = hash(seed, v.m_bindings); |
| 368 | seed = hash(seed, v.m_attributes); |
| 369 | return seed; |
| 370 | } |
| 371 | |
| 372 | friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputLayout &); |
| 373 | }; |
| 374 | |
| 375 | #ifndef QT_NO_DEBUG_STREAM |
| 376 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputLayout &); |
| 377 | #endif |
| 378 | |
| 379 | class Q_GUI_EXPORT QRhiShaderStage |
| 380 | { |
| 381 | public: |
| 382 | enum Type { |
| 383 | Vertex, |
| 384 | TessellationControl, |
| 385 | TessellationEvaluation, |
| 386 | Geometry, |
| 387 | Fragment, |
| 388 | Compute |
| 389 | }; |
| 390 | |
| 391 | QRhiShaderStage() = default; |
| 392 | QRhiShaderStage(Type type, const QShader &shader, |
| 393 | QShader::Variant v = QShader::StandardShader); |
| 394 | |
| 395 | Type type() const { return m_type; } |
| 396 | void setType(Type t) { m_type = t; } |
| 397 | |
| 398 | QShader shader() const { return m_shader; } |
| 399 | void setShader(const QShader &s) { m_shader = s; } |
| 400 | |
| 401 | QShader::Variant shaderVariant() const { return m_shaderVariant; } |
| 402 | void setShaderVariant(QShader::Variant v) { m_shaderVariant = v; } |
| 403 | |
| 404 | private: |
| 405 | Type m_type = Vertex; |
| 406 | QShader m_shader; |
| 407 | QShader::Variant m_shaderVariant = QShader::StandardShader; |
| 408 | |
| 409 | friend bool operator==(const QRhiShaderStage &a, const QRhiShaderStage &b) noexcept |
| 410 | { |
| 411 | return a.m_type == b.m_type |
| 412 | && a.m_shader == b.m_shader |
| 413 | && a.m_shaderVariant == b.m_shaderVariant; |
| 414 | } |
| 415 | |
| 416 | friend bool operator!=(const QRhiShaderStage &a, const QRhiShaderStage &b) noexcept |
| 417 | { |
| 418 | return !(a == b); |
| 419 | } |
| 420 | |
| 421 | friend size_t qHash(const QRhiShaderStage &v, size_t seed = 0) noexcept |
| 422 | { |
| 423 | QtPrivate::QHashCombine hash(seed); |
| 424 | seed = hash(seed, v.m_type); |
| 425 | seed = hash(seed, v.m_shader); |
| 426 | seed = hash(seed, v.m_shaderVariant); |
| 427 | return seed; |
| 428 | } |
| 429 | }; |
| 430 | |
| 431 | Q_DECLARE_TYPEINFO(QRhiShaderStage, Q_RELOCATABLE_TYPE); |
| 432 | |
| 433 | #ifndef QT_NO_DEBUG_STREAM |
| 434 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderStage &); |
| 435 | #endif |
| 436 | |
| 437 | using QRhiGraphicsShaderStage = QRhiShaderStage; |
| 438 | |
| 439 | class Q_GUI_EXPORT QRhiShaderResourceBinding |
| 440 | { |
| 441 | public: |
| 442 | enum Type { |
| 443 | UniformBuffer, |
| 444 | SampledTexture, |
| 445 | Texture, |
| 446 | Sampler, |
| 447 | ImageLoad, |
| 448 | ImageStore, |
| 449 | ImageLoadStore, |
| 450 | BufferLoad, |
| 451 | BufferStore, |
| 452 | BufferLoadStore |
| 453 | }; |
| 454 | |
| 455 | enum StageFlag { |
| 456 | VertexStage = 1 << 0, |
| 457 | TessellationControlStage = 1 << 1, |
| 458 | TessellationEvaluationStage = 1 << 2, |
| 459 | GeometryStage = 1 << 3, |
| 460 | FragmentStage = 1 << 4, |
| 461 | ComputeStage = 1 << 5 |
| 462 | }; |
| 463 | Q_DECLARE_FLAGS(StageFlags, StageFlag) |
| 464 | |
| 465 | QRhiShaderResourceBinding() = default; |
| 466 | |
| 467 | bool isLayoutCompatible(const QRhiShaderResourceBinding &other) const; |
| 468 | |
| 469 | static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf); |
| 470 | static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
| 471 | static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, quint32 size); |
| 472 | |
| 473 | static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler); |
| 474 | |
| 475 | struct TextureAndSampler { |
| 476 | QRhiTexture *tex; |
| 477 | QRhiSampler *sampler; |
| 478 | }; |
| 479 | static QRhiShaderResourceBinding sampledTextures(int binding, StageFlags stage, int count, const TextureAndSampler *texSamplers); |
| 480 | |
| 481 | static QRhiShaderResourceBinding texture(int binding, StageFlags stage, QRhiTexture *tex); |
| 482 | static QRhiShaderResourceBinding textures(int binding, StageFlags stage, int count, QRhiTexture **tex); |
| 483 | static QRhiShaderResourceBinding sampler(int binding, StageFlags stage, QRhiSampler *sampler); |
| 484 | |
| 485 | static QRhiShaderResourceBinding imageLoad(int binding, StageFlags stage, QRhiTexture *tex, int level); |
| 486 | static QRhiShaderResourceBinding imageStore(int binding, StageFlags stage, QRhiTexture *tex, int level); |
| 487 | static QRhiShaderResourceBinding imageLoadStore(int binding, StageFlags stage, QRhiTexture *tex, int level); |
| 488 | |
| 489 | static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf); |
| 490 | static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
| 491 | static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf); |
| 492 | static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
| 493 | static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf); |
| 494 | static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
| 495 | |
| 496 | struct Data |
| 497 | { |
| 498 | int binding; |
| 499 | QRhiShaderResourceBinding::StageFlags stage; |
| 500 | QRhiShaderResourceBinding::Type type; |
| 501 | struct UniformBufferData { |
| 502 | QRhiBuffer *buf; |
| 503 | quint32 offset; |
| 504 | quint32 maybeSize; |
| 505 | bool hasDynamicOffset; |
| 506 | }; |
| 507 | static constexpr int MAX_TEX_SAMPLER_ARRAY_SIZE = 16; |
| 508 | struct TextureAndOrSamplerData { |
| 509 | int count; |
| 510 | TextureAndSampler texSamplers[MAX_TEX_SAMPLER_ARRAY_SIZE]; |
| 511 | }; |
| 512 | struct StorageImageData { |
| 513 | QRhiTexture *tex; |
| 514 | int level; |
| 515 | }; |
| 516 | struct StorageBufferData { |
| 517 | QRhiBuffer *buf; |
| 518 | quint32 offset; |
| 519 | quint32 maybeSize; |
| 520 | }; |
| 521 | union { |
| 522 | UniformBufferData ubuf; |
| 523 | TextureAndOrSamplerData stex; |
| 524 | StorageImageData simage; |
| 525 | StorageBufferData sbuf; |
| 526 | } u; |
| 527 | |
| 528 | int arraySize() const |
| 529 | { |
| 530 | return type == QRhiShaderResourceBinding::SampledTexture || type == QRhiShaderResourceBinding::Texture |
| 531 | ? u.stex.count |
| 532 | : 1; |
| 533 | } |
| 534 | |
| 535 | template<typename Output> |
| 536 | Output serialize(Output dst) const |
| 537 | { |
| 538 | // must write out exactly LAYOUT_DESC_ENTRIES_PER_BINDING elements here |
| 539 | *dst++ = quint32(binding); |
| 540 | *dst++ = quint32(stage); |
| 541 | *dst++ = quint32(type); |
| 542 | *dst++ = quint32(arraySize()); |
| 543 | return dst; |
| 544 | } |
| 545 | }; |
| 546 | |
| 547 | static constexpr int LAYOUT_DESC_ENTRIES_PER_BINDING = 4; |
| 548 | |
| 549 | template<typename Output> |
| 550 | static void serializeLayoutDescription(const QRhiShaderResourceBinding *first, |
| 551 | const QRhiShaderResourceBinding *last, |
| 552 | Output dst) |
| 553 | { |
| 554 | while (first != last) { |
| 555 | dst = first->d.serialize(dst); |
| 556 | ++first; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | private: |
| 561 | Data d; |
| 562 | friend class QRhiImplementation; |
| 563 | }; |
| 564 | |
| 565 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags) |
| 566 | |
| 567 | Q_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_PRIMITIVE_TYPE); |
| 568 | |
| 569 | Q_GUI_EXPORT bool operator==(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) noexcept; |
| 570 | Q_GUI_EXPORT bool operator!=(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) noexcept; |
| 571 | Q_GUI_EXPORT size_t qHash(const QRhiShaderResourceBinding &b, size_t seed = 0) noexcept; |
| 572 | #ifndef QT_NO_DEBUG_STREAM |
| 573 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBinding &); |
| 574 | #endif |
| 575 | |
| 576 | class Q_GUI_EXPORT QRhiColorAttachment |
| 577 | { |
| 578 | public: |
| 579 | QRhiColorAttachment() = default; |
| 580 | QRhiColorAttachment(QRhiTexture *texture); |
| 581 | QRhiColorAttachment(QRhiRenderBuffer *renderBuffer); |
| 582 | |
| 583 | QRhiTexture *texture() const { return m_texture; } |
| 584 | void setTexture(QRhiTexture *tex) { m_texture = tex; } |
| 585 | |
| 586 | QRhiRenderBuffer *renderBuffer() const { return m_renderBuffer; } |
| 587 | void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; } |
| 588 | |
| 589 | int layer() const { return m_layer; } |
| 590 | void setLayer(int layer) { m_layer = layer; } |
| 591 | |
| 592 | int level() const { return m_level; } |
| 593 | void setLevel(int level) { m_level = level; } |
| 594 | |
| 595 | QRhiTexture *resolveTexture() const { return m_resolveTexture; } |
| 596 | void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; } |
| 597 | |
| 598 | int resolveLayer() const { return m_resolveLayer; } |
| 599 | void setResolveLayer(int layer) { m_resolveLayer = layer; } |
| 600 | |
| 601 | int resolveLevel() const { return m_resolveLevel; } |
| 602 | void setResolveLevel(int level) { m_resolveLevel = level; } |
| 603 | |
| 604 | int multiViewCount() const { return m_multiViewCount; } |
| 605 | void setMultiViewCount(int count) { m_multiViewCount = count; } |
| 606 | |
| 607 | private: |
| 608 | QRhiTexture *m_texture = nullptr; |
| 609 | QRhiRenderBuffer *m_renderBuffer = nullptr; |
| 610 | int m_layer = 0; |
| 611 | int m_level = 0; |
| 612 | QRhiTexture *m_resolveTexture = nullptr; |
| 613 | int m_resolveLayer = 0; |
| 614 | int m_resolveLevel = 0; |
| 615 | int m_multiViewCount = 0; |
| 616 | }; |
| 617 | |
| 618 | Q_DECLARE_TYPEINFO(QRhiColorAttachment, Q_RELOCATABLE_TYPE); |
| 619 | |
| 620 | class Q_GUI_EXPORT QRhiTextureRenderTargetDescription |
| 621 | { |
| 622 | public: |
| 623 | QRhiTextureRenderTargetDescription() = default; |
| 624 | QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment); |
| 625 | QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer); |
| 626 | QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture); |
| 627 | |
| 628 | void setColorAttachments(std::initializer_list<QRhiColorAttachment> list) { m_colorAttachments = list; } |
| 629 | template<typename InputIterator> |
| 630 | void setColorAttachments(InputIterator first, InputIterator last) |
| 631 | { |
| 632 | m_colorAttachments.clear(); |
| 633 | std::copy(first, last, std::back_inserter(x&: m_colorAttachments)); |
| 634 | } |
| 635 | const QRhiColorAttachment *cbeginColorAttachments() const { return m_colorAttachments.cbegin(); } |
| 636 | const QRhiColorAttachment *cendColorAttachments() const { return m_colorAttachments.cend(); } |
| 637 | const QRhiColorAttachment *colorAttachmentAt(qsizetype index) const { return &m_colorAttachments.at(idx: index); } |
| 638 | qsizetype colorAttachmentCount() const { return m_colorAttachments.count(); } |
| 639 | |
| 640 | QRhiRenderBuffer *depthStencilBuffer() const { return m_depthStencilBuffer; } |
| 641 | void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; } |
| 642 | |
| 643 | QRhiTexture *depthTexture() const { return m_depthTexture; } |
| 644 | void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; } |
| 645 | |
| 646 | QRhiTexture *depthResolveTexture() const { return m_depthResolveTexture; } |
| 647 | void setDepthResolveTexture(QRhiTexture *tex) { m_depthResolveTexture = tex; } |
| 648 | |
| 649 | QRhiShadingRateMap *shadingRateMap() const { return m_shadingRateMap; } |
| 650 | void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; } |
| 651 | |
| 652 | private: |
| 653 | QVarLengthArray<QRhiColorAttachment, 8> m_colorAttachments; |
| 654 | QRhiRenderBuffer *m_depthStencilBuffer = nullptr; |
| 655 | QRhiTexture *m_depthTexture = nullptr; |
| 656 | QRhiTexture *m_depthResolveTexture = nullptr; |
| 657 | QRhiShadingRateMap *m_shadingRateMap = nullptr; |
| 658 | }; |
| 659 | |
| 660 | class Q_GUI_EXPORT QRhiTextureSubresourceUploadDescription |
| 661 | { |
| 662 | public: |
| 663 | QRhiTextureSubresourceUploadDescription() = default; |
| 664 | explicit QRhiTextureSubresourceUploadDescription(const QImage &image); |
| 665 | QRhiTextureSubresourceUploadDescription(const void *data, quint32 size); |
| 666 | explicit QRhiTextureSubresourceUploadDescription(const QByteArray &data); |
| 667 | |
| 668 | QImage image() const { return m_image; } |
| 669 | void setImage(const QImage &image) { m_image = image; } |
| 670 | |
| 671 | QByteArray data() const { return m_data; } |
| 672 | void setData(const QByteArray &data) { m_data = data; } |
| 673 | |
| 674 | quint32 dataStride() const { return m_dataStride; } |
| 675 | void setDataStride(quint32 stride) { m_dataStride = stride; } |
| 676 | |
| 677 | QPoint destinationTopLeft() const { return m_destinationTopLeft; } |
| 678 | void setDestinationTopLeft(const QPoint &p) { m_destinationTopLeft = p; } |
| 679 | |
| 680 | QSize sourceSize() const { return m_sourceSize; } |
| 681 | void setSourceSize(const QSize &size) { m_sourceSize = size; } |
| 682 | |
| 683 | QPoint sourceTopLeft() const { return m_sourceTopLeft; } |
| 684 | void setSourceTopLeft(const QPoint &p) { m_sourceTopLeft = p; } |
| 685 | |
| 686 | private: |
| 687 | QImage m_image; |
| 688 | QByteArray m_data; |
| 689 | quint32 m_dataStride = 0; |
| 690 | QPoint m_destinationTopLeft; |
| 691 | QSize m_sourceSize; |
| 692 | QPoint m_sourceTopLeft; |
| 693 | }; |
| 694 | |
| 695 | Q_DECLARE_TYPEINFO(QRhiTextureSubresourceUploadDescription, Q_RELOCATABLE_TYPE); |
| 696 | |
| 697 | class Q_GUI_EXPORT QRhiTextureUploadEntry |
| 698 | { |
| 699 | public: |
| 700 | QRhiTextureUploadEntry() = default; |
| 701 | QRhiTextureUploadEntry(int layer, int level, const QRhiTextureSubresourceUploadDescription &desc); |
| 702 | |
| 703 | int layer() const { return m_layer; } |
| 704 | void setLayer(int layer) { m_layer = layer; } |
| 705 | |
| 706 | int level() const { return m_level; } |
| 707 | void setLevel(int level) { m_level = level; } |
| 708 | |
| 709 | QRhiTextureSubresourceUploadDescription description() const { return m_desc; } |
| 710 | void setDescription(const QRhiTextureSubresourceUploadDescription &desc) { m_desc = desc; } |
| 711 | |
| 712 | private: |
| 713 | int m_layer = 0; |
| 714 | int m_level = 0; |
| 715 | QRhiTextureSubresourceUploadDescription m_desc; |
| 716 | }; |
| 717 | |
| 718 | Q_DECLARE_TYPEINFO(QRhiTextureUploadEntry, Q_RELOCATABLE_TYPE); |
| 719 | |
| 720 | class Q_GUI_EXPORT QRhiTextureUploadDescription |
| 721 | { |
| 722 | public: |
| 723 | QRhiTextureUploadDescription() = default; |
| 724 | QRhiTextureUploadDescription(const QRhiTextureUploadEntry &entry); |
| 725 | QRhiTextureUploadDescription(std::initializer_list<QRhiTextureUploadEntry> list); |
| 726 | |
| 727 | void setEntries(std::initializer_list<QRhiTextureUploadEntry> list) { m_entries = list; } |
| 728 | template<typename InputIterator> |
| 729 | void setEntries(InputIterator first, InputIterator last) |
| 730 | { |
| 731 | m_entries.clear(); |
| 732 | std::copy(first, last, std::back_inserter(x&: m_entries)); |
| 733 | } |
| 734 | const QRhiTextureUploadEntry *cbeginEntries() const { return m_entries.cbegin(); } |
| 735 | const QRhiTextureUploadEntry *cendEntries() const { return m_entries.cend(); } |
| 736 | const QRhiTextureUploadEntry *entryAt(qsizetype index) const { return &m_entries.at(idx: index); } |
| 737 | qsizetype entryCount() const { return m_entries.count(); } |
| 738 | |
| 739 | private: |
| 740 | QVarLengthArray<QRhiTextureUploadEntry, 16> m_entries; |
| 741 | }; |
| 742 | |
| 743 | class Q_GUI_EXPORT QRhiTextureCopyDescription |
| 744 | { |
| 745 | public: |
| 746 | QRhiTextureCopyDescription() = default; |
| 747 | |
| 748 | QSize pixelSize() const { return m_pixelSize; } |
| 749 | void setPixelSize(const QSize &sz) { m_pixelSize = sz; } |
| 750 | |
| 751 | int sourceLayer() const { return m_sourceLayer; } |
| 752 | void setSourceLayer(int layer) { m_sourceLayer = layer; } |
| 753 | |
| 754 | int sourceLevel() const { return m_sourceLevel; } |
| 755 | void setSourceLevel(int level) { m_sourceLevel = level; } |
| 756 | |
| 757 | QPoint sourceTopLeft() const { return m_sourceTopLeft; } |
| 758 | void setSourceTopLeft(const QPoint &p) { m_sourceTopLeft = p; } |
| 759 | |
| 760 | int destinationLayer() const { return m_destinationLayer; } |
| 761 | void setDestinationLayer(int layer) { m_destinationLayer = layer; } |
| 762 | |
| 763 | int destinationLevel() const { return m_destinationLevel; } |
| 764 | void setDestinationLevel(int level) { m_destinationLevel = level; } |
| 765 | |
| 766 | QPoint destinationTopLeft() const { return m_destinationTopLeft; } |
| 767 | void setDestinationTopLeft(const QPoint &p) { m_destinationTopLeft = p; } |
| 768 | |
| 769 | private: |
| 770 | QSize m_pixelSize; |
| 771 | int m_sourceLayer = 0; |
| 772 | int m_sourceLevel = 0; |
| 773 | QPoint m_sourceTopLeft; |
| 774 | int m_destinationLayer = 0; |
| 775 | int m_destinationLevel = 0; |
| 776 | QPoint m_destinationTopLeft; |
| 777 | }; |
| 778 | |
| 779 | Q_DECLARE_TYPEINFO(QRhiTextureCopyDescription, Q_RELOCATABLE_TYPE); |
| 780 | |
| 781 | class Q_GUI_EXPORT QRhiReadbackDescription |
| 782 | { |
| 783 | public: |
| 784 | QRhiReadbackDescription() = default; |
| 785 | QRhiReadbackDescription(QRhiTexture *texture); |
| 786 | |
| 787 | QRhiTexture *texture() const { return m_texture; } |
| 788 | void setTexture(QRhiTexture *tex) { m_texture = tex; } |
| 789 | |
| 790 | int layer() const { return m_layer; } |
| 791 | void setLayer(int layer) { m_layer = layer; } |
| 792 | |
| 793 | int level() const { return m_level; } |
| 794 | void setLevel(int level) { m_level = level; } |
| 795 | |
| 796 | QRect rect() const { return m_rect; } |
| 797 | void setRect(const QRect &rectangle) { m_rect = rectangle; } |
| 798 | |
| 799 | private: |
| 800 | QRhiTexture *m_texture = nullptr; |
| 801 | int m_layer = 0; |
| 802 | int m_level = 0; |
| 803 | QRect m_rect; |
| 804 | }; |
| 805 | |
| 806 | Q_DECLARE_TYPEINFO(QRhiReadbackDescription, Q_RELOCATABLE_TYPE); |
| 807 | |
| 808 | struct Q_GUI_EXPORT QRhiNativeHandles |
| 809 | { |
| 810 | }; |
| 811 | |
| 812 | class Q_GUI_EXPORT QRhiResource |
| 813 | { |
| 814 | public: |
| 815 | enum Type { |
| 816 | Buffer, |
| 817 | Texture, |
| 818 | Sampler, |
| 819 | RenderBuffer, |
| 820 | RenderPassDescriptor, |
| 821 | SwapChainRenderTarget, |
| 822 | TextureRenderTarget, |
| 823 | ShaderResourceBindings, |
| 824 | GraphicsPipeline, |
| 825 | SwapChain, |
| 826 | ComputePipeline, |
| 827 | CommandBuffer, |
| 828 | ShadingRateMap |
| 829 | }; |
| 830 | |
| 831 | virtual ~QRhiResource(); |
| 832 | |
| 833 | virtual Type resourceType() const = 0; |
| 834 | |
| 835 | virtual void destroy() = 0; |
| 836 | |
| 837 | void deleteLater(); |
| 838 | |
| 839 | QByteArray name() const; |
| 840 | void setName(const QByteArray &name); |
| 841 | |
| 842 | quint64 globalResourceId() const; |
| 843 | |
| 844 | QRhi *rhi() const; |
| 845 | |
| 846 | protected: |
| 847 | QRhiResource(QRhiImplementation *rhi); |
| 848 | Q_DISABLE_COPY(QRhiResource) |
| 849 | friend class QRhiImplementation; |
| 850 | QRhiImplementation *m_rhi = nullptr; |
| 851 | quint64 m_id; |
| 852 | QByteArray m_objectName; |
| 853 | }; |
| 854 | |
| 855 | class Q_GUI_EXPORT QRhiBuffer : public QRhiResource |
| 856 | { |
| 857 | public: |
| 858 | enum Type { |
| 859 | Immutable, |
| 860 | Static, |
| 861 | Dynamic |
| 862 | }; |
| 863 | |
| 864 | enum UsageFlag { |
| 865 | VertexBuffer = 1 << 0, |
| 866 | IndexBuffer = 1 << 1, |
| 867 | UniformBuffer = 1 << 2, |
| 868 | StorageBuffer = 1 << 3 |
| 869 | }; |
| 870 | Q_DECLARE_FLAGS(UsageFlags, UsageFlag) |
| 871 | |
| 872 | struct NativeBuffer { |
| 873 | const void *objects[3]; |
| 874 | int slotCount; |
| 875 | }; |
| 876 | |
| 877 | QRhiResource::Type resourceType() const override; |
| 878 | |
| 879 | Type type() const { return m_type; } |
| 880 | void setType(Type t) { m_type = t; } |
| 881 | |
| 882 | UsageFlags usage() const { return m_usage; } |
| 883 | void setUsage(UsageFlags u) { m_usage = u; } |
| 884 | |
| 885 | quint32 size() const { return m_size; } |
| 886 | void setSize(quint32 sz) { m_size = sz; } |
| 887 | |
| 888 | virtual bool create() = 0; |
| 889 | |
| 890 | virtual NativeBuffer nativeBuffer(); |
| 891 | |
| 892 | virtual char *beginFullDynamicBufferUpdateForCurrentFrame(); |
| 893 | virtual void endFullDynamicBufferUpdateForCurrentFrame(); |
| 894 | virtual void fullDynamicBufferUpdateForCurrentFrame(const void *data, quint32 size = 0); |
| 895 | |
| 896 | protected: |
| 897 | QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_); |
| 898 | Type m_type; |
| 899 | UsageFlags m_usage; |
| 900 | quint32 m_size; |
| 901 | }; |
| 902 | |
| 903 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags) |
| 904 | |
| 905 | class Q_GUI_EXPORT QRhiTexture : public QRhiResource |
| 906 | { |
| 907 | public: |
| 908 | enum Flag { |
| 909 | RenderTarget = 1 << 0, |
| 910 | CubeMap = 1 << 2, |
| 911 | MipMapped = 1 << 3, |
| 912 | sRGB = 1 << 4, |
| 913 | UsedAsTransferSource = 1 << 5, |
| 914 | UsedWithGenerateMips = 1 << 6, |
| 915 | UsedWithLoadStore = 1 << 7, |
| 916 | UsedAsCompressedAtlas = 1 << 8, |
| 917 | ExternalOES = 1 << 9, |
| 918 | ThreeDimensional = 1 << 10, |
| 919 | TextureRectangleGL = 1 << 11, |
| 920 | TextureArray = 1 << 12, |
| 921 | OneDimensional = 1 << 13, |
| 922 | UsedAsShadingRateMap = 1 << 14 |
| 923 | }; |
| 924 | Q_DECLARE_FLAGS(Flags, Flag) |
| 925 | |
| 926 | enum Format { |
| 927 | UnknownFormat, |
| 928 | |
| 929 | RGBA8, |
| 930 | BGRA8, |
| 931 | R8, |
| 932 | RG8, |
| 933 | R16, |
| 934 | RG16, |
| 935 | RED_OR_ALPHA8, |
| 936 | |
| 937 | RGBA16F, |
| 938 | RGBA32F, |
| 939 | R16F, |
| 940 | R32F, |
| 941 | |
| 942 | RGB10A2, |
| 943 | |
| 944 | R8SI, |
| 945 | R32SI, |
| 946 | RG32SI, |
| 947 | RGBA32SI, |
| 948 | |
| 949 | R8UI, |
| 950 | R32UI, |
| 951 | RG32UI, |
| 952 | RGBA32UI, |
| 953 | |
| 954 | D16, |
| 955 | D24, |
| 956 | D24S8, |
| 957 | D32F, |
| 958 | D32FS8, |
| 959 | |
| 960 | BC1, |
| 961 | BC2, |
| 962 | BC3, |
| 963 | BC4, |
| 964 | BC5, |
| 965 | BC6H, |
| 966 | BC7, |
| 967 | |
| 968 | ETC2_RGB8, |
| 969 | ETC2_RGB8A1, |
| 970 | ETC2_RGBA8, |
| 971 | |
| 972 | ASTC_4x4, |
| 973 | ASTC_5x4, |
| 974 | ASTC_5x5, |
| 975 | ASTC_6x5, |
| 976 | ASTC_6x6, |
| 977 | ASTC_8x5, |
| 978 | ASTC_8x6, |
| 979 | ASTC_8x8, |
| 980 | ASTC_10x5, |
| 981 | ASTC_10x6, |
| 982 | ASTC_10x8, |
| 983 | ASTC_10x10, |
| 984 | ASTC_12x10, |
| 985 | ASTC_12x12 |
| 986 | }; |
| 987 | |
| 988 | struct NativeTexture { |
| 989 | quint64 object; |
| 990 | int layout; // or state |
| 991 | }; |
| 992 | |
| 993 | QRhiResource::Type resourceType() const override; |
| 994 | |
| 995 | Format format() const { return m_format; } |
| 996 | void setFormat(Format fmt) { m_format = fmt; } |
| 997 | |
| 998 | QSize pixelSize() const { return m_pixelSize; } |
| 999 | void setPixelSize(const QSize &sz) { m_pixelSize = sz; } |
| 1000 | |
| 1001 | int depth() const { return m_depth; } |
| 1002 | void setDepth(int depth) { m_depth = depth; } |
| 1003 | |
| 1004 | int arraySize() const { return m_arraySize; } |
| 1005 | void setArraySize(int arraySize) { m_arraySize = arraySize; } |
| 1006 | |
| 1007 | int arrayRangeStart() const { return m_arrayRangeStart; } |
| 1008 | int arrayRangeLength() const { return m_arrayRangeLength; } |
| 1009 | void setArrayRange(int startIndex, int count) |
| 1010 | { |
| 1011 | m_arrayRangeStart = startIndex; |
| 1012 | m_arrayRangeLength = count; |
| 1013 | } |
| 1014 | |
| 1015 | Flags flags() const { return m_flags; } |
| 1016 | void setFlags(Flags f) { m_flags = f; } |
| 1017 | |
| 1018 | int sampleCount() const { return m_sampleCount; } |
| 1019 | void setSampleCount(int s) { m_sampleCount = s; } |
| 1020 | |
| 1021 | struct ViewFormat { |
| 1022 | QRhiTexture::Format format; |
| 1023 | bool srgb; |
| 1024 | }; |
| 1025 | ViewFormat readViewFormat() const { return m_readViewFormat; } |
| 1026 | void setReadViewFormat(const ViewFormat &fmt) { m_readViewFormat = fmt; } |
| 1027 | ViewFormat writeViewFormat() const { return m_writeViewFormat; } |
| 1028 | void setWriteViewFormat(const ViewFormat &fmt) { m_writeViewFormat = fmt; } |
| 1029 | |
| 1030 | virtual bool create() = 0; |
| 1031 | virtual NativeTexture nativeTexture(); |
| 1032 | virtual bool createFrom(NativeTexture src); |
| 1033 | virtual void setNativeLayout(int layout); |
| 1034 | |
| 1035 | protected: |
| 1036 | QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, int depth_, |
| 1037 | int arraySize_, int sampleCount_, Flags flags_); |
| 1038 | Format m_format; |
| 1039 | QSize m_pixelSize; |
| 1040 | int m_depth; |
| 1041 | int m_arraySize; |
| 1042 | int m_sampleCount; |
| 1043 | Flags m_flags; |
| 1044 | int m_arrayRangeStart = -1; |
| 1045 | int m_arrayRangeLength = -1; |
| 1046 | ViewFormat m_readViewFormat = { .format: UnknownFormat, .srgb: false }; |
| 1047 | ViewFormat m_writeViewFormat = { .format: UnknownFormat, .srgb: false }; |
| 1048 | }; |
| 1049 | |
| 1050 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags) |
| 1051 | |
| 1052 | class Q_GUI_EXPORT QRhiSampler : public QRhiResource |
| 1053 | { |
| 1054 | public: |
| 1055 | enum Filter { |
| 1056 | None, |
| 1057 | Nearest, |
| 1058 | Linear |
| 1059 | }; |
| 1060 | |
| 1061 | enum AddressMode { |
| 1062 | Repeat, |
| 1063 | ClampToEdge, |
| 1064 | Mirror, |
| 1065 | }; |
| 1066 | |
| 1067 | enum CompareOp { |
| 1068 | Never, |
| 1069 | Less, |
| 1070 | Equal, |
| 1071 | LessOrEqual, |
| 1072 | Greater, |
| 1073 | NotEqual, |
| 1074 | GreaterOrEqual, |
| 1075 | Always |
| 1076 | }; |
| 1077 | |
| 1078 | QRhiResource::Type resourceType() const override; |
| 1079 | |
| 1080 | Filter magFilter() const { return m_magFilter; } |
| 1081 | void setMagFilter(Filter f) { m_magFilter = f; } |
| 1082 | |
| 1083 | Filter minFilter() const { return m_minFilter; } |
| 1084 | void setMinFilter(Filter f) { m_minFilter = f; } |
| 1085 | |
| 1086 | Filter mipmapMode() const { return m_mipmapMode; } |
| 1087 | void setMipmapMode(Filter f) { m_mipmapMode = f; } |
| 1088 | |
| 1089 | AddressMode addressU() const { return m_addressU; } |
| 1090 | void setAddressU(AddressMode mode) { m_addressU = mode; } |
| 1091 | |
| 1092 | AddressMode addressV() const { return m_addressV; } |
| 1093 | void setAddressV(AddressMode mode) { m_addressV = mode; } |
| 1094 | |
| 1095 | AddressMode addressW() const { return m_addressW; } |
| 1096 | void setAddressW(AddressMode mode) { m_addressW = mode; } |
| 1097 | |
| 1098 | CompareOp textureCompareOp() const { return m_compareOp; } |
| 1099 | void setTextureCompareOp(CompareOp op) { m_compareOp = op; } |
| 1100 | |
| 1101 | virtual bool create() = 0; |
| 1102 | |
| 1103 | protected: |
| 1104 | QRhiSampler(QRhiImplementation *rhi, |
| 1105 | Filter magFilter_, Filter minFilter_, Filter mipmapMode_, |
| 1106 | AddressMode u_, AddressMode v_, AddressMode w_); |
| 1107 | Filter m_magFilter; |
| 1108 | Filter m_minFilter; |
| 1109 | Filter m_mipmapMode; |
| 1110 | AddressMode m_addressU; |
| 1111 | AddressMode m_addressV; |
| 1112 | AddressMode m_addressW; |
| 1113 | CompareOp m_compareOp; |
| 1114 | }; |
| 1115 | |
| 1116 | class Q_GUI_EXPORT QRhiRenderBuffer : public QRhiResource |
| 1117 | { |
| 1118 | public: |
| 1119 | enum Type { |
| 1120 | DepthStencil, |
| 1121 | Color |
| 1122 | }; |
| 1123 | |
| 1124 | enum Flag { |
| 1125 | UsedWithSwapChainOnly = 1 << 0 |
| 1126 | }; |
| 1127 | Q_DECLARE_FLAGS(Flags, Flag) |
| 1128 | |
| 1129 | struct NativeRenderBuffer { |
| 1130 | quint64 object; |
| 1131 | }; |
| 1132 | |
| 1133 | QRhiResource::Type resourceType() const override; |
| 1134 | |
| 1135 | Type type() const { return m_type; } |
| 1136 | void setType(Type t) { m_type = t; } |
| 1137 | |
| 1138 | QSize pixelSize() const { return m_pixelSize; } |
| 1139 | void setPixelSize(const QSize &sz) { m_pixelSize = sz; } |
| 1140 | |
| 1141 | int sampleCount() const { return m_sampleCount; } |
| 1142 | void setSampleCount(int s) { m_sampleCount = s; } |
| 1143 | |
| 1144 | Flags flags() const { return m_flags; } |
| 1145 | void setFlags(Flags f) { m_flags = f; } |
| 1146 | |
| 1147 | virtual bool create() = 0; |
| 1148 | virtual bool createFrom(NativeRenderBuffer src); |
| 1149 | |
| 1150 | virtual QRhiTexture::Format backingFormat() const = 0; |
| 1151 | |
| 1152 | protected: |
| 1153 | QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_, |
| 1154 | int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_); |
| 1155 | Type m_type; |
| 1156 | QSize m_pixelSize; |
| 1157 | int m_sampleCount; |
| 1158 | Flags m_flags; |
| 1159 | QRhiTexture::Format m_backingFormatHint; |
| 1160 | }; |
| 1161 | |
| 1162 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags) |
| 1163 | |
| 1164 | class Q_GUI_EXPORT QRhiShadingRateMap : public QRhiResource |
| 1165 | { |
| 1166 | public: |
| 1167 | struct NativeShadingRateMap { |
| 1168 | quint64 object; |
| 1169 | }; |
| 1170 | |
| 1171 | QRhiResource::Type resourceType() const override; |
| 1172 | |
| 1173 | virtual bool createFrom(NativeShadingRateMap src); |
| 1174 | virtual bool createFrom(QRhiTexture *src); |
| 1175 | |
| 1176 | protected: |
| 1177 | QRhiShadingRateMap(QRhiImplementation *rhi); |
| 1178 | }; |
| 1179 | |
| 1180 | class Q_GUI_EXPORT QRhiRenderPassDescriptor : public QRhiResource |
| 1181 | { |
| 1182 | public: |
| 1183 | QRhiResource::Type resourceType() const override; |
| 1184 | |
| 1185 | virtual bool isCompatible(const QRhiRenderPassDescriptor *other) const = 0; |
| 1186 | virtual const QRhiNativeHandles *nativeHandles(); |
| 1187 | |
| 1188 | virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() const = 0; |
| 1189 | |
| 1190 | virtual QVector<quint32> serializedFormat() const = 0; |
| 1191 | |
| 1192 | protected: |
| 1193 | QRhiRenderPassDescriptor(QRhiImplementation *rhi); |
| 1194 | }; |
| 1195 | |
| 1196 | class Q_GUI_EXPORT QRhiRenderTarget : public QRhiResource |
| 1197 | { |
| 1198 | public: |
| 1199 | virtual QSize pixelSize() const = 0; |
| 1200 | virtual float devicePixelRatio() const = 0; |
| 1201 | virtual int sampleCount() const = 0; |
| 1202 | |
| 1203 | QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } |
| 1204 | void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } |
| 1205 | |
| 1206 | protected: |
| 1207 | QRhiRenderTarget(QRhiImplementation *rhi); |
| 1208 | QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; |
| 1209 | }; |
| 1210 | |
| 1211 | class Q_GUI_EXPORT QRhiSwapChainRenderTarget : public QRhiRenderTarget |
| 1212 | { |
| 1213 | public: |
| 1214 | QRhiResource::Type resourceType() const override; |
| 1215 | QRhiSwapChain *swapChain() const { return m_swapchain; } |
| 1216 | |
| 1217 | protected: |
| 1218 | QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_); |
| 1219 | QRhiSwapChain *m_swapchain; |
| 1220 | }; |
| 1221 | |
| 1222 | class Q_GUI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget |
| 1223 | { |
| 1224 | public: |
| 1225 | enum Flag { |
| 1226 | PreserveColorContents = 1 << 0, |
| 1227 | PreserveDepthStencilContents = 1 << 1, |
| 1228 | DoNotStoreDepthStencilContents = 1 << 2 |
| 1229 | }; |
| 1230 | Q_DECLARE_FLAGS(Flags, Flag) |
| 1231 | |
| 1232 | QRhiResource::Type resourceType() const override; |
| 1233 | |
| 1234 | QRhiTextureRenderTargetDescription description() const { return m_desc; } |
| 1235 | void setDescription(const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; } |
| 1236 | |
| 1237 | Flags flags() const { return m_flags; } |
| 1238 | void setFlags(Flags f) { m_flags = f; } |
| 1239 | |
| 1240 | virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0; |
| 1241 | |
| 1242 | virtual bool create() = 0; |
| 1243 | |
| 1244 | protected: |
| 1245 | QRhiTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc_, Flags flags_); |
| 1246 | QRhiTextureRenderTargetDescription m_desc; |
| 1247 | Flags m_flags; |
| 1248 | }; |
| 1249 | |
| 1250 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags) |
| 1251 | |
| 1252 | class Q_GUI_EXPORT QRhiShaderResourceBindings : public QRhiResource |
| 1253 | { |
| 1254 | public: |
| 1255 | QRhiResource::Type resourceType() const override; |
| 1256 | |
| 1257 | void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; } |
| 1258 | template<typename InputIterator> |
| 1259 | void setBindings(InputIterator first, InputIterator last) |
| 1260 | { |
| 1261 | m_bindings.clear(); |
| 1262 | std::copy(first, last, std::back_inserter(x&: m_bindings)); |
| 1263 | } |
| 1264 | const QRhiShaderResourceBinding *cbeginBindings() const { return m_bindings.cbegin(); } |
| 1265 | const QRhiShaderResourceBinding *cendBindings() const { return m_bindings.cend(); } |
| 1266 | const QRhiShaderResourceBinding *bindingAt(qsizetype index) const { return &m_bindings.at(idx: index); } |
| 1267 | qsizetype bindingCount() const { return m_bindings.count(); } |
| 1268 | |
| 1269 | bool isLayoutCompatible(const QRhiShaderResourceBindings *other) const; |
| 1270 | |
| 1271 | QVector<quint32> serializedLayoutDescription() const { return m_layoutDesc; } |
| 1272 | |
| 1273 | virtual bool create() = 0; |
| 1274 | |
| 1275 | enum UpdateFlag { |
| 1276 | BindingsAreSorted = 0x01 |
| 1277 | }; |
| 1278 | Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag) |
| 1279 | |
| 1280 | virtual void updateResources(UpdateFlags flags = {}) = 0; |
| 1281 | |
| 1282 | protected: |
| 1283 | static constexpr int BINDING_PREALLOC = 12; |
| 1284 | QRhiShaderResourceBindings(QRhiImplementation *rhi); |
| 1285 | QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings; |
| 1286 | size_t m_layoutDescHash = 0; |
| 1287 | // Intentionally not using QVLA for m_layoutDesc: clients like Qt Quick are much |
| 1288 | // better served with an implicitly shared container here, because they will likely |
| 1289 | // throw this directly into structs serving as cache keys. |
| 1290 | QVector<quint32> m_layoutDesc; |
| 1291 | friend class QRhiImplementation; |
| 1292 | #ifndef QT_NO_DEBUG_STREAM |
| 1293 | friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &); |
| 1294 | #endif |
| 1295 | }; |
| 1296 | |
| 1297 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags) |
| 1298 | |
| 1299 | #ifndef QT_NO_DEBUG_STREAM |
| 1300 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &); |
| 1301 | #endif |
| 1302 | |
| 1303 | // The proper name. Until it gets rolled out universally, have the better name |
| 1304 | // as a typedef. Eventually it should be reversed (the old name being a typedef |
| 1305 | // to the new one). |
| 1306 | using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings; |
| 1307 | |
| 1308 | class Q_GUI_EXPORT QRhiGraphicsPipeline : public QRhiResource |
| 1309 | { |
| 1310 | public: |
| 1311 | enum Flag { |
| 1312 | UsesBlendConstants = 1 << 0, |
| 1313 | UsesStencilRef = 1 << 1, |
| 1314 | UsesScissor = 1 << 2, |
| 1315 | CompileShadersWithDebugInfo = 1 << 3, |
| 1316 | UsesShadingRate = 1 << 4 |
| 1317 | }; |
| 1318 | Q_DECLARE_FLAGS(Flags, Flag) |
| 1319 | |
| 1320 | enum Topology { |
| 1321 | Triangles, |
| 1322 | TriangleStrip, |
| 1323 | TriangleFan, |
| 1324 | Lines, |
| 1325 | LineStrip, |
| 1326 | Points, |
| 1327 | Patches |
| 1328 | }; |
| 1329 | |
| 1330 | enum CullMode { |
| 1331 | None, |
| 1332 | Front, |
| 1333 | Back |
| 1334 | }; |
| 1335 | |
| 1336 | enum FrontFace { |
| 1337 | CCW, |
| 1338 | CW |
| 1339 | }; |
| 1340 | |
| 1341 | enum ColorMaskComponent { |
| 1342 | R = 1 << 0, |
| 1343 | G = 1 << 1, |
| 1344 | B = 1 << 2, |
| 1345 | A = 1 << 3 |
| 1346 | }; |
| 1347 | Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent) |
| 1348 | |
| 1349 | enum BlendFactor { |
| 1350 | Zero, |
| 1351 | One, |
| 1352 | SrcColor, |
| 1353 | OneMinusSrcColor, |
| 1354 | DstColor, |
| 1355 | OneMinusDstColor, |
| 1356 | SrcAlpha, |
| 1357 | OneMinusSrcAlpha, |
| 1358 | DstAlpha, |
| 1359 | OneMinusDstAlpha, |
| 1360 | ConstantColor, |
| 1361 | OneMinusConstantColor, |
| 1362 | ConstantAlpha, |
| 1363 | OneMinusConstantAlpha, |
| 1364 | SrcAlphaSaturate, |
| 1365 | Src1Color, |
| 1366 | OneMinusSrc1Color, |
| 1367 | Src1Alpha, |
| 1368 | OneMinusSrc1Alpha |
| 1369 | }; |
| 1370 | |
| 1371 | enum BlendOp { |
| 1372 | Add, |
| 1373 | Subtract, |
| 1374 | ReverseSubtract, |
| 1375 | Min, |
| 1376 | Max |
| 1377 | }; |
| 1378 | |
| 1379 | struct TargetBlend { |
| 1380 | ColorMask colorWrite = ColorMask(0xF); // R | G | B | A |
| 1381 | bool enable = false; |
| 1382 | BlendFactor srcColor = One; |
| 1383 | BlendFactor dstColor = OneMinusSrcAlpha; |
| 1384 | BlendOp opColor = Add; |
| 1385 | BlendFactor srcAlpha = One; |
| 1386 | BlendFactor dstAlpha = OneMinusSrcAlpha; |
| 1387 | BlendOp opAlpha = Add; |
| 1388 | }; |
| 1389 | |
| 1390 | enum CompareOp { |
| 1391 | Never, |
| 1392 | Less, |
| 1393 | Equal, |
| 1394 | LessOrEqual, |
| 1395 | Greater, |
| 1396 | NotEqual, |
| 1397 | GreaterOrEqual, |
| 1398 | Always |
| 1399 | }; |
| 1400 | |
| 1401 | enum StencilOp { |
| 1402 | StencilZero, |
| 1403 | Keep, |
| 1404 | Replace, |
| 1405 | IncrementAndClamp, |
| 1406 | DecrementAndClamp, |
| 1407 | Invert, |
| 1408 | IncrementAndWrap, |
| 1409 | DecrementAndWrap |
| 1410 | }; |
| 1411 | |
| 1412 | struct StencilOpState { |
| 1413 | StencilOp failOp = Keep; |
| 1414 | StencilOp depthFailOp = Keep; |
| 1415 | StencilOp passOp = Keep; |
| 1416 | CompareOp compareOp = Always; |
| 1417 | }; |
| 1418 | |
| 1419 | enum PolygonMode { |
| 1420 | Fill, |
| 1421 | Line |
| 1422 | }; |
| 1423 | |
| 1424 | QRhiResource::Type resourceType() const override; |
| 1425 | |
| 1426 | Flags flags() const { return m_flags; } |
| 1427 | void setFlags(Flags f) { m_flags = f; } |
| 1428 | |
| 1429 | Topology topology() const { return m_topology; } |
| 1430 | void setTopology(Topology t) { m_topology = t; } |
| 1431 | |
| 1432 | CullMode cullMode() const { return m_cullMode; } |
| 1433 | void setCullMode(CullMode mode) { m_cullMode = mode; } |
| 1434 | |
| 1435 | FrontFace frontFace() const { return m_frontFace; } |
| 1436 | void setFrontFace(FrontFace f) { m_frontFace = f; } |
| 1437 | |
| 1438 | void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; } |
| 1439 | template<typename InputIterator> |
| 1440 | void setTargetBlends(InputIterator first, InputIterator last) |
| 1441 | { |
| 1442 | m_targetBlends.clear(); |
| 1443 | std::copy(first, last, std::back_inserter(x&: m_targetBlends)); |
| 1444 | } |
| 1445 | const TargetBlend *cbeginTargetBlends() const { return m_targetBlends.cbegin(); } |
| 1446 | const TargetBlend *cendTargetBlends() const { return m_targetBlends.cend(); } |
| 1447 | const TargetBlend *targetBlendAt(qsizetype index) const { return &m_targetBlends.at(idx: index); } |
| 1448 | qsizetype targetBlendCount() const { return m_targetBlends.count(); } |
| 1449 | |
| 1450 | bool hasDepthTest() const { return m_depthTest; } |
| 1451 | void setDepthTest(bool enable) { m_depthTest = enable; } |
| 1452 | |
| 1453 | bool hasDepthWrite() const { return m_depthWrite; } |
| 1454 | void setDepthWrite(bool enable) { m_depthWrite = enable; } |
| 1455 | |
| 1456 | CompareOp depthOp() const { return m_depthOp; } |
| 1457 | void setDepthOp(CompareOp op) { m_depthOp = op; } |
| 1458 | |
| 1459 | bool hasStencilTest() const { return m_stencilTest; } |
| 1460 | void setStencilTest(bool enable) { m_stencilTest = enable; } |
| 1461 | |
| 1462 | StencilOpState stencilFront() const { return m_stencilFront; } |
| 1463 | void setStencilFront(const StencilOpState &state) { m_stencilFront = state; } |
| 1464 | |
| 1465 | StencilOpState stencilBack() const { return m_stencilBack; } |
| 1466 | void setStencilBack(const StencilOpState &state) { m_stencilBack = state; } |
| 1467 | |
| 1468 | quint32 stencilReadMask() const { return m_stencilReadMask; } |
| 1469 | void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; } |
| 1470 | |
| 1471 | quint32 stencilWriteMask() const { return m_stencilWriteMask; } |
| 1472 | void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; } |
| 1473 | |
| 1474 | int sampleCount() const { return m_sampleCount; } |
| 1475 | void setSampleCount(int s) { m_sampleCount = s; } |
| 1476 | |
| 1477 | float lineWidth() const { return m_lineWidth; } |
| 1478 | void setLineWidth(float width) { m_lineWidth = width; } |
| 1479 | |
| 1480 | int depthBias() const { return m_depthBias; } |
| 1481 | void setDepthBias(int bias) { m_depthBias = bias; } |
| 1482 | |
| 1483 | float slopeScaledDepthBias() const { return m_slopeScaledDepthBias; } |
| 1484 | void setSlopeScaledDepthBias(float bias) { m_slopeScaledDepthBias = bias; } |
| 1485 | |
| 1486 | void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; } |
| 1487 | template<typename InputIterator> |
| 1488 | void setShaderStages(InputIterator first, InputIterator last) |
| 1489 | { |
| 1490 | m_shaderStages.clear(); |
| 1491 | std::copy(first, last, std::back_inserter(x&: m_shaderStages)); |
| 1492 | } |
| 1493 | const QRhiShaderStage *cbeginShaderStages() const { return m_shaderStages.cbegin(); } |
| 1494 | const QRhiShaderStage *cendShaderStages() const { return m_shaderStages.cend(); } |
| 1495 | const QRhiShaderStage *shaderStageAt(qsizetype index) const { return &m_shaderStages.at(idx: index); } |
| 1496 | qsizetype shaderStageCount() const { return m_shaderStages.count(); } |
| 1497 | |
| 1498 | QRhiVertexInputLayout vertexInputLayout() const { return m_vertexInputLayout; } |
| 1499 | void setVertexInputLayout(const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; } |
| 1500 | |
| 1501 | QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; } |
| 1502 | void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; } |
| 1503 | |
| 1504 | QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } |
| 1505 | void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } |
| 1506 | |
| 1507 | int patchControlPointCount() const { return m_patchControlPointCount; } |
| 1508 | void setPatchControlPointCount(int count) { m_patchControlPointCount = count; } |
| 1509 | |
| 1510 | PolygonMode polygonMode() const {return m_polygonMode; } |
| 1511 | void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; } |
| 1512 | |
| 1513 | int multiViewCount() const { return m_multiViewCount; } |
| 1514 | void setMultiViewCount(int count) { m_multiViewCount = count; } |
| 1515 | |
| 1516 | virtual bool create() = 0; |
| 1517 | |
| 1518 | protected: |
| 1519 | QRhiGraphicsPipeline(QRhiImplementation *rhi); |
| 1520 | Flags m_flags; |
| 1521 | Topology m_topology = Triangles; |
| 1522 | CullMode m_cullMode = None; |
| 1523 | FrontFace m_frontFace = CCW; |
| 1524 | QVarLengthArray<TargetBlend, 8> m_targetBlends; |
| 1525 | bool m_depthTest = false; |
| 1526 | bool m_depthWrite = false; |
| 1527 | CompareOp m_depthOp = Less; |
| 1528 | bool m_stencilTest = false; |
| 1529 | StencilOpState m_stencilFront; |
| 1530 | StencilOpState m_stencilBack; |
| 1531 | quint32 m_stencilReadMask = 0xFF; |
| 1532 | quint32 m_stencilWriteMask = 0xFF; |
| 1533 | int m_sampleCount = 1; |
| 1534 | float m_lineWidth = 1.0f; |
| 1535 | int m_depthBias = 0; |
| 1536 | float m_slopeScaledDepthBias = 0.0f; |
| 1537 | int m_patchControlPointCount = 3; |
| 1538 | PolygonMode m_polygonMode = Fill; |
| 1539 | int m_multiViewCount = 0; |
| 1540 | QVarLengthArray<QRhiShaderStage, 4> m_shaderStages; |
| 1541 | QRhiVertexInputLayout m_vertexInputLayout; |
| 1542 | QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; |
| 1543 | QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; |
| 1544 | }; |
| 1545 | |
| 1546 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags) |
| 1547 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask) |
| 1548 | Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE); |
| 1549 | |
| 1550 | struct QRhiSwapChainHdrInfo |
| 1551 | { |
| 1552 | enum LimitsType { |
| 1553 | LuminanceInNits, |
| 1554 | ColorComponentValue |
| 1555 | }; |
| 1556 | |
| 1557 | enum LuminanceBehavior { |
| 1558 | SceneReferred, |
| 1559 | DisplayReferred |
| 1560 | }; |
| 1561 | |
| 1562 | LimitsType limitsType; |
| 1563 | union { |
| 1564 | struct { |
| 1565 | float minLuminance; |
| 1566 | float maxLuminance; |
| 1567 | } luminanceInNits; |
| 1568 | struct { |
| 1569 | float maxColorComponentValue; |
| 1570 | float maxPotentialColorComponentValue; |
| 1571 | } colorComponentValue; |
| 1572 | } limits; |
| 1573 | LuminanceBehavior luminanceBehavior; |
| 1574 | float sdrWhiteLevel; |
| 1575 | }; |
| 1576 | |
| 1577 | Q_DECLARE_TYPEINFO(QRhiSwapChainHdrInfo, Q_RELOCATABLE_TYPE); |
| 1578 | |
| 1579 | #ifndef QT_NO_DEBUG_STREAM |
| 1580 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiSwapChainHdrInfo &); |
| 1581 | #endif |
| 1582 | |
| 1583 | struct QRhiSwapChainProxyData |
| 1584 | { |
| 1585 | void *reserved[2] = {}; |
| 1586 | }; |
| 1587 | |
| 1588 | class Q_GUI_EXPORT QRhiSwapChain : public QRhiResource |
| 1589 | { |
| 1590 | public: |
| 1591 | enum Flag { |
| 1592 | SurfaceHasPreMulAlpha = 1 << 0, |
| 1593 | SurfaceHasNonPreMulAlpha = 1 << 1, |
| 1594 | sRGB = 1 << 2, |
| 1595 | UsedAsTransferSource = 1 << 3, |
| 1596 | NoVSync = 1 << 4, |
| 1597 | MinimalBufferCount = 1 << 5 |
| 1598 | }; |
| 1599 | Q_DECLARE_FLAGS(Flags, Flag) |
| 1600 | |
| 1601 | enum Format { |
| 1602 | SDR, |
| 1603 | HDRExtendedSrgbLinear, |
| 1604 | HDR10, |
| 1605 | HDRExtendedDisplayP3Linear |
| 1606 | }; |
| 1607 | |
| 1608 | enum StereoTargetBuffer { |
| 1609 | LeftBuffer, |
| 1610 | RightBuffer |
| 1611 | }; |
| 1612 | |
| 1613 | QRhiResource::Type resourceType() const override; |
| 1614 | |
| 1615 | QWindow *window() const { return m_window; } |
| 1616 | void setWindow(QWindow *window) { m_window = window; } |
| 1617 | |
| 1618 | QRhiSwapChainProxyData proxyData() const { return m_proxyData; } |
| 1619 | void setProxyData(const QRhiSwapChainProxyData &d) { m_proxyData = d; } |
| 1620 | |
| 1621 | Flags flags() const { return m_flags; } |
| 1622 | void setFlags(Flags f) { m_flags = f; } |
| 1623 | |
| 1624 | Format format() const { return m_format; } |
| 1625 | void setFormat(Format f) { m_format = f; } |
| 1626 | |
| 1627 | QRhiRenderBuffer *depthStencil() const { return m_depthStencil; } |
| 1628 | void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; } |
| 1629 | |
| 1630 | int sampleCount() const { return m_sampleCount; } |
| 1631 | void setSampleCount(int samples) { m_sampleCount = samples; } |
| 1632 | |
| 1633 | QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } |
| 1634 | void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } |
| 1635 | |
| 1636 | QRhiShadingRateMap *shadingRateMap() const { return m_shadingRateMap; } |
| 1637 | void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; } |
| 1638 | |
| 1639 | QSize currentPixelSize() const { return m_currentPixelSize; } |
| 1640 | |
| 1641 | virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0; |
| 1642 | virtual QRhiRenderTarget *currentFrameRenderTarget() = 0; |
| 1643 | virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer); |
| 1644 | virtual QSize surfacePixelSize() = 0; |
| 1645 | virtual bool isFormatSupported(Format f) = 0; |
| 1646 | virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0; |
| 1647 | virtual bool createOrResize() = 0; |
| 1648 | virtual QRhiSwapChainHdrInfo hdrInfo(); |
| 1649 | |
| 1650 | protected: |
| 1651 | QRhiSwapChain(QRhiImplementation *rhi); |
| 1652 | QWindow *m_window = nullptr; |
| 1653 | Flags m_flags; |
| 1654 | Format m_format = SDR; |
| 1655 | QRhiRenderBuffer *m_depthStencil = nullptr; |
| 1656 | int m_sampleCount = 1; |
| 1657 | QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; |
| 1658 | QSize m_currentPixelSize; |
| 1659 | QRhiSwapChainProxyData m_proxyData; |
| 1660 | QRhiShadingRateMap *m_shadingRateMap = nullptr; |
| 1661 | }; |
| 1662 | |
| 1663 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags) |
| 1664 | |
| 1665 | class Q_GUI_EXPORT QRhiComputePipeline : public QRhiResource |
| 1666 | { |
| 1667 | public: |
| 1668 | enum Flag { |
| 1669 | CompileShadersWithDebugInfo = 1 << 0 |
| 1670 | }; |
| 1671 | Q_DECLARE_FLAGS(Flags, Flag) |
| 1672 | |
| 1673 | QRhiResource::Type resourceType() const override; |
| 1674 | virtual bool create() = 0; |
| 1675 | |
| 1676 | Flags flags() const { return m_flags; } |
| 1677 | void setFlags(Flags f) { m_flags = f; } |
| 1678 | |
| 1679 | QRhiShaderStage shaderStage() const { return m_shaderStage; } |
| 1680 | void setShaderStage(const QRhiShaderStage &stage) { m_shaderStage = stage; } |
| 1681 | |
| 1682 | QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; } |
| 1683 | void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; } |
| 1684 | |
| 1685 | protected: |
| 1686 | QRhiComputePipeline(QRhiImplementation *rhi); |
| 1687 | Flags m_flags; |
| 1688 | QRhiShaderStage m_shaderStage; |
| 1689 | QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; |
| 1690 | }; |
| 1691 | |
| 1692 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags) |
| 1693 | |
| 1694 | class Q_GUI_EXPORT QRhiCommandBuffer : public QRhiResource |
| 1695 | { |
| 1696 | public: |
| 1697 | enum IndexFormat { |
| 1698 | IndexUInt16, |
| 1699 | IndexUInt32 |
| 1700 | }; |
| 1701 | |
| 1702 | enum BeginPassFlag { |
| 1703 | ExternalContent = 0x01, |
| 1704 | DoNotTrackResourcesForCompute = 0x02 |
| 1705 | }; |
| 1706 | Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag) |
| 1707 | |
| 1708 | QRhiResource::Type resourceType() const override; |
| 1709 | |
| 1710 | void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates); |
| 1711 | |
| 1712 | void beginPass(QRhiRenderTarget *rt, |
| 1713 | const QColor &colorClearValue, |
| 1714 | const QRhiDepthStencilClearValue &depthStencilClearValue, |
| 1715 | QRhiResourceUpdateBatch *resourceUpdates = nullptr, |
| 1716 | BeginPassFlags flags = {}); |
| 1717 | void endPass(QRhiResourceUpdateBatch *resourceUpdates = nullptr); |
| 1718 | |
| 1719 | void setGraphicsPipeline(QRhiGraphicsPipeline *ps); |
| 1720 | using DynamicOffset = std::pair<int, quint32>; // binding, offset |
| 1721 | void setShaderResources(QRhiShaderResourceBindings *srb = nullptr, |
| 1722 | int dynamicOffsetCount = 0, |
| 1723 | const DynamicOffset *dynamicOffsets = nullptr); |
| 1724 | using VertexInput = std::pair<QRhiBuffer *, quint32>; // buffer, offset |
| 1725 | void setVertexInput(int startBinding, int bindingCount, const VertexInput *bindings, |
| 1726 | QRhiBuffer *indexBuf = nullptr, quint32 indexOffset = 0, |
| 1727 | IndexFormat indexFormat = IndexUInt16); |
| 1728 | |
| 1729 | void setViewport(const QRhiViewport &viewport); |
| 1730 | void setScissor(const QRhiScissor &scissor); |
| 1731 | void setBlendConstants(const QColor &c); |
| 1732 | void setStencilRef(quint32 refValue); |
| 1733 | void setShadingRate(const QSize &coarsePixelSize); |
| 1734 | |
| 1735 | void draw(quint32 vertexCount, |
| 1736 | quint32 instanceCount = 1, |
| 1737 | quint32 firstVertex = 0, |
| 1738 | quint32 firstInstance = 0); |
| 1739 | |
| 1740 | void drawIndexed(quint32 indexCount, |
| 1741 | quint32 instanceCount = 1, |
| 1742 | quint32 firstIndex = 0, |
| 1743 | qint32 vertexOffset = 0, |
| 1744 | quint32 firstInstance = 0); |
| 1745 | |
| 1746 | void debugMarkBegin(const QByteArray &name); |
| 1747 | void debugMarkEnd(); |
| 1748 | void debugMarkMsg(const QByteArray &msg); |
| 1749 | |
| 1750 | void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates = nullptr, BeginPassFlags flags = {}); |
| 1751 | void endComputePass(QRhiResourceUpdateBatch *resourceUpdates = nullptr); |
| 1752 | void setComputePipeline(QRhiComputePipeline *ps); |
| 1753 | void dispatch(int x, int y, int z); |
| 1754 | |
| 1755 | const QRhiNativeHandles *nativeHandles(); |
| 1756 | void beginExternal(); |
| 1757 | void endExternal(); |
| 1758 | |
| 1759 | double lastCompletedGpuTime(); |
| 1760 | |
| 1761 | protected: |
| 1762 | QRhiCommandBuffer(QRhiImplementation *rhi); |
| 1763 | }; |
| 1764 | |
| 1765 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags) |
| 1766 | |
| 1767 | struct Q_GUI_EXPORT QRhiReadbackResult |
| 1768 | { |
| 1769 | std::function<void()> completed = nullptr; |
| 1770 | QRhiTexture::Format format; |
| 1771 | QSize pixelSize; |
| 1772 | QByteArray data; |
| 1773 | }; |
| 1774 | |
| 1775 | class Q_GUI_EXPORT QRhiResourceUpdateBatch |
| 1776 | { |
| 1777 | public: |
| 1778 | ~QRhiResourceUpdateBatch(); |
| 1779 | |
| 1780 | void release(); |
| 1781 | |
| 1782 | void merge(QRhiResourceUpdateBatch *other); |
| 1783 | bool hasOptimalCapacity() const; |
| 1784 | |
| 1785 | void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data); |
| 1786 | void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data); |
| 1787 | void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data); |
| 1788 | void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data); |
| 1789 | void uploadStaticBuffer(QRhiBuffer *buf, const void *data); |
| 1790 | void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data); |
| 1791 | void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result); |
| 1792 | void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc); |
| 1793 | void uploadTexture(QRhiTexture *tex, const QImage &image); |
| 1794 | void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription()); |
| 1795 | void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result); |
| 1796 | void generateMips(QRhiTexture *tex); |
| 1797 | |
| 1798 | private: |
| 1799 | QRhiResourceUpdateBatch(QRhiImplementation *rhi); |
| 1800 | Q_DISABLE_COPY(QRhiResourceUpdateBatch) |
| 1801 | QRhiResourceUpdateBatchPrivate *d; |
| 1802 | friend class QRhiResourceUpdateBatchPrivate; |
| 1803 | friend class QRhi; |
| 1804 | }; |
| 1805 | |
| 1806 | struct Q_GUI_EXPORT QRhiDriverInfo |
| 1807 | { |
| 1808 | enum DeviceType { |
| 1809 | UnknownDevice, |
| 1810 | IntegratedDevice, |
| 1811 | DiscreteDevice, |
| 1812 | ExternalDevice, |
| 1813 | VirtualDevice, |
| 1814 | CpuDevice |
| 1815 | }; |
| 1816 | |
| 1817 | QByteArray deviceName; |
| 1818 | quint64 deviceId = 0; |
| 1819 | quint64 vendorId = 0; |
| 1820 | DeviceType deviceType = UnknownDevice; |
| 1821 | }; |
| 1822 | |
| 1823 | Q_DECLARE_TYPEINFO(QRhiDriverInfo, Q_RELOCATABLE_TYPE); |
| 1824 | |
| 1825 | #ifndef QT_NO_DEBUG_STREAM |
| 1826 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiDriverInfo &); |
| 1827 | #endif |
| 1828 | |
| 1829 | struct Q_GUI_EXPORT QRhiStats |
| 1830 | { |
| 1831 | qint64 totalPipelineCreationTime = 0; |
| 1832 | // Vulkan or D3D12 memory allocator statistics |
| 1833 | quint32 blockCount = 0; |
| 1834 | quint32 allocCount = 0; |
| 1835 | quint64 usedBytes = 0; |
| 1836 | quint64 unusedBytes = 0; |
| 1837 | // D3D12 only, from IDXGIAdapter3::QueryVideoMemoryInfo(), incl. all resources |
| 1838 | quint64 totalUsageBytes = 0; |
| 1839 | }; |
| 1840 | |
| 1841 | Q_DECLARE_TYPEINFO(QRhiStats, Q_RELOCATABLE_TYPE); |
| 1842 | |
| 1843 | #ifndef QT_NO_DEBUG_STREAM |
| 1844 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiStats &); |
| 1845 | #endif |
| 1846 | |
| 1847 | class Q_GUI_EXPORT QRhiAdapter |
| 1848 | { |
| 1849 | public: |
| 1850 | virtual ~QRhiAdapter(); |
| 1851 | virtual QRhiDriverInfo info() const = 0; |
| 1852 | }; |
| 1853 | |
| 1854 | struct Q_GUI_EXPORT QRhiInitParams |
| 1855 | { |
| 1856 | }; |
| 1857 | |
| 1858 | class Q_GUI_EXPORT QRhi |
| 1859 | { |
| 1860 | public: |
| 1861 | enum Implementation { |
| 1862 | Null, |
| 1863 | Vulkan, |
| 1864 | OpenGLES2, |
| 1865 | D3D11, |
| 1866 | Metal, |
| 1867 | D3D12 |
| 1868 | }; |
| 1869 | |
| 1870 | enum Flag { |
| 1871 | EnableDebugMarkers = 1 << 0, |
| 1872 | PreferSoftwareRenderer = 1 << 1, |
| 1873 | EnablePipelineCacheDataSave = 1 << 2, |
| 1874 | EnableTimestamps = 1 << 3, |
| 1875 | SuppressSmokeTestWarnings = 1 << 4 |
| 1876 | }; |
| 1877 | Q_DECLARE_FLAGS(Flags, Flag) |
| 1878 | |
| 1879 | enum FrameOpResult { |
| 1880 | FrameOpSuccess = 0, |
| 1881 | FrameOpError, |
| 1882 | FrameOpSwapChainOutOfDate, |
| 1883 | FrameOpDeviceLost |
| 1884 | }; |
| 1885 | |
| 1886 | enum Feature { |
| 1887 | MultisampleTexture = 1, |
| 1888 | MultisampleRenderBuffer, |
| 1889 | DebugMarkers, |
| 1890 | Timestamps, |
| 1891 | Instancing, |
| 1892 | CustomInstanceStepRate, |
| 1893 | PrimitiveRestart, |
| 1894 | NonDynamicUniformBuffers, |
| 1895 | NonFourAlignedEffectiveIndexBufferOffset, |
| 1896 | NPOTTextureRepeat, |
| 1897 | RedOrAlpha8IsRed, |
| 1898 | ElementIndexUint, |
| 1899 | Compute, |
| 1900 | WideLines, |
| 1901 | VertexShaderPointSize, |
| 1902 | BaseVertex, |
| 1903 | BaseInstance, |
| 1904 | TriangleFanTopology, |
| 1905 | ReadBackNonUniformBuffer, |
| 1906 | ReadBackNonBaseMipLevel, |
| 1907 | TexelFetch, |
| 1908 | RenderToNonBaseMipLevel, |
| 1909 | IntAttributes, |
| 1910 | ScreenSpaceDerivatives, |
| 1911 | ReadBackAnyTextureFormat, |
| 1912 | PipelineCacheDataLoadSave, |
| 1913 | ImageDataStride, |
| 1914 | RenderBufferImport, |
| 1915 | ThreeDimensionalTextures, |
| 1916 | RenderTo3DTextureSlice, |
| 1917 | TextureArrays, |
| 1918 | Tessellation, |
| 1919 | GeometryShader, |
| 1920 | TextureArrayRange, |
| 1921 | NonFillPolygonMode, |
| 1922 | OneDimensionalTextures, |
| 1923 | OneDimensionalTextureMipmaps, |
| 1924 | HalfAttributes, |
| 1925 | RenderToOneDimensionalTexture, |
| 1926 | ThreeDimensionalTextureMipmaps, |
| 1927 | MultiView, |
| 1928 | TextureViewFormat, |
| 1929 | ResolveDepthStencil, |
| 1930 | VariableRateShading, |
| 1931 | VariableRateShadingMap, |
| 1932 | VariableRateShadingMapWithTexture, |
| 1933 | PerRenderTargetBlending, |
| 1934 | SampleVariables |
| 1935 | }; |
| 1936 | |
| 1937 | enum BeginFrameFlag { |
| 1938 | }; |
| 1939 | Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag) |
| 1940 | |
| 1941 | enum EndFrameFlag { |
| 1942 | SkipPresent = 1 << 0 |
| 1943 | }; |
| 1944 | Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag) |
| 1945 | |
| 1946 | enum ResourceLimit { |
| 1947 | TextureSizeMin = 1, |
| 1948 | TextureSizeMax, |
| 1949 | MaxColorAttachments, |
| 1950 | FramesInFlight, |
| 1951 | MaxAsyncReadbackFrames, |
| 1952 | MaxThreadGroupsPerDimension, |
| 1953 | MaxThreadsPerThreadGroup, |
| 1954 | MaxThreadGroupX, |
| 1955 | MaxThreadGroupY, |
| 1956 | MaxThreadGroupZ, |
| 1957 | TextureArraySizeMax, |
| 1958 | MaxUniformBufferRange, |
| 1959 | MaxVertexInputs, |
| 1960 | MaxVertexOutputs, |
| 1961 | ShadingRateImageTileSize |
| 1962 | }; |
| 1963 | |
| 1964 | ~QRhi(); |
| 1965 | |
| 1966 | static QRhi *create(Implementation impl, |
| 1967 | QRhiInitParams *params, |
| 1968 | Flags flags = {}, |
| 1969 | QRhiNativeHandles *importDevice = nullptr); |
| 1970 | static QRhi *create(Implementation impl, |
| 1971 | QRhiInitParams *params, |
| 1972 | Flags flags, |
| 1973 | QRhiNativeHandles *importDevice, |
| 1974 | QRhiAdapter *adapter); |
| 1975 | static bool probe(Implementation impl, QRhiInitParams *params); |
| 1976 | using AdapterList = QVector<QRhiAdapter *>; |
| 1977 | static AdapterList enumerateAdapters(Implementation impl, |
| 1978 | QRhiInitParams *params, |
| 1979 | QRhiNativeHandles *nativeHandles = nullptr); |
| 1980 | |
| 1981 | Implementation backend() const; |
| 1982 | const char *backendName() const; |
| 1983 | static const char *backendName(Implementation impl); |
| 1984 | QRhiDriverInfo driverInfo() const; |
| 1985 | QThread *thread() const; |
| 1986 | |
| 1987 | using CleanupCallback = std::function<void(QRhi *)>; |
| 1988 | void addCleanupCallback(const CleanupCallback &callback); |
| 1989 | void addCleanupCallback(const void *key, const CleanupCallback &callback); |
| 1990 | void removeCleanupCallback(const void *key); |
| 1991 | |
| 1992 | QRhiGraphicsPipeline *newGraphicsPipeline(); |
| 1993 | QRhiComputePipeline *newComputePipeline(); |
| 1994 | QRhiShaderResourceBindings *newShaderResourceBindings(); |
| 1995 | |
| 1996 | QRhiBuffer *newBuffer(QRhiBuffer::Type type, |
| 1997 | QRhiBuffer::UsageFlags usage, |
| 1998 | quint32 size); |
| 1999 | |
| 2000 | QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type, |
| 2001 | const QSize &pixelSize, |
| 2002 | int sampleCount = 1, |
| 2003 | QRhiRenderBuffer::Flags flags = {}, |
| 2004 | QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat); |
| 2005 | |
| 2006 | QRhiTexture *newTexture(QRhiTexture::Format format, |
| 2007 | const QSize &pixelSize, |
| 2008 | int sampleCount = 1, |
| 2009 | QRhiTexture::Flags flags = {}); |
| 2010 | |
| 2011 | QRhiTexture *newTexture(QRhiTexture::Format format, |
| 2012 | int width, int height, int depth, |
| 2013 | int sampleCount = 1, |
| 2014 | QRhiTexture::Flags flags = {}); |
| 2015 | |
| 2016 | QRhiTexture *newTextureArray(QRhiTexture::Format format, |
| 2017 | int arraySize, |
| 2018 | const QSize &pixelSize, |
| 2019 | int sampleCount = 1, |
| 2020 | QRhiTexture::Flags flags = {}); |
| 2021 | |
| 2022 | QRhiSampler *newSampler(QRhiSampler::Filter magFilter, |
| 2023 | QRhiSampler::Filter minFilter, |
| 2024 | QRhiSampler::Filter mipmapMode, |
| 2025 | QRhiSampler::AddressMode addressU, |
| 2026 | QRhiSampler::AddressMode addressV, |
| 2027 | QRhiSampler::AddressMode addressW = QRhiSampler::Repeat); |
| 2028 | |
| 2029 | QRhiShadingRateMap *newShadingRateMap(); |
| 2030 | |
| 2031 | QRhiTextureRenderTarget *newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, |
| 2032 | QRhiTextureRenderTarget::Flags flags = {}); |
| 2033 | |
| 2034 | QRhiSwapChain *newSwapChain(); |
| 2035 | FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {}); |
| 2036 | FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {}); |
| 2037 | bool isRecordingFrame() const; |
| 2038 | int currentFrameSlot() const; |
| 2039 | |
| 2040 | FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {}); |
| 2041 | FrameOpResult endOffscreenFrame(EndFrameFlags flags = {}); |
| 2042 | |
| 2043 | QRhi::FrameOpResult finish(); |
| 2044 | |
| 2045 | QRhiResourceUpdateBatch *nextResourceUpdateBatch(); |
| 2046 | |
| 2047 | QList<int> supportedSampleCounts() const; |
| 2048 | |
| 2049 | int ubufAlignment() const; |
| 2050 | int ubufAligned(int v) const; |
| 2051 | |
| 2052 | static int mipLevelsForSize(const QSize &size); |
| 2053 | static QSize sizeForMipLevel(int mipLevel, const QSize &baseLevelSize); |
| 2054 | |
| 2055 | bool isYUpInFramebuffer() const; |
| 2056 | bool isYUpInNDC() const; |
| 2057 | bool isClipDepthZeroToOne() const; |
| 2058 | |
| 2059 | QMatrix4x4 clipSpaceCorrMatrix() const; |
| 2060 | |
| 2061 | bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {}) const; |
| 2062 | bool isFeatureSupported(QRhi::Feature feature) const; |
| 2063 | int resourceLimit(ResourceLimit limit) const; |
| 2064 | |
| 2065 | const QRhiNativeHandles *nativeHandles(); |
| 2066 | bool makeThreadLocalNativeContextCurrent(); |
| 2067 | void setQueueSubmitParams(QRhiNativeHandles *params); |
| 2068 | |
| 2069 | static constexpr int MAX_MIP_LEVELS = 16; // -> max width or height is 65536 |
| 2070 | |
| 2071 | void releaseCachedResources(); |
| 2072 | |
| 2073 | bool isDeviceLost() const; |
| 2074 | |
| 2075 | QByteArray pipelineCacheData(); |
| 2076 | void setPipelineCacheData(const QByteArray &data); |
| 2077 | |
| 2078 | QRhiStats statistics() const; |
| 2079 | |
| 2080 | static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window); |
| 2081 | |
| 2082 | QList<QSize> supportedShadingRates(int sampleCount) const; |
| 2083 | |
| 2084 | protected: |
| 2085 | QRhi(); |
| 2086 | |
| 2087 | private: |
| 2088 | Q_DISABLE_COPY(QRhi) |
| 2089 | QRhiImplementation *d = nullptr; |
| 2090 | }; |
| 2091 | |
| 2092 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags) |
| 2093 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags) |
| 2094 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags) |
| 2095 | |
| 2096 | QT_END_NAMESPACE |
| 2097 | |
| 2098 | #include <rhi/qrhi_platform.h> |
| 2099 | |
| 2100 | #endif |
| 2101 | |