Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qrhid3d11.cpp File Reference

(e12791b05759819708d2b466362dc4a1df75b686)

#include "qrhid3d11_p.h"
#include "qshader.h"
#include "vs_test_p.h"
#include <QWindow>
#include <qmath.h>
#include <QtCore/qcryptographichash.h>
#include <QtCore/private/qsystemerror_p.h>
#include "qrhid3dhelpers_p.h"
+ Include dependency graph for qrhid3d11.cpp:

Go to the source code of this file.

Classes

struct  QD3D11PipelineCacheDataHeader
 

Macros

#define DXGI_ADAPTER_FLAG_SOFTWARE   2
 \variable QRhiD3D11NativeHandles::dev
 
#define D3D11_1_UAV_SLOT_COUNT   64
 
#define D3D11_VS_INPUT_REGISTER_COUNT   32
 
#define SETUBUFBATCH(stagePrefixL, stagePrefixU)
 
#define SETSAMPLERBATCH(stagePrefixL, stagePrefixU)
 
#define SETUAVBATCH(stagePrefixL, stagePrefixU)
 
#define SETSHADER(StageL, StageU)
 

Functions

template<class Int >
Int aligned (Int v, Int byteAlign)
 
static IDXGIFactory1 * createDXGIFactory2 ()
 
static QD3D11RenderTargetDatartData (QRhiRenderTarget *rt)
 
static DXGI_FORMAT toD3DTextureFormat (QRhiTexture::Format format, QRhiTexture::Flags flags)
 
static QRhiTexture::Format swapchainReadbackTextureFormat (DXGI_FORMAT format, QRhiTexture::Flags *flags)
 
static bool isDepthTextureFormat (QRhiTexture::Format format)
 
static QPair< int, int > mapBinding (int binding, int stageIndex, const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[])
 
static void applyDynamicOffsets (UINT *offsets, int batchIndex, const QRhiBatchedBindings< UINT > *originalBindings, const QRhiBatchedBindings< UINT > *staticOffsets, const uint *dynOfsPairs, int dynOfsPairCount)
 
static uint clampedResourceCount (uint startSlot, int countSlots, uint maxSlots, const char *resType)
 
static uint toD3DBufferUsage (QRhiBuffer::UsageFlags usage)
 
static DXGI_FORMAT toD3DDepthTextureSRVFormat (QRhiTexture::Format format)
 
static DXGI_FORMAT toD3DDepthTextureDSVFormat (QRhiTexture::Format format)
 
static D3D11_FILTER toD3DFilter (QRhiSampler::Filter minFilter, QRhiSampler::Filter magFilter, QRhiSampler::Filter mipFilter)
 
static D3D11_TEXTURE_ADDRESS_MODE toD3DAddressMode (QRhiSampler::AddressMode m)
 
static D3D11_COMPARISON_FUNC toD3DTextureComparisonFunc (QRhiSampler::CompareOp op)
 
template<typename T >
void releasePipelineShader (T &s)
 
static D3D11_CULL_MODE toD3DCullMode (QRhiGraphicsPipeline::CullMode c)
 
static D3D11_FILL_MODE toD3DFillMode (QRhiGraphicsPipeline::PolygonMode mode)
 
static D3D11_COMPARISON_FUNC toD3DCompareOp (QRhiGraphicsPipeline::CompareOp op)
 
static D3D11_STENCIL_OP toD3DStencilOp (QRhiGraphicsPipeline::StencilOp op)
 
static DXGI_FORMAT toD3DAttributeFormat (QRhiVertexInputAttribute::Format format)
 
static D3D11_PRIMITIVE_TOPOLOGY toD3DTopology (QRhiGraphicsPipeline::Topology t, int patchControlPointCount)
 
static UINT8 toD3DColorWriteMask (QRhiGraphicsPipeline::ColorMask c)
 
static D3D11_BLEND toD3DBlendFactor (QRhiGraphicsPipeline::BlendFactor f, bool rgb)
 
static D3D11_BLEND_OP toD3DBlendOp (QRhiGraphicsPipeline::BlendOp op)
 
static QByteArray sourceHash (const QByteArray &source)
 

Variables

static const int RBM_SUPPORTED_STAGES = 6
 
static const int RBM_VERTEX = 0
 
static const int RBM_HULL = 1
 
static const int RBM_DOMAIN = 2
 
