qrhid3d11_p.h 20.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt RHI module
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QRHID3D11_P_H
#define QRHID3D11_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qrhid3d11.h"
#include "qrhi_p.h"
#include <QShaderDescription>
#include <QWindow>

49
#include <d3d11_1.h>
50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include <dxgi1_3.h>

QT_BEGIN_NAMESPACE

struct QD3D11Buffer : public QRhiBuffer
{
    QD3D11Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
    void release() override;
    bool build() override;

    ID3D11Buffer *buffer = nullptr;
    QByteArray dynBuf;
    bool hasPendingDynamicUpdates = false;
    uint generation = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
64
    friend class QRhiD3D11;
65 66 67 68 69
};

struct QD3D11RenderBuffer : public QRhiRenderBuffer
{
    QD3D11RenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
Laszlo Agocs's avatar
Laszlo Agocs committed
70
                       int sampleCount, QRhiRenderBuffer::Flags flags);
71 72
    void release() override;
    bool build() override;
Laszlo Agocs's avatar
Laszlo Agocs committed
73
    QRhiTexture::Format backingFormat() const override;
74 75 76

    ID3D11Texture2D *tex = nullptr;
    ID3D11DepthStencilView *dsv = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
77
    ID3D11RenderTargetView *rtv = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
78
    DXGI_FORMAT dxgiFormat;
Laszlo Agocs's avatar
Laszlo Agocs committed
79
    DXGI_SAMPLE_DESC sampleDesc;
Laszlo Agocs's avatar
Laszlo Agocs committed
80
    friend class QRhiD3D11;
81 82 83 84
};

struct QD3D11Texture : public QRhiTexture
{
Laszlo Agocs's avatar
Laszlo Agocs committed
85 86
    QD3D11Texture(QRhiImplementation *rhi, Format format, const QSize &pixelSize,
                  int sampleCount, Flags flags);
87 88
    void release() override;
    bool build() override;
Laszlo Agocs's avatar
Laszlo Agocs committed
89 90 91 92 93
    bool buildFrom(const QRhiNativeHandles *src) override;
    const QRhiNativeHandles *nativeHandles() override;

    bool prepareBuild(QSize *adjustedSize = nullptr);
    bool finishBuild();
94 95

    ID3D11Texture2D *tex = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
96
    bool owns = true;
97
    ID3D11ShaderResourceView *srv = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
98
    DXGI_FORMAT dxgiFormat;
99
    uint mipLevelCount = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
100
    DXGI_SAMPLE_DESC sampleDesc;
Laszlo Agocs's avatar
Laszlo Agocs committed
101
    QRhiD3D11TextureNativeHandles nativeHandlesStruct;
102
    uint generation = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
103
    friend class QRhiD3D11;
104 105 106 107 108 109 110 111 112 113 114
};

struct QD3D11Sampler : public QRhiSampler
{
    QD3D11Sampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
                  AddressMode u, AddressMode v, AddressMode w);
    void release() override;
    bool build() override;

    ID3D11SamplerState *samplerState = nullptr;
    uint generation = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
115
    friend class QRhiD3D11;
116 117
};

118
struct QD3D11RenderPassDescriptor : public QRhiRenderPassDescriptor
119
{
120
    QD3D11RenderPassDescriptor(QRhiImplementation *rhi);
121 122 123
    void release() override;
};

124
struct QD3D11RenderTargetData
125
{
126
    QD3D11RenderTargetData(QRhiImplementation *)
127 128 129 130
    {
        for (int i = 0; i < MAX_COLOR_ATTACHMENTS; ++i)
            rtv[i] = nullptr;
    }
131

132
    QD3D11RenderPassDescriptor *rp = nullptr;
133
    QSize pixelSize;
Laszlo Agocs's avatar
Laszlo Agocs committed
134
    float dpr = 1;
135
    int sampleCount = 1;
136 137
    int colorAttCount = 0;
    int dsAttCount = 0;
138 139 140 141

    static const int MAX_COLOR_ATTACHMENTS = 8;
    ID3D11RenderTargetView *rtv[MAX_COLOR_ATTACHMENTS];
    ID3D11DepthStencilView *dsv = nullptr;
142 143
};

