Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsd3d11testdevicecontext_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWINDOWSD3D11TESTDEVICECONTEXT_P_H
5#define QWINDOWSD3D11TESTDEVICECONTEXT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qbytearray.h>
19#include <QtCore/qbytearrayview.h>
20#include <QtCore/qsize.h>
21#include <QtCore/private/qcomptr_p.h>
22#include <QtCore/private/qexpected_p.h>
23#include <QtGui/qcolor.h>
24
25#include <vector>
26
27#include <d3d11_1.h>
28
29QT_BEGIN_NAMESPACE
30class QRhi;
31QT_END_NAMESPACE
32
33template <typename T>
34using ComResult = q23::expected<T, HRESULT>;
35
36// Shared D3D11 device fixture for Windows-only multimedia unit tests.
38{
41
42 ComResult<QColor> getFirstPixelColor(const ComPtr<ID3D11Texture2D> &texture) const;
43
44 // Like getFirstPixelColor, but interprets the pixel bytes in B,G,R,A order (for
45 // DXGI_FORMAT_B8G8R8A8_UNORM textures).
46 ComResult<QColor> getFirstPixelColorBGRA(const ComPtr<ID3D11Texture2D> &texture) const;
47
49 const std::vector<QColor> &colors) const;
50
51 bool isTextureFormatSupported(DXGI_FORMAT format) const;
52
53 // Creates an uninitialized single-plane NV12 texture, e.g. for structural (plane
54 // count/size/format) tests that don't need to verify pixel contents.
56
57 // Fills an NV12 texture's luma plane with lumaValue and its interleaved chroma plane with
58 // (chromaUValue, chromaVValue), e.g. for pixel round-trip tests. If texture is a texture
59 // array (e.g. a pooled decoder surface), arraySlice selects which slice to fill.
60 HRESULT fillNV12Texture(const ComPtr<ID3D11Texture2D> &texture, QSize size, quint8 lumaValue,
61 quint8 chromaUValue, quint8 chromaVValue, UINT arraySlice = 0) const;
62
63 // Creates a single-plane NV12 texture with a uniform luma/chroma value, for tests that
64 // verify actual color conversion.
66 createFilledNV12Texture(QSize size, quint8 lumaValue, quint8 chromaU, quint8 chromaV) const;
67
68 // Same as createNV12Texture, but for a 10-bit P010 surface.
70
71 // Same as fillNV12Texture, but for a 10-bit P010 surface: each 16-bit sample holds its value
72 // left-shifted into the high bits (FFmpeg's P010 convention).
73 HRESULT fillP010Texture(const ComPtr<ID3D11Texture2D> &texture, QSize size, quint16 lumaValue,
74 quint16 chromaUValue, quint16 chromaVValue, UINT arraySlice = 0) const;
75
76 // Creates an uninitialized single-plane texture in the given (non-planar) format, e.g. for
77 // structural tests of a packed hw pixel format.
79 DXGI_FORMAT format) const;
80
81 // Fills a single-plane texture uniformly by repeating texel across every pixel.
82 HRESULT fillSinglePlaneTexture(const ComPtr<ID3D11Texture2D> &texture, QSize size,
83 QByteArrayView texel, UINT arraySlice = 0) const;
84
85 // Reads back "height" rows of "width" texels ("texelSize" bytes each), tightly packed (row
86 // padding from the texture's native row pitch is stripped), starting "rowOffset" rows into
87 // the given array slice. Suitable for verifying any plane of any pixel format, e.g. the
88 // second (chroma) plane of a planar format by passing rowOffset = the first plane's height.
89 ComResult<QByteArray> readPlaneRows(const ComPtr<ID3D11Texture2D> &texture, int rowOffset,
90 int width, int height, int texelSize,
91 UINT arraySlice = 0) const;
92
93private:
94 // Function to set the pixels of an ID3D11Texture2D texture to red
95 HRESULT fillTextureWithColors(const ComPtr<ID3D11Texture2D> &texture,
96 const std::vector<QColor> &colors) const;
97
98 // Creates a single-slice staging texture with the given CPU access, holding a copy of
99 // 'arraySlice' of 'texture'. Only that slice is copied: copying a whole multi-slice planar
100 // texture array created with D3D11_BIND_DECODER, like FFmpeg's decoder pool, removes the
101 // device on some drivers (seen on AMD).
102 ComResult<ComPtr<ID3D11Texture2D>>
103 createStagingSliceCopy(const ComPtr<ID3D11Texture2D> &texture, UINT arraySlice,
104 UINT cpuAccessFlags) const;
105};
106
107// Creates a device context using a hardware D3D11 adapter.
109
110// Creates a device context using the software (WARP) D3D11 adapter, e.g. to test behavior
111// with a QRhi that reports QRhiDriverInfo::CpuDevice.
113
114// Get QWindowsD3D11TestDeviceContext from QRhi instance
116
117#endif // QWINDOWSD3D11TESTDEVICECONTEXT_P_H
ComResult< QWindowsD3D11TestDeviceContext > wrapRhiD3D11Device(QRhi &rhi)
ComResult< QWindowsD3D11TestDeviceContext > createD3D11TestDeviceContext()
static ComResult< QWindowsD3D11TestDeviceContext > createD3D11TestDeviceContextImpl(D3D_DRIVER_TYPE driverType, UINT flags)
ComResult< QWindowsD3D11TestDeviceContext > createWarpD3D11TestDeviceContext()
ComResult< ComPtr< ID3D11Texture2D > > createSinglePlaneTexture(QSize size, DXGI_FORMAT format) const
ComResult< ComPtr< ID3D11Texture2D > > createFilledNV12Texture(QSize size, quint8 lumaValue, quint8 chromaU, quint8 chromaV) const
ComResult< ComPtr< ID3D11Texture2D > > createNV12Texture(QSize size) const
bool isTextureFormatSupported(DXGI_FORMAT format) const
HRESULT fillNV12Texture(const ComPtr< ID3D11Texture2D > &texture, QSize size, quint8 lumaValue, quint8 chromaUValue, quint8 chromaVValue, UINT arraySlice=0) const
ComResult< QColor > getFirstPixelColorBGRA(const ComPtr< ID3D11Texture2D > &texture) const
ComResult< ComPtr< ID3D11Texture2D > > createP010Texture(QSize size) const
ComResult< QByteArray > readPlaneRows(const ComPtr< ID3D11Texture2D > &texture, int rowOffset, int width, int height, int texelSize, UINT arraySlice=0) const
HRESULT fillP010Texture(const ComPtr< ID3D11Texture2D > &texture, QSize size, quint16 lumaValue, quint16 chromaUValue, quint16 chromaVValue, UINT arraySlice=0) const
ComResult< ComPtr< ID3D11Texture2D > > createTextureArray(QSize size, const std::vector< QColor > &colors) const
HRESULT fillSinglePlaneTexture(const ComPtr< ID3D11Texture2D > &texture, QSize size, QByteArrayView texel, UINT arraySlice=0) const
ComResult< QColor > getFirstPixelColor(const ComPtr< ID3D11Texture2D > &texture) const