static const int RBM_GEOMETRY = 3
 
static const int RBM_FRAGMENT = 4
 
static const int RBM_COMPUTE = 5
 
static const DXGI_FORMAT DEFAULT_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM
 
static const DXGI_FORMAT DEFAULT_SRGB_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
 

Macro Definition Documentation

◆ D3D11_1_UAV_SLOT_COUNT

#define D3D11_1_UAV_SLOT_COUNT   64

Definition at line 145 of file qrhid3d11.cpp.

◆ D3D11_VS_INPUT_REGISTER_COUNT

#define D3D11_VS_INPUT_REGISTER_COUNT   32

Definition at line 149 of file qrhid3d11.cpp.

Referenced by QRhiD3D11::resourceLimit().

◆ DXGI_ADAPTER_FLAG_SOFTWARE

#define DXGI_ADAPTER_FLAG_SOFTWARE   2

\variable QRhiD3D11NativeHandles::dev

Points to a \l{https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nn-d3d11-id3d11device}{ID3D11Device} or left set to \nullptr if no existing device is to be imported.

Note
When importing a device, both the device and the device context must be set to valid objects.

\variable QRhiD3D11NativeHandles::context

Points to a \l{https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nn-d3d11-id3d11devicecontext}{ID3D11DeviceContext} or left set to \nullptr if no existing device context is to be imported.

Note
When importing a device, both the device and the device context must be set to valid objects.

\variable QRhiD3D11NativeHandles::featureLevel

Specifies the feature level passed to \l{https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11createdevice}{D3D11CreateDevice()}. Relevant only when QRhi creates the device, ignored when importing a device and device context. When not set, the default rules outlined in the D3D documentation apply.

\variable QRhiD3D11NativeHandles::adapterLuidLow

The low part of the local identifier (LUID) of the DXGI adapter to use. Relevant only when QRhi creates the device, ignored when importing a device and device context.

\variable QRhiD3D11NativeHandles::adapterLuidHigh

The high part of the local identifier (LUID) of the DXGI adapter to use. Relevant only when QRhi creates the device, ignored when importing a device and device context.

Definition at line 141 of file qrhid3d11.cpp.

Referenced by QRhiD3D11::create(), and QRhiD3D::fillDriverInfo().

◆ SETSAMPLERBATCH

#define SETSAMPLERBATCH ( stagePrefixL,
stagePrefixU )
Value:
if (srbD->stagePrefixL##SamplerBatches.present) { \
for (const auto &batch : srbD->stagePrefixL##SamplerBatches.samplers.batches) { \
const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, #stagePrefixU " sampler"); \
if (count) \
context->stagePrefixU##SetSamplers(batch.startBinding, count, batch.resources.constData()); \
} \
for (const auto &batch : srbD->stagePrefixL##SamplerBatches.shaderresources.batches) { \
const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, #stagePrefixU " SRV"); \
if (count) { \
context->stagePrefixU##SetShaderResources(batch.startBinding, count, batch.resources.constData()); \
contextState.stagePrefixL##HighestActiveSrvBinding = qMax(contextState.stagePrefixL##HighestActiveSrvBinding, \
int(batch.startBinding + count) - 1); \
} \
} \
}
static void * context
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLenum GLenum GLsizei count
GLuint * samplers
static uint clampedResourceCount(uint startSlot, int countSlots, uint maxSlots, const char *resType)
unsigned int uint
Definition qtypes.h:34

Definition at line 2597 of file qrhid3d11.cpp.

Referenced by QRhiD3D11::bindShaderResources().

◆ SETSHADER

#define SETSHADER ( StageL,
StageU )
Value:
if (psD->StageL.shader) { \
context->StageU##SetShader(psD->StageL.shader, nullptr, 0); \
currentShaderMask |= StageU##MaskBit; \
} else if (currentShaderMask & StageU##MaskBit) { \
context->StageU##SetShader(nullptr, nullptr, 0); \
currentShaderMask &= ~StageU##MaskBit; \
}

Definition at line 2729 of file qrhid3d11.cpp.

Referenced by QRhiD3D11::executeCommandBuffer().

◆ SETUAVBATCH