144
struct QD3D11ReferenceRenderTarget : public QRhiRenderTarget
145 146 147
{
    QD3D11ReferenceRenderTarget(QRhiImplementation *rhi);
    void release() override;
148

149
    Type type() const override;
150
    QSize pixelSize() const override;
Laszlo Agocs's avatar
Laszlo Agocs committed
151
    float devicePixelRatio() const override;
152
    int sampleCount() const override;
153

154
    QD3D11RenderTargetData d;
155 156 157 158 159 160
};

struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget
{
    QD3D11TextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags);
    void release() override;
Laszlo Agocs's avatar
Laszlo Agocs committed
161

162
    Type type() const override;
163
    QSize pixelSize() const override;
Laszlo Agocs's avatar
Laszlo Agocs committed
164
    float devicePixelRatio() const override;
165
    int sampleCount() const override;
166

167
    QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
Laszlo Agocs's avatar
Laszlo Agocs committed
168 169
    bool build() override;

170 171 172
    QD3D11RenderTargetData d;
    bool ownsRtv[QD3D11RenderTargetData::MAX_COLOR_ATTACHMENTS];
    ID3D11RenderTargetView *rtv[QD3D11RenderTargetData::MAX_COLOR_ATTACHMENTS];
173 174
    bool ownsDsv = false;
    ID3D11DepthStencilView *dsv = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
175
    friend class QRhiD3D11;
176 177 178 179 180 181 182 183
};

struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings
{
    QD3D11ShaderResourceBindings(QRhiImplementation *rhi);
    void release() override;
    bool build() override;

Laszlo Agocs's avatar
Laszlo Agocs committed
184
    QVector<QRhiShaderResourceBinding> sortedBindings;
185 186 187 188 189
    uint generation = 0;

    // Keep track of the generation number of each referenced QRhi* to be able
    // to detect that the batched bindings are out of date.
    struct BoundUniformBufferData {
Laszlo Agocs's avatar
Laszlo Agocs committed
190
        quint64 id;
191 192 193
        uint generation;
    };
    struct BoundSampledTextureData {
Laszlo Agocs's avatar
Laszlo Agocs committed
194
        quint64 texId;
195
        uint texGeneration;
Laszlo Agocs's avatar
Laszlo Agocs committed
196
        quint64 samplerId;
197 198 199 200 201 202 203 204 205 206
        uint samplerGeneration;
    };
    struct BoundResourceData {
        union {
            BoundUniformBufferData ubuf;
            BoundSampledTextureData stex;
        };
    };
    QVector<BoundResourceData> boundResourceData;

207 208 209
    QRhiBatchedBindings<ID3D11Buffer *> vsubufs;
    QRhiBatchedBindings<UINT> vsubufoffsets;
    QRhiBatchedBindings<UINT> vsubufsizes;
210

211 212 213
    QRhiBatchedBindings<ID3D11Buffer *> fsubufs;
    QRhiBatchedBindings<UINT> fsubufoffsets;
    QRhiBatchedBindings<UINT> fsubufsizes;
214

215 216
    QRhiBatchedBindings<ID3D11SamplerState *> vssamplers;
    QRhiBatchedBindings<ID3D11ShaderResourceView *> vsshaderresources;
217

218 219
    QRhiBatchedBindings<ID3D11SamplerState *> fssamplers;
    QRhiBatchedBindings<ID3D11ShaderResourceView *> fsshaderresources;
Laszlo Agocs's avatar
Laszlo Agocs committed
220 221

    friend class QRhiD3D11;
222 223
};

Laszlo Agocs's avatar
Laszlo Agocs committed
224 225
Q_DECLARE_TYPEINFO(QD3D11ShaderResourceBindings::BoundResourceData, Q_MOVABLE_TYPE);

