Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qrhid3d11.cpp File Reference
#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 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 QD3D11RenderTargetDatartData (QRhiRenderTarget *rt)
 
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)
 
static bool output6ForWindow (QWindow *w, IDXGIAdapter1 *adapter, IDXGIOutput6 **result)
 
static bool outputDesc1ForWindow (QWindow *w, IDXGIAdapter1 *adapter, DXGI_OUTPUT_DESC1 *result)
 

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 120 of file qrhid3d11.cpp.

◆ D3D11_VS_INPUT_REGISTER_COUNT

#define D3D11_VS_INPUT_REGISTER_COUNT   32

Definition at line 124 of file qrhid3d11.cpp.

◆ DXGI_ADAPTER_FLAG_SOFTWARE

#define DXGI_ADAPTER_FLAG_SOFTWARE   2

\variable QRhiD3D11NativeHandles::dev

\variable QRhiD3D11NativeHandles::context

\variable QRhiD3D11NativeHandles::featureLevel

\variable QRhiD3D11NativeHandles::adapterLuidLow

\variable QRhiD3D11NativeHandles::adapterLuidHigh

Definition at line 116 of file qrhid3d11.cpp.

◆ 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:29

Definition at line 2505 of file qrhid3d11.cpp.

◆ 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 2637 of file qrhid3d11.cpp.

◆ 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 2524 of file qrhid3d11.cpp.

◆ 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 2476 of file qrhid3d11.cpp.

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 2442 of file qrhid3d11.cpp.

References QRhiBatchedBindings< T >::batches.

◆ clampedResourceCount()

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

Definition at line 2466 of file qrhid3d11.cpp.

References qWarning.

◆ createDXGIFactory2()

static IDXGIFactory1 * createDXGIFactory2 ( )
static

Definition at line 156 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 1528 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 2127 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:

◆ output6ForWindow()

static bool output6ForWindow ( QWindow w,
IDXGIAdapter1 *  adapter,
IDXGIOutput6 **  result 
)
static

Definition at line 4866 of file qrhid3d11.cpp.

References QRect::center(), QRect::contains(), desc, i, ok, output, QRect::size(), and QRect::topLeft().

Referenced by outputDesc1ForWindow().

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

◆ outputDesc1ForWindow()

static bool outputDesc1ForWindow ( QWindow w,
IDXGIAdapter1 *  adapter,
DXGI_OUTPUT_DESC1 *  result 
)
static

Definition at line 4893 of file qrhid3d11.cpp.

References ok, and output6ForWindow().

Referenced by QD3D11SwapChain::createOrResize(), QD3D11SwapChain::hdrInfo(), and QD3D11SwapChain::isFormatSupported().

+ 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 3990 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 1928 of file qrhid3d11.cpp.

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

Referenced by 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 4264 of file qrhid3d11.cpp.

References QCryptographicHash::addData(), QCryptographicHash::result(), QCryptographicHash::Sha1, and QByteArray::toHex().

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

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

◆ swapchainReadbackTextureFormat()

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

Definition at line 1500 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 3558 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 4245 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 2866 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 4180 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 4061 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 4033 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 3168 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 3151 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 4048 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 3526 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 4086 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 3573 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 4158 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 4994 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 4995 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