#define SETUAVBATCH ( stagePrefixL,
stagePrefixU )
Value:
if (srbD->stagePrefixL##UavBatches.present) { \
for (const auto &batch : srbD->stagePrefixL##UavBatches.uavs.batches) { \
const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
D3D11_1_UAV_SLOT_COUNT, #stagePrefixU " UAV"); \
if (count) { \
context->stagePrefixU##SetUnorderedAccessViews(batch.startBinding, \
count, \
batch.resources.constData(), \
nullptr); \
contextState.stagePrefixL##HighestActiveUavBinding = qMax(contextState.stagePrefixL##HighestActiveUavBinding, \
int(batch.startBinding + count) - 1); \
} \
} \
}
#define D3D11_1_UAV_SLOT_COUNT

Definition at line 2616 of file qrhid3d11.cpp.

Referenced by QRhiD3D11::bindShaderResources().

◆ SETUBUFBATCH

#define SETUBUFBATCH ( stagePrefixL,
stagePrefixU )
Value:
if (srbD->stagePrefixL##UniformBufferBatches.present) { \
const QD3D11ShaderResourceBindings::StageUniformBufferBatches &batches(srbD->stagePrefixL##UniformBufferBatches); \
for (int i = 0, ie = batches.ubufs.batches.count(); i != ie; ++i) { \
const uint count = clampedResourceCount(batches.ubufs.batches[i].startBinding, \
batches.ubufs.batches[i].resources.count(), \
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, \
#stagePrefixU " cbuf"); \
if (count) { \
if (!dynOfsPairCount) { \
context->stagePrefixU##SetConstantBuffers1(batches.ubufs.batches[i].startBinding, \
count, \
batches.ubufs.batches[i].resources.constData(), \
batches.ubufoffsets.batches[i].resources.constData(), \
batches.ubufsizes.batches[i].resources.constData()); \
} else { \
applyDynamicOffsets(offsets, i, \
&batches.ubuforigbindings, &batches.ubufoffsets, \
dynOfsPairs, dynOfsPairCount); \
context->stagePrefixU##SetConstantBuffers1(batches.ubufs.batches[i].startBinding, \
count, \
batches.ubufs.batches[i].resources.constData(), \
batches.ubufsizes.batches[i].resources.constData()); \
} \
} \
} \
}
GLuint GLsizei const GLuint const GLintptr * offsets

Definition at line 2568 of file qrhid3d11.cpp.

Referenced by QRhiD3D11::bindShaderResources().

Function Documentation

◆ aligned()

◆ applyDynamicOffsets()

static void applyDynamicOffsets ( UINT * offsets,
int batchIndex,
const QRhiBatchedBindings< UINT > * originalBindings,
const QRhiBatchedBindings< UINT > * staticOffsets,
const uint * dynOfsPairs,
int dynOfsPairCount )
static

Definition at line 2534 of file qrhid3d11.cpp.

◆ clampedResourceCount()

static uint clampedResourceCount ( uint startSlot,
int countSlots,
uint maxSlots,
const char * resType )
inlinestatic

Definition at line 2558 of file qrhid3d11.cpp.

References qWarning.

◆ createDXGIFactory2()

static IDXGIFactory1 * createDXGIFactory2 ( )
static

Definition at line 181 of file qrhid3d11.cpp.

References qPrintable, and qWarning.

Referenced by QRhiD3D11::create().

+ Here is the caller graph for this function:

◆ isDepthTextureFormat()

static bool isDepthTextureFormat ( QRhiTexture::Format format)
inlinestatic

Definition at line 1631 of file qrhid3d11.cpp.

References QRhiTexture::D16, QRhiTexture::D24, QRhiTexture::D24S8, and QRhiTexture::D32F.

Referenced by QD3D11Texture::create(), QVkTexture::create(), QD3D11Texture::finishCreate(), and QD3D11Texture::prepareCreate().

+ Here is the caller graph for this function:

◆ mapBinding()

static QPair< int, int > mapBinding ( int binding,
int stageIndex,
const QShader::NativeResourceBindingMap * nativeResourceBindingMaps[] )
inlinestatic

Definition at line 2219 of file qrhid3d11.cpp.

References QMap< Key, T >::cend(), QMap< Key, T >::constFind(), QMap< Key, T >::isEmpty(), it, and map.

Referenced by QRhiMetal::enqueueShaderResourceBindings(), and QRhiD3D11::updateShaderResourceBindings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ releasePipelineShader()

template<typename T >
void releasePipelineShader ( T & s)
inline

Definition at line 4086 of file qrhid3d11.cpp.