226 227 228 229 230 231 232 233 234 235 236 237 238 239
struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline
{
    QD3D11GraphicsPipeline(QRhiImplementation *rhi);
    void release() override;
    bool build() override;

    ID3D11DepthStencilState *dsState = nullptr;
    ID3D11BlendState *blendState = nullptr;
    ID3D11VertexShader *vs = nullptr;
    ID3D11PixelShader *fs = nullptr;
    ID3D11InputLayout *inputLayout = nullptr;
    D3D11_PRIMITIVE_TOPOLOGY d3dTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
    ID3D11RasterizerState *rastState = nullptr;
    uint generation = 0;
Laszlo Agocs's avatar
Laszlo Agocs committed
240
    friend class QRhiD3D11;
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
};

struct QD3D11SwapChain;

struct QD3D11CommandBuffer : public QRhiCommandBuffer
{
    QD3D11CommandBuffer(QRhiImplementation *rhi);
    void release() override;

    struct Command {
        enum Cmd {
            SetRenderTarget,
            Clear,
            Viewport,
            Scissor,
            BindVertexBuffers,
            BindIndexBuffer,
            BindGraphicsPipeline,
259
            BindShaderResources,
260 261 262
            StencilRef,
            BlendConstants,
            Draw,
Laszlo Agocs's avatar
Laszlo Agocs committed
263
            DrawIndexed,
264
            UpdateSubRes,
Laszlo Agocs's avatar
Laszlo Agocs committed
265
            CopySubRes,
Laszlo Agocs's avatar
Laszlo Agocs committed
266
            ResolveSubRes,
267 268 269 270
            GenMip,
            DebugMarkBegin,
            DebugMarkEnd,
            DebugMarkMsg
271 272 273
        };
        enum ClearFlag { Color = 1, Depth = 2, Stencil = 4 };
        Cmd cmd;
274 275 276 277 278

        static const int MAX_UBUF_BINDINGS = 32; // should be D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT but 128 is a waste of space for our purposes

        // QRhi*/QD3D11* references should be kept at minimum (so no
        // QRhiTexture/Buffer/etc. pointers).
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
        union {
            struct {
                QRhiRenderTarget *rt;
            } setRenderTarget;
            struct {
                QRhiRenderTarget *rt;
                int mask;
                float c[4];
                float d;
                quint32 s;
            } clear;
            struct {
                float x, y, w, h;
                float d0, d1;
            } viewport;
            struct {
                int x, y, w, h;
            } scissor;
            struct {
                int startSlot;
                int slotCount;
                ID3D11Buffer *buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
                UINT offsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
                UINT strides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
            } bindVertexBuffers;
            struct {
                ID3D11Buffer *buffer;
                quint32 offset;
                DXGI_FORMAT format;
            } bindIndexBuffer;
            struct {
                QD3D11GraphicsPipeline *ps;
            } bindGraphicsPipeline;
312 313 314 315 316 317
            struct {
                QD3D11ShaderResourceBindings *srb;
                bool offsetOnlyChange;
                int dynamicOffsetCount;
                uint dynamicOffsetPairs[MAX_UBUF_BINDINGS * 2]; // binding, offsetInConstants
            } bindShaderResources;
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
            struct {
                QD3D11GraphicsPipeline *ps;
                quint32 ref;
            } stencilRef;
            struct {
                QD3D11GraphicsPipeline *ps;
                float c[4];
            } blendConstants;
            struct {
                QD3D11GraphicsPipeline *ps;
                quint32 vertexCount;
                quint32 instanceCount;
                quint32 firstVertex;
                quint32 firstInstance;
            } draw;
            struct {
                QD3D11GraphicsPipeline *ps;
                quint32 indexCount;
                quint32 instanceCount;
                quint32 firstIndex;
                qint32 vertexOffset;
                quint32 firstInstance;
            } drawIndexed;
Laszlo Agocs's avatar
Laszlo Agocs committed
341
            struct {
342 343 344 345 346 347 348 349 350 351 352 353
                ID3D11Resource *dst;
                UINT dstSubRes;
                bool hasDstBox;
                D3D11_BOX dstBox;
                const void *src; // must come from retain*()
                UINT srcRowPitch;
            } updateSubRes;
            struct {
                ID3D11Resource *dst;
                UINT dstSubRes;
                UINT dstX;
                UINT dstY;
Laszlo Agocs's avatar
Laszlo Agocs committed
354
                ID3D11Resource *src;
355 356 357 358
                UINT srcSubRes;
                bool hasSrcBox;
                D3D11_BOX srcBox;
            } copySubRes;
Laszlo Agocs's avatar
Laszlo Agocs committed
359 360 361 362 363 364 365
            struct {
                ID3D11Resource *dst;
                UINT dstSubRes;
                ID3D11Resource *src;
                UINT srcSubRes;
                DXGI_FORMAT format;
            } resolveSubRes;
Laszlo Agocs's avatar
Laszlo Agocs committed
366
            struct {
367
                ID3D11ShaderResourceView *srv;
Laszlo Agocs's avatar
Laszlo Agocs committed
368
            } genMip;
369 370 371
            struct {
                char s[64];
            } debugMark;
372 373 374 375 376 377 378 379 380
        } args;
    };

    QVector<Command> commands;
    QRhiRenderTarget *currentTarget;
    QRhiGraphicsPipeline *currentPipeline;
    uint currentPipelineGeneration;
    QRhiShaderResourceBindings *currentSrb;
    uint currentSrbGeneration;
381 382 383 384
    ID3D11Buffer *currentIndexBuffer;
    quint32 currentIndexOffset;
    DXGI_FORMAT currentIndexFormat;
    ID3D11Buffer *currentVertexBuffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
385
    quint32 currentVertexOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
386

387 388 389 390
    QVector<QByteArray> dataRetainPool;
    QVector<QImage> imageRetainPool;

    // relies heavily on implicit sharing (no copies of the actual data will be made)
Laszlo Agocs's avatar
Laszlo Agocs committed
391
    const uchar *retainData(const QByteArray &data) {
392
        dataRetainPool.append(data);
Laszlo Agocs's avatar
Laszlo Agocs committed
393
        return reinterpret_cast<const uchar *>(dataRetainPool.constLast().constData());
394
    }
Laszlo Agocs's avatar
Laszlo Agocs committed
395
    const uchar *retainImage(const QImage &image) {
396 397 398
        imageRetainPool.append(image);
        return imageRetainPool.constLast().constBits();
    }
Laszlo Agocs's avatar
Laszlo Agocs committed
399
    void resetCommands() {
400
        commands.clear();
401 402
        dataRetainPool.clear();
        imageRetainPool.clear();
Laszlo Agocs's avatar
Laszlo Agocs committed
403 404 405
    }
    void resetState() {
        resetCommands();
406 407 408 409 410
        currentTarget = nullptr;
        currentPipeline = nullptr;
        currentPipelineGeneration = 0;
        currentSrb = nullptr;
        currentSrbGeneration = 0;
411 412 413 414 415
        currentIndexBuffer = nullptr;
        currentIndexOffset = 0;
        currentIndexFormat = DXGI_FORMAT_R16_UINT;
        memset(currentVertexBuffers, 0, sizeof(currentVertexBuffers));
        memset(currentVertexOffsets, 0, sizeof(currentVertexOffsets));
416 417 418
    }
};

Laszlo Agocs's avatar
Laszlo Agocs committed
419 420
Q_DECLARE_TYPEINFO(QD3D11CommandBuffer::Command, Q_MOVABLE_TYPE);

421 422 423 424 425 426 427
struct QD3D11SwapChain : public QRhiSwapChain
{
    QD3D11SwapChain(QRhiImplementation *rhi);
    void release() override;