Referenced by QD3D11GraphicsPipeline::destroy().

+ Here is the caller graph for this function:

◆ rtData()

static QD3D11RenderTargetData * rtData ( QRhiRenderTarget * rt)
inlinestatic

Definition at line 1322 of file qrhid3d11.cpp.

References QRHI_RES, QRhiResource::resourceType(), QRhiResource::SwapChainRenderTarget, and QRhiResource::TextureRenderTarget.

Referenced by QRhiD3D11::beginFrame(), QRhiD3D11::beginPass(), and QRhiD3D11::executeCommandBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sourceHash()

static QByteArray sourceHash ( const QByteArray & source)
inlinestatic

Definition at line 4376 of file qrhid3d11.cpp.

References QCryptographicHash::Sha1.

Referenced by QRhiD3D11::compileHlslShaderSource(), and QRhiD3D11::setPipelineCacheData().

+ Here is the caller graph for this function:

◆ swapchainReadbackTextureFormat()

static QRhiTexture::Format swapchainReadbackTextureFormat ( DXGI_FORMAT format,
QRhiTexture::Flags * flags )
inlinestatic

Definition at line 1603 of file qrhid3d11.cpp.

References QRhiTexture::BGRA8, qWarning, QRhiTexture::RGB10A2, QRhiTexture::RGBA16F, QRhiTexture::RGBA32F, QRhiTexture::RGBA8, QRhiTexture::sRGB, and QRhiTexture::UnknownFormat.

Referenced by QRhiD3D11::enqueueResourceUpdates(), and QRhiVulkan::enqueueResourceUpdates().

+ Here is the caller graph for this function:

◆ toD3DAddressMode()

static D3D11_TEXTURE_ADDRESS_MODE toD3DAddressMode ( QRhiSampler::AddressMode m)
inlinestatic

Definition at line 3654 of file qrhid3d11.cpp.

References QRhiSampler::ClampToEdge, QRhiSampler::Mirror, and QRhiSampler::Repeat.

Referenced by QD3D11Sampler::create().

+ Here is the caller graph for this function:

◆ toD3DAttributeFormat()

◆ toD3DBlendFactor()

◆ toD3DBlendOp()

static D3D11_BLEND_OP toD3DBlendOp ( QRhiGraphicsPipeline::BlendOp op)
inlinestatic

Definition at line 4357 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::Add, QRhiGraphicsPipeline::Max, QRhiGraphicsPipeline::Min, QRhiGraphicsPipeline::ReverseSubtract, and QRhiGraphicsPipeline::Subtract.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

◆ toD3DBufferUsage()

static uint toD3DBufferUsage ( QRhiBuffer::UsageFlags usage)
inlinestatic

Definition at line 2962 of file qrhid3d11.cpp.

References QRhiBuffer::IndexBuffer, QRhiBuffer::StorageBuffer, QRhiBuffer::UniformBuffer, and QRhiBuffer::VertexBuffer.

Referenced by QD3D11Buffer::create().

+ Here is the caller graph for this function:

◆ toD3DColorWriteMask()

static UINT8 toD3DColorWriteMask ( QRhiGraphicsPipeline::ColorMask c)
inlinestatic

Definition at line 4292 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::A, QRhiGraphicsPipeline::B, QRhiGraphicsPipeline::G, and QRhiGraphicsPipeline::R.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

◆ toD3DCompareOp()

static D3D11_COMPARISON_FUNC toD3DCompareOp ( QRhiGraphicsPipeline::CompareOp op)
inlinestatic

Definition at line 4157 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::Always, QRhiGraphicsPipeline::Equal, QRhiGraphicsPipeline::Greater, QRhiGraphicsPipeline::GreaterOrEqual, QRhiGraphicsPipeline::Less, QRhiGraphicsPipeline::LessOrEqual, QRhiGraphicsPipeline::Never, and QRhiGraphicsPipeline::NotEqual.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

◆ toD3DCullMode()

static D3D11_CULL_MODE toD3DCullMode ( QRhiGraphicsPipeline::CullMode c)
inlinestatic

Definition at line 4129 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::Back, QRhiGraphicsPipeline::Front, and QRhiGraphicsPipeline::None.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

◆ toD3DDepthTextureDSVFormat()

static DXGI_FORMAT toD3DDepthTextureDSVFormat ( QRhiTexture::Format format)
inlinestatic