    QRhiCommandBuffer *currentFrameCommandBuffer() override;
    QRhiRenderTarget *currentFrameRenderTarget() override;
Laszlo Agocs's avatar
Laszlo Agocs committed
428

429
    QSize surfacePixelSize() override;
430

431
    QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
432
    bool buildOrResize() override;
433

434 435 436 437
    void releaseBuffers();
    bool newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI_SAMPLE_DESC sampleDesc,
                        ID3D11Texture2D **tex, ID3D11RenderTargetView **rtv) const;

438 439 440 441
    QWindow *window = nullptr;
    QSize pixelSize;
    QD3D11ReferenceRenderTarget rt;
    QD3D11CommandBuffer cb;
442
    DXGI_FORMAT colorFormat;
443 444 445 446
    IDXGISwapChain1 *swapChain = nullptr;
    static const int BUFFER_COUNT = 2;
    ID3D11Texture2D *tex[BUFFER_COUNT];
    ID3D11RenderTargetView *rtv[BUFFER_COUNT];
447 448 449
    ID3D11Texture2D *msaaTex[BUFFER_COUNT];
    ID3D11RenderTargetView *msaaRtv[BUFFER_COUNT];
    DXGI_SAMPLE_DESC sampleDesc;
450 451
    int currentFrameSlot = 0;
    int frameCount = 0;
452
    QD3D11RenderBuffer *ds = nullptr;
Laszlo Agocs's avatar
Laszlo Agocs committed
453
    bool timestampActive[BUFFER_COUNT];
454 455
    ID3D11Query *timestampDisjointQuery[BUFFER_COUNT];
    ID3D11Query *timestampQuery[BUFFER_COUNT * 2];
456
    UINT swapInterval = 1;
457 458 459 460 461
};

class QRhiD3D11 : public QRhiImplementation
{
public:
462
    QRhiD3D11(QRhiD3D11InitParams *params, QRhiD3D11NativeHandles *importDevice = nullptr);
463

464
    bool create(QRhi::Flags flags) override;
465
    void destroy() override;
466 467 468 469 470 471 472 473 474

    QRhiGraphicsPipeline *createGraphicsPipeline() override;
    QRhiShaderResourceBindings *createShaderResourceBindings() override;
    QRhiBuffer *createBuffer(QRhiBuffer::Type type,
                             QRhiBuffer::UsageFlags usage,
                             int size) override;
    QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
                                         const QSize &pixelSize,
                                         int sampleCount,
Laszlo Agocs's avatar
Laszlo Agocs committed
475
                                         QRhiRenderBuffer::Flags flags) override;
476 477
    QRhiTexture *createTexture(QRhiTexture::Format format,
                               const QSize &pixelSize,
Laszlo Agocs's avatar
Laszlo Agocs committed
478
                               int sampleCount,
479 480 481 482 483 484 485 486 487
                               QRhiTexture::Flags flags) override;
    QRhiSampler *createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter,
                               QRhiSampler::Filter mipmapMode,
                               QRhiSampler:: AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w) override;

    QRhiTextureRenderTarget *createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
                                                       QRhiTextureRenderTarget::Flags flags) override;

    QRhiSwapChain *createSwapChain() override;
488 489
    QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override;
    QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override;
490
    QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb) override;
491 492
    QRhi::FrameOpResult endOffscreenFrame() override;
    QRhi::FrameOpResult finish() override;
493

494 495 496 497
    void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;

    void beginPass(QRhiCommandBuffer *cb,
                   QRhiRenderTarget *rt,
498 499 500
                   const QRhiColorClearValue &colorClearValue,
                   const QRhiDepthStencilClearValue &depthStencilClearValue,
                   QRhiResourceUpdateBatch *resourceUpdates) override;
501
    void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override;
502 503

    void setGraphicsPipeline(QRhiCommandBuffer *cb,
504 505 506 507 508
                             QRhiGraphicsPipeline *ps) override;

    void setShaderResources(QRhiCommandBuffer *cb,
                            QRhiShaderResourceBindings *srb,
                            const QVector<QRhiCommandBuffer::DynamicOffset> &dynamicOffsets) override;
509 510

    void setVertexInput(QRhiCommandBuffer *cb,
511
                        int startBinding, const QVector<QRhiCommandBuffer::VertexInput> &bindings,
512
                        QRhiBuffer *indexBuf, quint32 indexOffset,
513
                        QRhiCommandBuffer::IndexFormat indexFormat) override;
514 515 516 517 518 519 520 521 522 523 524 525 526

    void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override;
    void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override;
    void setBlendConstants(QRhiCommandBuffer *cb, const QVector4D &c) override;
    void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override;

    void draw(QRhiCommandBuffer *cb, quint32 vertexCount,
              quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override;

    void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
                     quint32 instanceCount, quint32 firstIndex,
                     qint32 vertexOffset, quint32 firstInstance) override;

527 528 529 530
    void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override;
    void debugMarkEnd(QRhiCommandBuffer *cb) override;
    void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override;

531 532 533
    QVector<int> supportedSampleCounts() const override;
    int ubufAlignment() const override;
    bool isYUpInFramebuffer() const override;
Laszlo Agocs's avatar
Laszlo Agocs committed
534
    bool isYUpInNDC() const override;
535
    QMatrix4x4 clipSpaceCorrMatrix() const override;
536
    bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
Laszlo Agocs's avatar
Laszlo Agocs committed
537
    bool isFeatureSupported(QRhi::Feature feature) const override;
Laszlo Agocs's avatar
Laszlo Agocs committed
538
    int resourceLimit(QRhi::ResourceLimit limit) const override;
539
    const QRhiNativeHandles *nativeHandles() override;
540

541
    void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
542 543
    void updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD);
    void executeBufferHostWritesForCurrentFrame(QD3D11Buffer *bufD);
544 545 546
    void bindShaderResources(QD3D11ShaderResourceBindings *srbD,
                             const uint *dynOfsPairs, int dynOfsPairCount,
                             bool offsetOnlyChange);
547
    void setRenderTarget(QRhiRenderTarget *rt);
Laszlo Agocs's avatar
Laszlo Agocs committed
548
    void executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *timestampSwapChain = nullptr);
549
    DXGI_SAMPLE_DESC effectiveSampleCount(int sampleCount) const;
550
    void finishActiveReadbacks();
551
    void reportLiveObjects(ID3D11Device *device);
552 553 554 555 556 557

    bool debugLayer = false;
    bool importedDevice = false;
    ID3D11Device *dev = nullptr;
    ID3D11DeviceContext1 *context = nullptr;
    D3D_FEATURE_LEVEL featureLevel;
558
    ID3DUserDefinedAnnotation *annotations = nullptr;
559
    IDXGIFactory2 *dxgiFactory = nullptr;
560
    QRhiD3D11NativeHandles nativeHandlesStruct;
561 562 563 564 565 566 567

    bool inFrame = false;
    bool inPass = false;

    struct {
        int vsLastActiveSrvBinding = 0;
        int fsLastActiveSrvBinding = 0;
568
        QD3D11SwapChain *currentSwapChain = nullptr;
569
    } contextState;
570 571 572 573 574 575

    struct OffscreenFrame {
        OffscreenFrame(QRhiImplementation *rhi) : cbWrapper(rhi) { }
        bool active = false;
        QD3D11CommandBuffer cbWrapper;
    } ofr;
576 577 578 579 580 581 582 583 584 585

    struct ActiveReadback {
        QRhiReadbackDescription desc;
        QRhiReadbackResult *result;
        ID3D11Texture2D *stagingTex;
        quint32 bufSize;
        QSize pixelSize;
        QRhiTexture::Format format;
    };
    QVector<ActiveReadback> activeReadbacks;
586 587
};

588 589
Q_DECLARE_TYPEINFO(QRhiD3D11::ActiveReadback, Q_MOVABLE_TYPE);

590 591 592
QT_END_NAMESPACE

#endif