Definition at line 3264 of file qrhid3d11.cpp.

References QRhiTexture::D16, QRhiTexture::D24, QRhiTexture::D24S8, and QRhiTexture::D32F.

Referenced by QD3D11TextureRenderTarget::create().

+ Here is the caller graph for this function:

◆ toD3DDepthTextureSRVFormat()

static DXGI_FORMAT toD3DDepthTextureSRVFormat ( QRhiTexture::Format format)
inlinestatic

Definition at line 3247 of file qrhid3d11.cpp.

References QRhiTexture::D16, QRhiTexture::D24, QRhiTexture::D24S8, and QRhiTexture::D32F.

Referenced by QD3D11Texture::finishCreate().

+ Here is the caller graph for this function:

◆ toD3DFillMode()

static D3D11_FILL_MODE toD3DFillMode ( QRhiGraphicsPipeline::PolygonMode mode)
inlinestatic

Definition at line 4144 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::Fill, and QRhiGraphicsPipeline::Line.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

◆ toD3DFilter()

static D3D11_FILTER toD3DFilter ( QRhiSampler::Filter minFilter,
QRhiSampler::Filter magFilter,
QRhiSampler::Filter mipFilter )
inlinestatic

Definition at line 3622 of file qrhid3d11.cpp.

References QRhiSampler::Linear, and QRhiSampler::Nearest.

Referenced by QD3D11Sampler::create().

+ Here is the caller graph for this function:

◆ toD3DStencilOp()

static D3D11_STENCIL_OP toD3DStencilOp ( QRhiGraphicsPipeline::StencilOp op)
inlinestatic

Definition at line 4182 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::DecrementAndClamp, QRhiGraphicsPipeline::DecrementAndWrap, QRhiGraphicsPipeline::IncrementAndClamp, QRhiGraphicsPipeline::IncrementAndWrap, QRhiGraphicsPipeline::Invert, QRhiGraphicsPipeline::Keep, QRhiGraphicsPipeline::Replace, and QRhiGraphicsPipeline::StencilZero.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

◆ toD3DTextureComparisonFunc()

static D3D11_COMPARISON_FUNC toD3DTextureComparisonFunc ( QRhiSampler::CompareOp op)
inlinestatic

Definition at line 3669 of file qrhid3d11.cpp.

References QRhiSampler::Always, QRhiSampler::Equal, QRhiSampler::Greater, QRhiSampler::GreaterOrEqual, QRhiSampler::Less, QRhiSampler::LessOrEqual, QRhiSampler::Never, and QRhiSampler::NotEqual.

Referenced by QD3D11Sampler::create().

+ Here is the caller graph for this function:

◆ toD3DTextureFormat()

◆ toD3DTopology()

static D3D11_PRIMITIVE_TOPOLOGY toD3DTopology ( QRhiGraphicsPipeline::Topology t,
int patchControlPointCount )
inlinestatic

Definition at line 4270 of file qrhid3d11.cpp.

References QRhiGraphicsPipeline::Lines, QRhiGraphicsPipeline::LineStrip, QRhiGraphicsPipeline::Patches, QRhiGraphicsPipeline::Points, Q_ASSERT, QRhiGraphicsPipeline::Triangles, and QRhiGraphicsPipeline::TriangleStrip.

Referenced by QD3D11GraphicsPipeline::create().

+ Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_FORMAT

const DXGI_FORMAT DEFAULT_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM
static

Definition at line 5074 of file qrhid3d11.cpp.

Referenced by QD3D11SwapChain::createOrResize().

◆ DEFAULT_SRGB_FORMAT

const DXGI_FORMAT DEFAULT_SRGB_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
static

Definition at line 5075 of file qrhid3d11.cpp.

Referenced by QD3D11SwapChain::createOrResize().

◆ RBM_COMPUTE

const int RBM_COMPUTE = 5
static

◆ RBM_DOMAIN

const int RBM_DOMAIN = 2
static

◆ RBM_FRAGMENT

const int RBM_FRAGMENT = 4
static

◆ RBM_GEOMETRY

const int RBM_GEOMETRY = 3
static

◆ RBM_HULL

const int RBM_HULL = 1
static

◆ RBM_SUPPORTED_STAGES

const int RBM_SUPPORTED_STAGES = 6
static

◆ RBM_VERTEX

const int RBM_VERTEX = 0
static