9#include <QtCore/qcryptographichash.h>
10#include <QtCore/private/qsystemerror_p.h>
140#ifndef DXGI_ADAPTER_FLAG_SOFTWARE
141#define DXGI_ADAPTER_FLAG_SOFTWARE 2
144#ifndef D3D11_1_UAV_SLOT_COUNT
145#define D3D11_1_UAV_SLOT_COUNT 64
148#ifndef D3D11_VS_INPUT_REGISTER_COUNT
149#define D3D11_VS_INPUT_REGISTER_COUNT 32
158 if (importParams->dev && importParams->context) {
159 dev =
reinterpret_cast<ID3D11Device *
>(importParams->dev);
160 ID3D11DeviceContext *
ctx =
reinterpret_cast<ID3D11DeviceContext *
>(importParams->context);
161 if (SUCCEEDED(
ctx->QueryInterface(__uuidof(ID3D11DeviceContext1),
reinterpret_cast<void **
>(&
context)))) {
166 qWarning(
"ID3D11DeviceContext1 not supported by context, cannot import");
169 featureLevel = D3D_FEATURE_LEVEL(importParams->featureLevel);
170 adapterLuid.LowPart = importParams->adapterLuidLow;
171 adapterLuid.HighPart = importParams->adapterLuidHigh;
178 return (
v + byteAlign - 1) & ~(byteAlign - 1);
183 IDXGIFactory1 *
result =
nullptr;
184 const HRESULT hr = CreateDXGIFactory2(0, __uuidof(IDXGIFactory2),
reinterpret_cast<void **
>(&
result));
186 qWarning(
"CreateDXGIFactory2() failed to create DXGI factory: %s",
187 qPrintable(QSystemError::windowsComString(hr)));
199 devFlags |= D3D11_CREATE_DEVICE_DEBUG;
209 IDXGIFactory5 *factory5 =
nullptr;
210 if (SUCCEEDED(
dxgiFactory->QueryInterface(__uuidof(IDXGIFactory5),
reinterpret_cast<void **
>(&factory5)))) {
211 BOOL allowTearing =
false;
212 if (SUCCEEDED(factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing,
sizeof(allowTearing))))
218 qWarning(
"The default swap effect is FLIP_DISCARD, QT_D3D_FLIP_DISCARD is now ignored");
225 qCDebug(QRHI_LOG_INFO,
"FLIP_* swapchain supported = true, ALLOW_TEARING supported = %s, use legacy (non-FLIP) model = %s",
230 IDXGIAdapter1 *adapter;
231 int requestedAdapterIndex = -1;
237 for (
int adapterIndex = 0;
dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
238 DXGI_ADAPTER_DESC1 desc;
239 adapter->GetDesc1(&desc);
241 if (desc.AdapterLuid.LowPart ==
adapterLuid.LowPart
242 && desc.AdapterLuid.HighPart ==
adapterLuid.HighPart)
244 requestedAdapterIndex = adapterIndex;
251 for (
int adapterIndex = 0;
dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
252 DXGI_ADAPTER_DESC1 desc;
253 adapter->GetDesc1(&desc);
256 requestedAdapterIndex = adapterIndex;
263 for (
int adapterIndex = 0;
dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
264 DXGI_ADAPTER_DESC1 desc;
265 adapter->GetDesc1(&desc);
267 qCDebug(QRHI_LOG_INFO,
"Adapter %d: '%s' (vendor 0x%X device 0x%X flags 0x%X)",
273 if (!
activeAdapter && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) {
277 qCDebug(QRHI_LOG_INFO,
" using this adapter");
289 QVarLengthArray<D3D_FEATURE_LEVEL, 4> requestedFeatureLevels;
290 bool requestFeatureLevels =
false;
292 requestFeatureLevels =
true;
296 ID3D11DeviceContext *
ctx =
nullptr;
298 requestFeatureLevels ? requestedFeatureLevels.constData() :
nullptr,
299 requestFeatureLevels ? requestedFeatureLevels.count() : 0,
303 if (hr == DXGI_ERROR_SDK_COMPONENT_MISSING &&
debugLayer) {
304 qCDebug(QRHI_LOG_INFO,
"Debug layer was requested but is not available. "
305 "Attempting to create D3D11 device without it.");
306 devFlags &= ~D3D11_CREATE_DEVICE_DEBUG;
307 hr = D3D11CreateDevice(
activeAdapter, D3D_DRIVER_TYPE_UNKNOWN,
nullptr, devFlags,
308 requestFeatureLevels ? requestedFeatureLevels.constData() :
nullptr,
309 requestFeatureLevels ? requestedFeatureLevels.count() : 0,
314 qWarning(
"Failed to create D3D11 device and context: %s",
315 qPrintable(QSystemError::windowsComString(hr)));
319 const bool supports11_1 = SUCCEEDED(
ctx->QueryInterface(__uuidof(ID3D11DeviceContext1),
reinterpret_cast<void **
>(&
context)));
322 qWarning(
"ID3D11DeviceContext1 not supported");
328 ID3D11VertexShader *testShader =
nullptr;
329 if (SUCCEEDED(
dev->CreateVertexShader(g_testVertexShader,
sizeof(g_testVertexShader),
nullptr, &testShader))) {
330 testShader->Release();
332 static const char *msg =
"D3D11 smoke test: Failed to create vertex shader";
334 qCDebug(QRHI_LOG_INFO,
"%s", msg);
340 D3D11_FEATURE_DATA_D3D11_OPTIONS features = {};
341 if (SUCCEEDED(
dev->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &features,
sizeof(features)))) {
345 if (!features.ConstantBufferOffsetting) {
346 static const char *msg =
"D3D11 smoke test: Constant buffer offsetting is not supported by the driver";
348 qCDebug(QRHI_LOG_INFO,
"%s", msg);
354 static const char *msg =
"D3D11 smoke test: Failed to query D3D11_FEATURE_D3D11_OPTIONS";
356 qCDebug(QRHI_LOG_INFO,
"%s", msg);
364 IDXGIDevice *dxgiDev =
nullptr;
365 if (SUCCEEDED(
dev->QueryInterface(__uuidof(IDXGIDevice),
reinterpret_cast<void **
>(&dxgiDev)))) {
366 IDXGIAdapter *adapter =
nullptr;
367 if (SUCCEEDED(dxgiDev->GetAdapter(&adapter))) {
368 IDXGIAdapter1 *adapter1 =
nullptr;
369 if (SUCCEEDED(adapter->QueryInterface(__uuidof(IDXGIAdapter1),
reinterpret_cast<void **
>(&adapter1)))) {
370 DXGI_ADAPTER_DESC1 desc;
371 adapter1->GetDesc1(&desc);
380 qCDebug(QRHI_LOG_INFO,
"Using imported device %p",
dev);
383 if (FAILED(
context->QueryInterface(__uuidof(ID3DUserDefinedAnnotation),
reinterpret_cast<void **
>(&
annotations))))
411 if (
ofr.tsDisjointQuery) {
412 ofr.tsDisjointQuery->Release();
413 ofr.tsDisjointQuery =
nullptr;
415 for (
int i = 0;
i < 2; ++
i) {
416 if (
ofr.tsQueries[
i]) {
417 ofr.tsQueries[
i]->Release();
418 ofr.tsQueries[
i] =
nullptr;
458 if (SUCCEEDED(
device->QueryInterface(__uuidof(ID3D11Debug),
reinterpret_cast<void **
>(&
debug)))) {
459 debug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL);
466 return { 1, 2, 4, 8 };
471 DXGI_SAMPLE_DESC desc;
477 desc.Count = UINT(
s);
479 desc.Quality = UINT(D3D11_STANDARD_MULTISAMPLE_PATTERN);
521 if (
m.isIdentity()) {
524 0.0f, 1.0f, 0.0f, 0.0f,
525 0.0f, 0.0f, 0.5f, 0.5f,
526 0.0f, 0.0f, 0.0f, 1.0f);
642 return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
654 return D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
656 return D3D11_CS_THREAD_GROUP_MAX_THREADS_PER_GROUP;
658 return D3D11_CS_THREAD_GROUP_MAX_X;
660 return D3D11_CS_THREAD_GROUP_MAX_Y;
662 return D3D11_CS_THREAD_GROUP_MAX_Z;
664 return D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION;
670 return D3D11_VS_OUTPUT_REGISTER_COUNT;
732 const size_t dataOffset =
sizeof(
header);
746 char *
p =
buf.data() + dataOffset;
754 memcpy(
p,
key.sourceHash.constData(),
key.sourceHash.size());
755 p +=
key.sourceHash.size();
757 i =
key.target.size();
760 memcpy(
p,
key.target.constData(),
key.target.size());
761 p +=
key.target.size();
763 i =
key.entryPoint.size();
766 memcpy(
p,
key.entryPoint.constData(),
key.entryPoint.size());
767 p +=
key.entryPoint.size();
777 p += bytecode.
size();
794 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: Invalid blob size (header incomplete)");
802 if (
header.rhiId != rhiId) {
803 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: The data is for a different QRhi version or backend (%u, %u)",
808 if (
header.arch != arch) {
809 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: Architecture does not match (%u, %u)",
817 qCDebug(QRHI_LOG_INFO,
"setPipelineCacheData: Invalid blob size (data incomplete)");
823 const char *
p =
data.constData() + dataOffset;
867 int sampleCount, QRhiRenderBuffer::Flags
flags,
874 const QSize &pixelSize,
int depth,
int arraySize,
875 int sampleCount, QRhiTexture::Flags
flags)
884 return new QD3D11Sampler(
this, magFilter, minFilter, mipmapMode, u,
v,
w);
888 QRhiTextureRenderTarget::Flags
flags)
915 if (pipelineChanged) {
922 cmd.
args.bindGraphicsPipeline.ps = psD;
935 int dynamicOffsetCount,
945 srb = gfxPsD->m_shaderResourceBindings;
947 srb = compPsD->m_shaderResourceBindings;
952 bool srbUpdate =
false;
953 for (
int i = 0, ie = srbD->sortedBindings.count();
i != ie; ++
i) {
965 if (bufD->generation != bd.ubuf.generation || bufD->m_id != bd.ubuf.id) {
967 bd.ubuf.id = bufD->m_id;
968 bd.ubuf.generation = bufD->generation;
977 if (bd.stex.count !=
data->count) {
981 for (
int elem = 0; elem <
data->count; ++elem) {
988 const quint64 texId = texD ? texD->m_id : 0;
989 const uint texGen = texD ? texD->generation : 0;
990 const quint64 samplerId = samplerD ? samplerD->m_id : 0;
991 const uint samplerGen = samplerD ? samplerD->generation : 0;
992 if (texGen != bd.stex.d[elem].texGeneration
993 || texId != bd.stex.d[elem].texId
994 || samplerGen != bd.stex.d[elem].samplerGeneration
995 || samplerId != bd.stex.d[elem].samplerId)
998 bd.stex.d[elem].texId = texId;
999 bd.stex.d[elem].texGeneration = texGen;
1000 bd.stex.d[elem].samplerId = samplerId;
1001 bd.stex.d[elem].samplerGeneration = samplerGen;
1011 if (texD->generation != bd.simage.generation || texD->m_id != bd.simage.id) {
1013 bd.simage.id = texD->m_id;
1014 bd.simage.generation = texD->generation;
1023 if (bufD->generation != bd.sbuf.generation || bufD->m_id != bd.sbuf.id) {
1025 bd.sbuf.id = bufD->m_id;
1026 bd.sbuf.generation = bufD->generation;
1038 memset(resBindMaps, 0,
sizeof(resBindMaps));
1040 resBindMaps[
RBM_VERTEX] = &gfxPsD->vs.nativeResourceBindingMap;
1041 resBindMaps[
RBM_HULL] = &gfxPsD->hs.nativeResourceBindingMap;
1042 resBindMaps[
RBM_DOMAIN] = &gfxPsD->ds.nativeResourceBindingMap;
1043 resBindMaps[
RBM_GEOMETRY] = &gfxPsD->gs.nativeResourceBindingMap;
1044 resBindMaps[
RBM_FRAGMENT] = &gfxPsD->fs.nativeResourceBindingMap;
1046 resBindMaps[
RBM_COMPUTE] = &compPsD->cs.nativeResourceBindingMap;
1054 if (srbChanged || srbRebuilt || srbUpdate || srbD->hasDynamicOffset) {
1066 cmd.
args.bindShaderResources.srb = srbD;
1069 cmd.
args.bindShaderResources.offsetOnlyChange = !srbChanged && !srbRebuilt && !srbUpdate && srbD->hasDynamicOffset;
1070 cmd.
args.bindShaderResources.dynamicOffsetCount = 0;
1071 if (srbD->hasDynamicOffset) {
1073 cmd.
args.bindShaderResources.dynamicOffsetCount = dynamicOffsetCount;
1074 uint *
p = cmd.
args.bindShaderResources.dynamicOffsetPairs;
1075 for (
int i = 0;
i < dynamicOffsetCount; ++
i) {
1077 const uint binding =
uint(dynOfs.first);
1079 const quint32 offsetInConstants = dynOfs.second / 16;
1081 *
p++ = offsetInConstants;
1084 qWarning(
"Too many dynamic offsets (%d, max is %d)",
1098 bool needsBindVBuf =
false;
1099 for (
int i = 0;
i < bindingCount; ++
i) {
1100 const int inputSlot = startBinding +
i;
1109 needsBindVBuf =
true;
1115 if (needsBindVBuf) {
1118 cmd.
args.bindVertexBuffers.startSlot = startBinding;
1120 qWarning(
"Too many vertex buffer bindings (%d, max is %d)",
1124 cmd.
args.bindVertexBuffers.slotCount = bindingCount;
1128 for (
int i = 0, ie =
qMin(bindingCount, inputBindingCount);
i != ie; ++
i) {
1130 cmd.
args.bindVertexBuffers.buffers[
i] = bufD->buffer;
1131 cmd.
args.bindVertexBuffers.offsets[
i] = bindings[
i].second;
1143 : DXGI_FORMAT_R32_UINT;
1154 cmd.
args.bindIndexBuffer.buffer = ibufD->buffer;
1155 cmd.
args.bindIndexBuffer.offset = indexOffset;
1156 cmd.
args.bindIndexBuffer.format = dxgiFormat;
1170 if (!qrhi_toTopLeftRenderTargetRect<UnBounded>(outputSize,
viewport.viewport(), &
x, &
y, &
w, &
h))
1175 cmd.
args.viewport.x =
x;
1176 cmd.
args.viewport.y =
y;
1177 cmd.
args.viewport.w =
w;
1178 cmd.
args.viewport.h =
h;
1192 if (!qrhi_toTopLeftRenderTargetRect<Bounded>(outputSize, scissor.
scissor(), &
x, &
y, &
w, &
h))
1197 cmd.
args.scissor.x =
x;
1198 cmd.
args.scissor.y =
y;
1199 cmd.
args.scissor.w =
w;
1200 cmd.
args.scissor.h =
h;
1211 cmd.
args.blendConstants.c[0] = float(
c.redF());
1212 cmd.
args.blendConstants.c[1] = float(
c.greenF());
1213 cmd.
args.blendConstants.c[2] = float(
c.blueF());
1214 cmd.
args.blendConstants.c[3] = float(
c.alphaF());
1225 cmd.
args.stencilRef.ref = refValue;
1237 cmd.
args.draw.vertexCount = vertexCount;
1239 cmd.
args.draw.firstVertex = firstVertex;
1240 cmd.
args.draw.firstInstance = firstInstance;
1252 cmd.
args.drawIndexed.indexCount = indexCount;
1254 cmd.
args.drawIndexed.firstIndex = firstIndex;
1255 cmd.
args.drawIndexed.vertexOffset = vertexOffset;
1256 cmd.
args.drawIndexed.firstInstance = firstInstance;
1343 swapChainD->cb.resetState();
1345 swapChainD->rt.d.rtv[0] = swapChainD->sampleDesc.Count > 1 ?
1347 swapChainD->rt.d.dsv = swapChainD->ds ? swapChainD->ds->dsv :
nullptr;
1351 if (swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex]) {
1352 double elapsedSec = 0;
1353 if (swapChainD->timestamps.tryQueryTimestamps(swapChainD->currentTimestampPairIndex,
context, &elapsedSec))
1354 swapChainD->cb.lastGpuTime = elapsedSec;
1357 ID3D11Query *tsStart = swapChainD->timestamps.query[swapChainD->currentTimestampPairIndex * 2];
1358 ID3D11Query *tsDisjoint = swapChainD->timestamps.disjointQuery[swapChainD->currentTimestampPairIndex];
1359 const bool recordTimestamps = tsStart && tsDisjoint && !swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex];
1363 cmd.
args.beginFrame.tsQuery = recordTimestamps ? tsStart :
nullptr;
1364 cmd.
args.beginFrame.tsDisjointQuery = recordTimestamps ? tsDisjoint :
nullptr;
1365 cmd.
args.beginFrame.swapchainData =
rtData(&swapChainD->rt);
1378 cmd.
args.endFrame.tsQuery =
nullptr;
1379 cmd.
args.endFrame.tsDisjointQuery =
nullptr;
1384 if (swapChainD->sampleDesc.Count > 1) {
1385 context->ResolveSubresource(swapChainD->backBufferTex, 0,
1387 swapChainD->colorFormat);
1391 ID3D11Query *tsEnd = swapChainD->timestamps.query[swapChainD->currentTimestampPairIndex * 2 + 1];
1392 ID3D11Query *tsDisjoint = swapChainD->timestamps.disjointQuery[swapChainD->currentTimestampPairIndex];
1393 const bool recordTimestamps = tsEnd && tsDisjoint && !swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex];
1394 if (recordTimestamps) {
1397 swapChainD->timestamps.active[swapChainD->currentTimestampPairIndex] =
true;
1402 UINT presentFlags = 0;
1403 if (swapChainD->swapInterval == 0 && (swapChainD->swapChainFlags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING))
1404 presentFlags |= DXGI_PRESENT_ALLOW_TEARING;
1405 if (!swapChainD->swapChain) {
1406 qWarning(
"Failed to present: IDXGISwapChain is unavailable");
1409 HRESULT hr = swapChainD->swapChain->Present(swapChainD->swapInterval, presentFlags);
1410 if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) {
1411 qWarning(
"Device loss detected in Present()");
1414 }
else if (FAILED(hr)) {
1416 qPrintable(QSystemError::windowsComString(hr)));
1420 if (
dcompDevice && swapChainD->dcompTarget && swapChainD->dcompVisual)
1429 swapChainD->frameCount += 1;
1440 ofr.cbWrapper.resetState();
1441 *
cb = &
ofr.cbWrapper;
1444 D3D11_QUERY_DESC queryDesc = {};
1445 if (!
ofr.tsDisjointQuery) {
1446 queryDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
1447 HRESULT hr =
dev->CreateQuery(&queryDesc, &
ofr.tsDisjointQuery);
1449 qWarning(
"Failed to create timestamp disjoint query: %s",
1450 qPrintable(QSystemError::windowsComString(hr)));
1454 queryDesc.Query = D3D11_QUERY_TIMESTAMP;
1455 for (
int i = 0;
i < 2; ++
i) {
1456 if (!
ofr.tsQueries[
i]) {
1459 qWarning(
"Failed to create timestamp query: %s",
1460 qPrintable(QSystemError::windowsComString(hr)));
1469 cmd.
args.beginFrame.tsQuery =
ofr.tsQueries[0] ?
ofr.tsQueries[0] :
nullptr;
1470 cmd.
args.beginFrame.tsDisjointQuery =
ofr.tsDisjointQuery ?
ofr.tsDisjointQuery :
nullptr;
1471 cmd.
args.beginFrame.swapchainData =
nullptr;
1483 cmd.
args.endFrame.tsQuery =
ofr.tsQueries[1] ?
ofr.tsQueries[1] :
nullptr;
1484 cmd.
args.endFrame.tsDisjointQuery =
ofr.tsDisjointQuery ?
ofr.tsDisjointQuery :
nullptr;
1491 if (
ofr.tsQueries[0]) {
1493 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT dj;
1497 hr =
context->GetData(
ofr.tsDisjointQuery, &dj,
sizeof(dj), 0);
1498 }
while (hr == S_FALSE);
1502 }
while (hr == S_FALSE);
1506 }
while (hr == S_FALSE);
1509 if (!dj.Disjoint && dj.Frequency) {
1510 const float elapsedMs = (timestamps[1] - timestamps[0]) /
float(dj.Frequency) * 1000.0f;
1511 ofr.cbWrapper.lastGpuTime = elapsedMs / 1000.0;
1524 return srgb ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM;
1526 return srgb ? DXGI_FORMAT_B8G8R8A8_UNORM_SRGB : DXGI_FORMAT_B8G8R8A8_UNORM;
1528 return DXGI_FORMAT_R8_UNORM;
1530 return DXGI_FORMAT_R8G8_UNORM;
1532 return DXGI_FORMAT_R16_UNORM;
1534 return DXGI_FORMAT_R16G16_UNORM;
1536 return DXGI_FORMAT_R8_UNORM;
1539 return DXGI_FORMAT_R16G16B16A16_FLOAT;
1541 return DXGI_FORMAT_R32G32B32A32_FLOAT;
1543 return DXGI_FORMAT_R16_FLOAT;
1545 return DXGI_FORMAT_R32_FLOAT;
1548 return DXGI_FORMAT_R10G10B10A2_UNORM;
1551 return DXGI_FORMAT_R16_TYPELESS;
1553 return DXGI_FORMAT_R24G8_TYPELESS;
1555 return DXGI_FORMAT_R24G8_TYPELESS;
1557 return DXGI_FORMAT_R32_TYPELESS;
1559 return DXGI_FORMAT_R32G8X24_TYPELESS;
1562 return srgb ? DXGI_FORMAT_BC1_UNORM_SRGB : DXGI_FORMAT_BC1_UNORM;
1564 return srgb ? DXGI_FORMAT_BC2_UNORM_SRGB : DXGI_FORMAT_BC2_UNORM;
1566 return srgb ? DXGI_FORMAT_BC3_UNORM_SRGB : DXGI_FORMAT_BC3_UNORM;
1568 return DXGI_FORMAT_BC4_UNORM;
1570 return DXGI_FORMAT_BC5_UNORM;
1572 return DXGI_FORMAT_BC6H_UF16;
1574 return srgb ? DXGI_FORMAT_BC7_UNORM_SRGB : DXGI_FORMAT_BC7_UNORM;
1579 qWarning(
"QRhiD3D11 does not support ETC2 textures");
1580 return DXGI_FORMAT_R8G8B8A8_UNORM;
1596 qWarning(
"QRhiD3D11 does not support ASTC textures");
1597 return DXGI_FORMAT_R8G8B8A8_UNORM;
1601 return DXGI_FORMAT_R8G8B8A8_UNORM;
1608 case DXGI_FORMAT_R8G8B8A8_UNORM:
1610 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
1614 case DXGI_FORMAT_B8G8R8A8_UNORM:
1616 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
1620 case DXGI_FORMAT_R16G16B16A16_FLOAT:
1622 case DXGI_FORMAT_R32G32B32A32_FLOAT:
1624 case DXGI_FORMAT_R10G10B10A2_UNORM:
1655 ofr.cbWrapper.resetCommands();
1673 UINT subres = D3D11CalcSubresource(UINT(
level), is3D ? 0u : UINT(
layer), texD->mipLevelCount);
1675 box.front = is3D ? UINT(
layer) : 0u;
1677 box.back =
box.front + 1;
1680 cmd.
args.updateSubRes.dst = texD->textureResource();
1681 cmd.
args.updateSubRes.dstSubRes = subres;
1687 int bpl =
img.bytesPerLine();
1692 if (
img.depth() == 32) {
1693 const int offset =
sp.y() *
img.bytesPerLine() +
sp.x() * 4;
1697 bpl =
img.bytesPerLine();
1703 box.left = UINT(dp.x());
1704 box.top = UINT(dp.y());
1705 box.right = UINT(dp.x() +
size.width());
1706 box.bottom = UINT(dp.y() +
size.height());
1707 cmd.
args.updateSubRes.hasDstBox =
true;
1708 cmd.
args.updateSubRes.dstBox =
box;
1709 cmd.
args.updateSubRes.srcRowPitch = UINT(bpl);
1719 box.left = UINT(
aligned(dp.x(), blockDim.width()));
1720 box.top = UINT(
aligned(dp.y(), blockDim.height()));
1721 box.right = UINT(
aligned(dp.x() +
size.width(), blockDim.width()));
1722 box.bottom = UINT(
aligned(dp.y() +
size.height(), blockDim.height()));
1723 cmd.
args.updateSubRes.hasDstBox =
true;
1724 cmd.
args.updateSubRes.dstBox =
box;
1726 cmd.
args.updateSubRes.srcRowPitch = bpl;
1735 box.left = UINT(dp.x());
1736 box.top = UINT(dp.y());
1737 box.right = UINT(dp.x() +
size.width());
1738 box.bottom = UINT(dp.y() +
size.height());
1739 cmd.
args.updateSubRes.hasDstBox =
true;
1740 cmd.
args.updateSubRes.dstBox =
box;
1742 cmd.
args.updateSubRes.srcRowPitch = bpl;
1754 for (
int opIdx = 0; opIdx < ud->activeBufferOpCount; ++opIdx) {
1760 bufD->hasPendingDynamicUpdates =
true;
1767 cmd.
args.updateSubRes.dst = bufD->buffer;
1768 cmd.
args.updateSubRes.dstSubRes = 0;
1770 cmd.
args.updateSubRes.srcRowPitch = 0;
1777 box.back =
box.bottom = 1;
1779 cmd.
args.updateSubRes.hasDstBox =
true;
1780 cmd.
args.updateSubRes.dstBox =
box;
1793 D3D11_BUFFER_DESC desc = {};
1794 desc.ByteWidth = readback.byteSize;
1795 desc.Usage = D3D11_USAGE_STAGING;
1796 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
1797 HRESULT hr =
dev->CreateBuffer(&desc,
nullptr, &readback.stagingBuf);
1799 qWarning(
"Failed to create buffer: %s",
1800 qPrintable(QSystemError::windowsComString(hr)));
1806 cmd.
args.copySubRes.dst = readback.stagingBuf;
1807 cmd.
args.copySubRes.dstSubRes = 0;
1808 cmd.
args.copySubRes.dstX = 0;
1809 cmd.
args.copySubRes.dstY = 0;
1810 cmd.
args.copySubRes.dstZ = 0;
1811 cmd.
args.copySubRes.src = bufD->buffer;
1812 cmd.
args.copySubRes.srcSubRes = 0;
1813 cmd.
args.copySubRes.hasSrcBox =
true;
1817 box.back =
box.bottom = 1;
1819 cmd.
args.copySubRes.srcBox =
box;
1825 for (
int opIdx = 0; opIdx < ud->activeTextureOpCount; ++opIdx) {
1848 srcBox.left = UINT(
sp.x());
1849 srcBox.top = UINT(
sp.y());
1852 srcBox.right = srcBox.left + UINT(copySize.width());
1853 srcBox.bottom = srcBox.top + UINT(copySize.height());
1854 srcBox.back = srcBox.front + 1;
1857 cmd.
args.copySubRes.dst = dstD->textureResource();
1858 cmd.
args.copySubRes.dstSubRes = dstSubRes;
1859 cmd.
args.copySubRes.dstX = UINT(dp.x());
1860 cmd.
args.copySubRes.dstY = UINT(dp.y());
1862 cmd.
args.copySubRes.src = srcD->textureResource();
1863 cmd.
args.copySubRes.srcSubRes = srcSubRes;
1864 cmd.
args.copySubRes.hasSrcBox =
true;
1865 cmd.
args.copySubRes.srcBox = srcBox;
1869 readback.result = u.
result;
1871 ID3D11Resource *
src;
1872 DXGI_FORMAT dxgiFormat;
1881 if (texD->sampleDesc.Count > 1) {
1882 qWarning(
"Multisample texture cannot be read back");
1885 src = texD->textureResource();
1886 dxgiFormat = texD->dxgiFormat;
1887 pixelSize =
q->sizeForMipLevel(u.
rb.
level(), texD->m_pixelSize);
1890 subres = D3D11CalcSubresource(UINT(u.
rb.
level()), UINT(is3D ? 0 : u.
rb.
layer()), texD->mipLevelCount);
1894 if (swapChainD->sampleDesc.Count > 1) {
1899 rcmd.args.resolveSubRes.dst = swapChainD->backBufferTex;
1900 rcmd.args.resolveSubRes.dstSubRes = 0;
1901 rcmd.args.resolveSubRes.src = swapChainD->msaaTex[swapChainD->currentFrameSlot];
1902 rcmd.args.resolveSubRes.srcSubRes = 0;
1903 rcmd.args.resolveSubRes.format = swapChainD->colorFormat;
1905 src = swapChainD->backBufferTex;
1906 dxgiFormat = swapChainD->colorFormat;
1907 pixelSize = swapChainD->pixelSize;
1916 D3D11_TEXTURE2D_DESC desc = {};
1917 desc.Width = UINT(pixelSize.
width());
1918 desc.Height = UINT(pixelSize.
height());
1921 desc.Format = dxgiFormat;
1922 desc.SampleDesc.Count = 1;
1923 desc.Usage = D3D11_USAGE_STAGING;
1924 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
1925 ID3D11Texture2D *stagingTex;
1926 HRESULT hr =
dev->CreateTexture2D(&desc,
nullptr, &stagingTex);
1928 qWarning(
"Failed to create readback staging texture: %s",
1929 qPrintable(QSystemError::windowsComString(hr)));
1935 cmd.
args.copySubRes.dst = stagingTex;
1936 cmd.
args.copySubRes.dstSubRes = 0;
1937 cmd.
args.copySubRes.dstX = 0;
1938 cmd.
args.copySubRes.dstY = 0;
1939 cmd.
args.copySubRes.dstZ = 0;
1940 cmd.
args.copySubRes.src =
src;
1941 cmd.
args.copySubRes.srcSubRes = subres;
1943 D3D11_BOX srcBox = {};
1944 srcBox.front = UINT(u.
rb.
layer());
1945 srcBox.right = desc.Width;
1946 srcBox.bottom = desc.Height;
1947 srcBox.back = srcBox.front + 1;
1948 cmd.
args.copySubRes.hasSrcBox =
true;
1949 cmd.
args.copySubRes.srcBox = srcBox;
1951 cmd.
args.copySubRes.hasSrcBox =
false;
1954 readback.stagingTex = stagingTex;
1955 readback.byteSize = byteSize;
1957 readback.pixelSize = pixelSize;
1958 readback.format =
format;
1978 readback.result->format = readback.format;
1979 readback.result->pixelSize = readback.pixelSize;
1981 D3D11_MAPPED_SUBRESOURCE mp;
1982 HRESULT hr =
context->Map(readback.stagingTex, 0, D3D11_MAP_READ, 0, &mp);
1983 if (SUCCEEDED(hr)) {
1984 readback.result->data.resize(
int(readback.byteSize));
1987 char *
dst = readback.result->data.data();
1988 char *
src =
static_cast<char *
>(mp.pData);
1989 for (
int y = 0,
h = readback.pixelSize.height();
y !=
h; ++
y) {
1990 memcpy(
dst,
src, readback.bpl);
1991 dst += readback.bpl;
1994 context->Unmap(readback.stagingTex, 0);
1996 qWarning(
"Failed to map readback staging texture: %s",
1997 qPrintable(QSystemError::windowsComString(hr)));
2000 readback.stagingTex->Release();
2002 if (readback.result->completed)
2003 completedCallbacks.append(readback.result->completed);
2011 D3D11_MAPPED_SUBRESOURCE mp;
2012 HRESULT hr =
context->Map(readback.stagingBuf, 0, D3D11_MAP_READ, 0, &mp);
2013 if (SUCCEEDED(hr)) {
2014 readback.result->data.resize(
int(readback.byteSize));
2015 memcpy(readback.result->data.data(), mp.pData, readback.byteSize);
2016 context->Unmap(readback.stagingBuf, 0);
2018 qWarning(
"Failed to map readback staging texture: %s",
2019 qPrintable(QSystemError::windowsComString(hr)));
2022 readback.stagingBuf->Release();
2024 if (readback.result->completed)
2025 completedCallbacks.append(readback.result->completed);
2030 for (
auto f : completedCallbacks)
2043 const QColor &colorClearValue,
2046 QRhiCommandBuffer::BeginPassFlags)
2051 if (resourceUpdates)
2054 bool wantsColorClear =
true;
2055 bool wantsDsClear =
true;
2061 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QD3D11Texture, QD3D11RenderBuffer>(rtTex->description(), rtD->currentResIdList))
2069 fbCmd.args.setRenderTarget.rt = rt;
2073 clearCmd.args.clear.rt = rt;
2074 clearCmd.args.clear.mask = 0;
2075 if (rtD->colorAttCount && wantsColorClear)
2077 if (rtD->dsAttCount && wantsDsClear)
2080 clearCmd.args.clear.c[0] = float(colorClearValue.redF());
2081 clearCmd.args.clear.c[1] = float(colorClearValue.greenF());
2082 clearCmd.args.clear.c[2] = float(colorClearValue.blueF());
2083 clearCmd.args.clear.c[3] = float(colorClearValue.alphaF());
2084 clearCmd.args.clear.d = depthStencilClearValue.depthClearValue();
2085 clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue();
2100 for (
auto it = rtTex->m_desc.cbeginColorAttachments(), itEnd = rtTex->m_desc.cendColorAttachments();
2113 cmd.
args.resolveSubRes.dst = dstTexD->textureResource();
2114 cmd.
args.resolveSubRes.dstSubRes = D3D11CalcSubresource(UINT(colorAtt.
resolveLevel()),
2116 dstTexD->mipLevelCount);
2118 cmd.
args.resolveSubRes.src = srcTexD->textureResource();
2119 if (srcTexD->dxgiFormat != dstTexD->dxgiFormat) {
2120 qWarning(
"Resolve source (%d) and destination (%d) formats do not match",
2121 int(srcTexD->dxgiFormat),
int(dstTexD->dxgiFormat));
2125 if (srcTexD->sampleDesc.Count <= 1) {
2126 qWarning(
"Cannot resolve a non-multisample texture");
2130 if (srcTexD->m_pixelSize != dstTexD->m_pixelSize) {
2131 qWarning(
"Resolve source and destination sizes do not match");
2136 cmd.
args.resolveSubRes.src = srcRbD->tex;
2137 if (srcRbD->dxgiFormat != dstTexD->dxgiFormat) {
2138 qWarning(
"Resolve source (%d) and destination (%d) formats do not match",
2139 int(srcRbD->dxgiFormat),
int(dstTexD->dxgiFormat));
2143 if (srcRbD->m_pixelSize != dstTexD->m_pixelSize) {
2144 qWarning(
"Resolve source and destination sizes do not match");
2149 cmd.
args.resolveSubRes.srcSubRes = D3D11CalcSubresource(0, UINT(colorAtt.
layer()), 1);
2150 cmd.
args.resolveSubRes.format = dstTexD->dxgiFormat;
2152 if (rtTex->m_desc.depthResolveTexture())
2153 qWarning(
"Resolving multisample depth-stencil buffers is not supported with D3D");
2159 if (resourceUpdates)
2165 QRhiCommandBuffer::BeginPassFlags)
2170 if (resourceUpdates)
2188 if (resourceUpdates)
2199 if (pipelineChanged) {
2206 cmd.
args.bindComputePipeline.ps = psD;
2217 cmd.
args.dispatch.x = UINT(
x);
2218 cmd.
args.dispatch.y = UINT(
y);
2219 cmd.
args.dispatch.z = UINT(
z);
2228 return { binding, binding };
2243 srbD->vsUniformBufferBatches.
clear();
2244 srbD->hsUniformBufferBatches.clear();
2245 srbD->dsUniformBufferBatches.clear();
2246 srbD->gsUniformBufferBatches.clear();
2247 srbD->fsUniformBufferBatches.clear();
2248 srbD->csUniformBufferBatches.clear();
2250 srbD->vsSamplerBatches.clear();
2251 srbD->hsSamplerBatches.clear();
2252 srbD->dsSamplerBatches.clear();
2253 srbD->gsSamplerBatches.clear();
2254 srbD->fsSamplerBatches.clear();
2255 srbD->csSamplerBatches.clear();
2257 srbD->csUavBatches.clear();
2264 uint offsetInConstants;
2265 uint sizeInConstants;
2269 ID3D11ShaderResourceView *srv;
2277 ID3D11UnorderedAccessView *uav;
2279 QVarLengthArray<Buffer, 8>
buffers;
2280 QVarLengthArray<Texture, 8>
textures;
2281 QVarLengthArray<Sampler, 8>
samplers;
2282 QVarLengthArray<Uav, 8> uavs;
2303 for (
const Stage::Uav &u : uavs)
2309 for (
int i = 0, ie = srbD->sortedBindings.count();
i != ie; ++
i) {
2317 bd.ubuf.id = bufD->m_id;
2318 bd.ubuf.generation = bufD->generation;
2325 const quint32 offsetInConstants =
b->u.ubuf.offset / 16;
2329 const quint32 sizeInConstants =
aligned(
b->u.ubuf.maybeSize ?
b->u.ubuf.maybeSize : bufD->m_size, 256u) / 16;
2332 if (nativeBinding.first >= 0)
2333 res[
RBM_VERTEX].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2336 QPair<int, int> nativeBinding =
mapBinding(
b->binding,
RBM_HULL, nativeResourceBindingMaps);
2337 if (nativeBinding.first >= 0)
2338 res[
RBM_HULL].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2342 if (nativeBinding.first >= 0)
2343 res[
RBM_DOMAIN].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2347 if (nativeBinding.first >= 0)
2348 res[
RBM_GEOMETRY].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2352 if (nativeBinding.first >= 0)
2353 res[
RBM_FRAGMENT].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2357 if (nativeBinding.first >= 0)
2358 res[
RBM_COMPUTE].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2368 const QPair<int, int> nativeBindingVert =
mapBinding(
b->binding,
RBM_VERTEX, nativeResourceBindingMaps);
2369 const QPair<int, int> nativeBindingHull =
mapBinding(
b->binding,
RBM_HULL, nativeResourceBindingMaps);
2370 const QPair<int, int> nativeBindingDomain =
mapBinding(
b->binding,
RBM_DOMAIN, nativeResourceBindingMaps);
2373 const QPair<int, int> nativeBindingComp =
mapBinding(
b->binding,
RBM_COMPUTE, nativeResourceBindingMaps);
2377 for (
int elem = 0; elem <
data->count; ++elem) {
2380 bd.stex.d[elem].texId = texD ? texD->m_id : 0;
2381 bd.stex.d[elem].texGeneration = texD ? texD->generation : 0;
2382 bd.stex.d[elem].samplerId = samplerD ? samplerD->m_id : 0;
2383 bd.stex.d[elem].samplerGeneration = samplerD ? samplerD->generation : 0;
2389 const int samplerBinding = texD && samplerD ? nativeBindingVert.second
2390 : (samplerD ? nativeBindingVert.first : -1);
2391 if (nativeBindingVert.first >= 0 && texD)
2392 res[
RBM_VERTEX].textures.append({ nativeBindingVert.first + elem, texD->srv });
2393 if (samplerBinding >= 0)
2394 res[
RBM_VERTEX].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2397 const int samplerBinding = texD && samplerD ? nativeBindingHull.second
2398 : (samplerD ? nativeBindingHull.first : -1);
2399 if (nativeBindingHull.first >= 0 && texD)
2400 res[
RBM_HULL].textures.append({ nativeBindingHull.first + elem, texD->srv });
2401 if (samplerBinding >= 0)
2402 res[
RBM_HULL].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2405 const int samplerBinding = texD && samplerD ? nativeBindingDomain.second
2406 : (samplerD ? nativeBindingDomain.first : -1);
2407 if (nativeBindingDomain.first >= 0 && texD)
2408 res[
RBM_DOMAIN].textures.append({ nativeBindingDomain.first + elem, texD->srv });
2409 if (samplerBinding >= 0)
2410 res[
RBM_DOMAIN].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2413 const int samplerBinding = texD && samplerD ? nativeBindingGeom.second
2414 : (samplerD ? nativeBindingGeom.first : -1);
2415 if (nativeBindingGeom.first >= 0 && texD)
2416 res[
RBM_GEOMETRY].textures.append({ nativeBindingGeom.first + elem, texD->srv });
2417 if (samplerBinding >= 0)
2418 res[
RBM_GEOMETRY].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2421 const int samplerBinding = texD && samplerD ? nativeBindingFrag.second
2422 : (samplerD ? nativeBindingFrag.first : -1);
2423 if (nativeBindingFrag.first >= 0 && texD)
2424 res[
RBM_FRAGMENT].textures.append({ nativeBindingFrag.first + elem, texD->srv });
2425 if (samplerBinding >= 0)
2426 res[
RBM_FRAGMENT].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2429 const int samplerBinding = texD && samplerD ? nativeBindingComp.second
2430 : (samplerD ? nativeBindingComp.first : -1);
2431 if (nativeBindingComp.first >= 0 && texD)
2432 res[
RBM_COMPUTE].textures.append({ nativeBindingComp.first + elem, texD->srv });
2433 if (samplerBinding >= 0)
2434 res[
RBM_COMPUTE].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2444 bd.simage.id = texD->m_id;
2445 bd.simage.generation = texD->generation;
2448 if (nativeBinding.first >= 0) {
2449 ID3D11UnorderedAccessView *uav = texD->unorderedAccessViewForLevel(
b->u.simage.level);
2454 qWarning(
"Unordered access only supported at compute stage");
2463 bd.sbuf.id = bufD->m_id;
2464 bd.sbuf.generation = bufD->generation;
2467 if (nativeBinding.first >= 0) {
2468 ID3D11UnorderedAccessView *uav = bufD->unorderedAccessView(
b->u.sbuf.offset);
2473 qWarning(
"Unordered access only supported at compute stage");
2488 std::sort(
res[stage].
buffers.begin(),
res[stage].buffers.end(), [](
const Stage::Buffer &
a,
const Stage::Buffer &
b) {
2489 return a.breg < b.breg;
2491 std::sort(
res[stage].
textures.begin(),
res[stage].textures.end(), [](
const Stage::Texture &
a,
const Stage::Texture &
b) {
2492 return a.treg < b.treg;
2494 std::sort(
res[stage].
samplers.begin(),
res[stage].samplers.end(), [](
const Stage::Sampler &
a,
const Stage::Sampler &
b) {
2495 return a.sreg < b.sreg;
2497 std::sort(
res[stage].uavs.begin(),
res[stage].uavs.end(), [](
const Stage::Uav &
a,
const Stage::Uav &
b) {
2498 return a.ureg < b.ureg;
2502 res[
RBM_VERTEX].buildBufferBatches(srbD->vsUniformBufferBatches);
2503 res[
RBM_HULL].buildBufferBatches(srbD->hsUniformBufferBatches);
2504 res[
RBM_DOMAIN].buildBufferBatches(srbD->dsUniformBufferBatches);
2507 res[
RBM_COMPUTE].buildBufferBatches(srbD->csUniformBufferBatches);
2509 res[
RBM_VERTEX].buildSamplerBatches(srbD->vsSamplerBatches);
2510 res[
RBM_HULL].buildSamplerBatches(srbD->hsSamplerBatches);
2511 res[
RBM_DOMAIN].buildSamplerBatches(srbD->dsSamplerBatches);
2521 if (!bufD->hasPendingDynamicUpdates || bufD->m_size < 1)
2525 bufD->hasPendingDynamicUpdates =
false;
2526 D3D11_MAPPED_SUBRESOURCE mp;
2527 HRESULT hr =
context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
2528 if (SUCCEEDED(hr)) {
2529 memcpy(mp.pData, bufD->dynBuf, bufD->m_size);
2530 context->Unmap(bufD->buffer, 0);
2532 qWarning(
"Failed to map buffer: %s",
2533 qPrintable(QSystemError::windowsComString(hr)));
2539 const QRhiBatchedBindings<UINT> *originalBindings,
2540 const QRhiBatchedBindings<UINT> *staticOffsets,
2541 const uint *dynOfsPairs,
int dynOfsPairCount)
2543 const int count = staticOffsets->batches[batchIndex].resources.count();
2547 offsets[
b] = staticOffsets->batches[batchIndex].resources[
b];
2548 for (
int di = 0; di < dynOfsPairCount; ++di) {
2549 const uint binding = dynOfsPairs[2 * di];
2552 if (binding == originalBindings->batches[batchIndex].resources[
b]) {
2553 const uint offsetInConstants = dynOfsPairs[2 * di + 1];
2563 if (startSlot + countSlots > maxSlots) {
2564 qWarning(
"Not enough D3D11 %s slots to bind %d resources starting at slot %d, max slots is %d",
2565 resType, countSlots, startSlot, maxSlots);
2566 countSlots = maxSlots > startSlot ? maxSlots - startSlot : 0;
2571#define SETUBUFBATCH(stagePrefixL, stagePrefixU) \
2572 if (srbD->stagePrefixL##UniformBufferBatches.present) { \
2573 const QD3D11ShaderResourceBindings::StageUniformBufferBatches &batches(srbD->stagePrefixL##UniformBufferBatches); \
2574 for (int i = 0, ie = batches.ubufs.batches.count(); i != ie; ++i) { \
2575 const uint count = clampedResourceCount(batches.ubufs.batches[i].startBinding, \
2576 batches.ubufs.batches[i].resources.count(), \
2577 D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, \
2578 #stagePrefixU " cbuf"); \
2580 if (!dynOfsPairCount) { \
2581 context->stagePrefixU##SetConstantBuffers1(batches.ubufs.batches[i].startBinding, \
2583 batches.ubufs.batches[i].resources.constData(), \
2584 batches.ubufoffsets.batches[i].resources.constData(), \
2585 batches.ubufsizes.batches[i].resources.constData()); \
2587 applyDynamicOffsets(offsets, i, \
2588 &batches.ubuforigbindings, &batches.ubufoffsets, \
2589 dynOfsPairs, dynOfsPairCount); \
2590 context->stagePrefixU##SetConstantBuffers1(batches.ubufs.batches[i].startBinding, \
2592 batches.ubufs.batches[i].resources.constData(), \
2594 batches.ubufsizes.batches[i].resources.constData()); \
2600#define SETSAMPLERBATCH(stagePrefixL, stagePrefixU) \
2601 if (srbD->stagePrefixL##SamplerBatches.present) { \
2602 for (const auto &batch : srbD->stagePrefixL##SamplerBatches.samplers.batches) { \
2603 const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
2604 D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, #stagePrefixU " sampler"); \
2606 context->stagePrefixU##SetSamplers(batch.startBinding, count, batch.resources.constData()); \
2608 for (const auto &batch : srbD->stagePrefixL##SamplerBatches.shaderresources.batches) { \
2609 const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
2610 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, #stagePrefixU " SRV"); \
2612 context->stagePrefixU##SetShaderResources(batch.startBinding, count, batch.resources.constData()); \
2613 contextState.stagePrefixL##HighestActiveSrvBinding = qMax(contextState.stagePrefixL##HighestActiveSrvBinding, \
2614 int(batch.startBinding + count) - 1); \
2619#define SETUAVBATCH(stagePrefixL, stagePrefixU) \
2620 if (srbD->stagePrefixL##UavBatches.present) { \
2621 for (const auto &batch : srbD->stagePrefixL##UavBatches.uavs.batches) { \
2622 const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
2623 D3D11_1_UAV_SLOT_COUNT, #stagePrefixU " UAV"); \
2625 context->stagePrefixU##SetUnorderedAccessViews(batch.startBinding, \
2627 batch.resources.constData(), \
2629 contextState.stagePrefixL##HighestActiveUavBinding = qMax(contextState.stagePrefixL##HighestActiveUavBinding, \
2630 int(batch.startBinding + count) - 1); \
2636 const uint *dynOfsPairs,
int dynOfsPairCount,
2637 bool offsetOnlyChange)
2648 if (!offsetOnlyChange) {
2665 context->IASetIndexBuffer(
nullptr, DXGI_FORMAT_R16_UINT, 0);
2669 if (
contextState.vsHighestActiveVertexBufferBinding >= 0) {
2671 QVarLengthArray<ID3D11Buffer *, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nullbufs(
count);
2673 nullbufs[
i] =
nullptr;
2674 QVarLengthArray<UINT, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nullstrides(
count);
2677 QVarLengthArray<UINT, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nulloffsets(
count);
2680 context->IASetVertexBuffers(0, UINT(
count), nullbufs.constData(), nullstrides.constData(), nulloffsets.constData());
2690 if (nullsrvCount > 0) {
2692 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> nullsrvs(nullsrvCount);
2693 for (
int i = 0;
i < nullsrvs.count(); ++
i)
2694 nullsrvs[
i] =
nullptr;
2696 context->VSSetShaderResources(0, UINT(
contextState.vsHighestActiveSrvBinding + 1), nullsrvs.constData());
2700 context->HSSetShaderResources(0, UINT(
contextState.hsHighestActiveSrvBinding + 1), nullsrvs.constData());
2704 context->DSSetShaderResources(0, UINT(
contextState.dsHighestActiveSrvBinding + 1), nullsrvs.constData());
2708 context->GSSetShaderResources(0, UINT(
contextState.gsHighestActiveSrvBinding + 1), nullsrvs.constData());
2712 context->PSSetShaderResources(0, UINT(
contextState.fsHighestActiveSrvBinding + 1), nullsrvs.constData());
2716 context->CSSetShaderResources(0, UINT(
contextState.csHighestActiveSrvBinding + 1), nullsrvs.constData());
2722 const int nulluavCount =
contextState.csHighestActiveUavBinding + 1;
2724 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> nulluavs(nulluavCount);
2725 for (
int i = 0;
i < nulluavCount; ++
i)
2726 nulluavs[
i] =
nullptr;
2727 context->CSSetUnorderedAccessViews(0, UINT(nulluavCount), nulluavs.constData(),
nullptr);
2732#define SETSHADER(StageL, StageU) \
2733 if (psD->StageL.shader) { \
2734 context->StageU##SetShader(psD->StageL.shader, nullptr, 0); \
2735 currentShaderMask |= StageU##MaskBit; \
2736 } else if (currentShaderMask & StageU##MaskBit) { \
2737 context->StageU##SetShader(nullptr, nullptr, 0); \
2738 currentShaderMask &= ~StageU##MaskBit; \
2744 float blendConstants[] = { 1, 1, 1, 1 };
2745 enum ActiveShaderMask {
2752 int currentShaderMask = 0xFF;
2758 if (cmd.
args.beginFrame.tsDisjointQuery)
2759 context->Begin(cmd.
args.beginFrame.tsDisjointQuery);
2760 if (cmd.
args.beginFrame.tsQuery) {
2761 if (cmd.
args.beginFrame.swapchainData) {
2767 context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv :
nullptr, rtD->dsv);
2773 if (cmd.
args.endFrame.tsQuery)
2775 if (cmd.
args.endFrame.tsDisjointQuery)
2784 context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv :
nullptr, rtD->dsv);
2791 for (
int i = 0;
i < rtD->colorAttCount; ++
i)
2792 context->ClearRenderTargetView(rtD->rtv[
i], cmd.
args.clear.c);
2796 ds |= D3D11_CLEAR_DEPTH;
2798 ds |= D3D11_CLEAR_STENCIL;
2800 context->ClearDepthStencilView(rtD->dsv, ds, cmd.
args.clear.d, UINT8(cmd.
args.clear.s));
2806 v.TopLeftX = cmd.
args.viewport.x;
2807 v.TopLeftY = cmd.
args.viewport.y;
2808 v.Width = cmd.
args.viewport.w;
2809 v.Height = cmd.
args.viewport.h;
2810 v.MinDepth = cmd.
args.viewport.d0;
2811 v.MaxDepth = cmd.
args.viewport.d1;
2818 r.left = cmd.
args.scissor.x;
2819 r.top = cmd.
args.scissor.y;
2821 r.right = cmd.
args.scissor.x + cmd.
args.scissor.w;
2822 r.bottom = cmd.
args.scissor.y + cmd.
args.scissor.h;
2827 contextState.vsHighestActiveVertexBufferBinding = qMax<int>(
2829 cmd.
args.bindVertexBuffers.startSlot + cmd.
args.bindVertexBuffers.slotCount - 1);
2830 context->IASetVertexBuffers(UINT(cmd.
args.bindVertexBuffers.startSlot),
2831 UINT(cmd.
args.bindVertexBuffers.slotCount),
2832 cmd.
args.bindVertexBuffers.buffers,
2833 cmd.
args.bindVertexBuffers.strides,
2834 cmd.
args.bindVertexBuffers.offsets);
2838 context->IASetIndexBuffer(cmd.
args.bindIndexBuffer.buffer,
2839 cmd.
args.bindIndexBuffer.format,
2840 cmd.
args.bindIndexBuffer.offset);
2850 context->IASetPrimitiveTopology(psD->d3dTopology);
2851 context->IASetInputLayout(psD->inputLayout);
2852 context->OMSetDepthStencilState(psD->dsState, stencilRef);
2853 context->OMSetBlendState(psD->blendState, blendConstants, 0xffffffff);
2854 context->RSSetState(psD->rastState);
2859 cmd.
args.bindShaderResources.dynamicOffsetPairs,
2860 cmd.
args.bindShaderResources.dynamicOffsetCount,
2861 cmd.
args.bindShaderResources.offsetOnlyChange);
2864 stencilRef = cmd.
args.stencilRef.ref;
2865 context->OMSetDepthStencilState(cmd.
args.stencilRef.ps->dsState, stencilRef);
2868 memcpy(blendConstants, cmd.
args.blendConstants.c, 4 *
sizeof(
float));
2869 context->OMSetBlendState(cmd.
args.blendConstants.ps->blendState, blendConstants, 0xffffffff);
2872 if (cmd.
args.draw.ps) {
2873 if (cmd.
args.draw.instanceCount == 1)
2876 context->DrawInstanced(cmd.
args.draw.vertexCount, cmd.
args.draw.instanceCount,
2877 cmd.
args.draw.firstVertex, cmd.
args.draw.firstInstance);
2879 qWarning(
"No graphics pipeline active for draw; ignored");
2883 if (cmd.
args.drawIndexed.ps) {
2884 if (cmd.
args.drawIndexed.instanceCount == 1)
2885 context->DrawIndexed(cmd.
args.drawIndexed.indexCount, cmd.
args.drawIndexed.firstIndex,
2886 cmd.
args.drawIndexed.vertexOffset);
2888 context->DrawIndexedInstanced(cmd.
args.drawIndexed.indexCount, cmd.
args.drawIndexed.instanceCount,
2889 cmd.
args.drawIndexed.firstIndex, cmd.
args.drawIndexed.vertexOffset,
2890 cmd.
args.drawIndexed.firstInstance);
2892 qWarning(
"No graphics pipeline active for drawIndexed; ignored");
2896 context->UpdateSubresource(cmd.
args.updateSubRes.dst, cmd.
args.updateSubRes.dstSubRes,
2897 cmd.
args.updateSubRes.hasDstBox ? &cmd.
args.updateSubRes.dstBox :
nullptr,
2898 cmd.
args.updateSubRes.src, cmd.
args.updateSubRes.srcRowPitch, 0);
2901 context->CopySubresourceRegion(cmd.
args.copySubRes.dst, cmd.
args.copySubRes.dstSubRes,
2902 cmd.
args.copySubRes.dstX, cmd.
args.copySubRes.dstY, cmd.
args.copySubRes.dstZ,
2903 cmd.
args.copySubRes.src, cmd.
args.copySubRes.srcSubRes,
2904 cmd.
args.copySubRes.hasSrcBox ? &cmd.
args.copySubRes.srcBox :
nullptr);
2907 context->ResolveSubresource(cmd.
args.resolveSubRes.dst, cmd.
args.resolveSubRes.dstSubRes,
2908 cmd.
args.resolveSubRes.src, cmd.
args.resolveSubRes.srcSubRes,
2909 cmd.
args.resolveSubRes.format);
2924 context->CSSetShader(cmd.
args.bindComputePipeline.ps->cs.shader,
nullptr, 0);
2957 it.value()->Release();
2962 rhiD->unregisterResource(
this);
2969 u |= D3D11_BIND_VERTEX_BUFFER;
2971 u |= D3D11_BIND_INDEX_BUFFER;
2973 u |= D3D11_BIND_CONSTANT_BUFFER;
2975 u |= D3D11_BIND_UNORDERED_ACCESS;
2985 qWarning(
"UniformBuffer must always be combined with Dynamic on D3D11");
2990 qWarning(
"StorageBuffer cannot be combined with Dynamic");
2997 D3D11_BUFFER_DESC desc = {};
2998 desc.ByteWidth = roundedSize;
2999 desc.Usage =
m_type ==
Dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
3001 desc.CPUAccessFlags =
m_type ==
Dynamic ? D3D11_CPU_ACCESS_WRITE : 0;
3005 HRESULT hr = rhiD->dev->CreateBuffer(&desc,
nullptr, &
buffer);
3007 qWarning(
"Failed to create buffer: %s",
3008 qPrintable(QSystemError::windowsComString(hr)));
3013 dynBuf =
new char[nonZeroSize];
3021 rhiD->registerResource(
this);
3029 rhiD->executeBufferHostWrites(
this);
3031 return { { &
buffer }, 1 };
3043 D3D11_MAPPED_SUBRESOURCE mp;
3045 HRESULT hr = rhiD->context->Map(
buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
3047 qWarning(
"Failed to map buffer: %s",
3048 qPrintable(QSystemError::windowsComString(hr)));
3051 return static_cast<char *
>(mp.pData);
3057 rhiD->context->Unmap(
buffer, 0);
3067 D3D11_UNORDERED_ACCESS_VIEW_DESC desc = {};
3068 desc.Format = DXGI_FORMAT_R32_TYPELESS;
3069 desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
3070 desc.Buffer.FirstElement =
offset / 4u;
3072 desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
3075 ID3D11UnorderedAccessView *uav =
nullptr;
3076 HRESULT hr = rhiD->dev->CreateUnorderedAccessView(
buffer, &desc, &uav);
3078 qWarning(
"Failed to create UAV: %s",
3079 qPrintable(QSystemError::windowsComString(hr)));
3088 int sampleCount, QRhiRenderBuffer::Flags
flags,
3119 rhiD->unregisterResource(
this);
3133 D3D11_TEXTURE2D_DESC desc = {};
3139 desc.Usage = D3D11_USAGE_DEFAULT;
3145 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3146 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, &
tex);
3148 qWarning(
"Failed to create color renderbuffer: %s",
3149 qPrintable(QSystemError::windowsComString(hr)));
3152 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
3154 rtvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS
3155 : D3D11_RTV_DIMENSION_TEXTURE2D;
3156 hr = rhiD->dev->CreateRenderTargetView(
tex, &rtvDesc, &
rtv);
3158 qWarning(
"Failed to create rtv: %s",
3159 qPrintable(QSystemError::windowsComString(hr)));
3165 desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3166 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, &
tex);
3168 qWarning(
"Failed to create depth-stencil buffer: %s",
3169 qPrintable(QSystemError::windowsComString(hr)));
3172 D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
3174 dsvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS
3175 : D3D11_DSV_DIMENSION_TEXTURE2D;
3176 hr = rhiD->dev->CreateDepthStencilView(
tex, &dsvDesc, &
dsv);
3178 qWarning(
"Failed to create dsv: %s",
3179 qPrintable(QSystemError::windowsComString(hr)));
3190 rhiD->registerResource(
this);
3247 rhiD->unregisterResource(
this);
3254 return DXGI_FORMAT_R16_FLOAT;
3256 return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
3258 return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
3260 return DXGI_FORMAT_R32_FLOAT;
3262 return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
3265 return DXGI_FORMAT_R32_FLOAT;
3273 return DXGI_FORMAT_D16_UNORM;
3275 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3277 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3279 return DXGI_FORMAT_D32_FLOAT;
3281 return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
3284 return DXGI_FORMAT_D32_FLOAT;
3309 qWarning(
"Cubemap texture cannot be multisample");
3313 qWarning(
"3D texture cannot be multisample");
3317 qWarning(
"Multisample texture cannot have mipmaps");
3321 if (isDepth && hasMipMaps) {
3322 qWarning(
"Depth texture cannot have mipmaps");
3325 if (isCube && is3D) {
3326 qWarning(
"Texture cannot be both cube and 3D");
3329 if (isArray && is3D) {
3330 qWarning(
"Texture cannot be both array and 3D");
3333 if (isCube && is1D) {
3334 qWarning(
"Texture cannot be both cube and 1D");
3338 qWarning(
"Texture cannot be both 1D and 3D");
3342 qWarning(
"Texture cannot have a depth of %d when it is not 3D",
m_depth);
3355 *adjustedSize =
size;
3369 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
3372 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
3377 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
3383 srvDesc.Texture1DArray.FirstArraySlice = 0;
3387 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
3390 }
else if (isArray) {
3392 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
3397 srvDesc.Texture2DMSArray.FirstArraySlice = 0;
3401 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
3407 srvDesc.Texture2DArray.FirstArraySlice = 0;
3413 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
3415 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
3418 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
3426 qWarning(
"Failed to create srv: %s",
3427 qPrintable(QSystemError::windowsComString(hr)));
3447 uint bindFlags = D3D11_BIND_SHADER_RESOURCE;
3448 uint miscFlags = isCube ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0;
3451 bindFlags |= D3D11_BIND_DEPTH_STENCIL;
3453 bindFlags |= D3D11_BIND_RENDER_TARGET;
3457 qWarning(
"Depth texture cannot have mipmaps generated");
3460 bindFlags |= D3D11_BIND_RENDER_TARGET;
3461 miscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
3464 bindFlags |= D3D11_BIND_UNORDERED_ACCESS;
3468 D3D11_TEXTURE1D_DESC desc = {};
3469 desc.Width = UINT(
size.width());
3473 desc.Usage = D3D11_USAGE_DEFAULT;
3474 desc.BindFlags = bindFlags;
3475 desc.MiscFlags = miscFlags;
3477 HRESULT hr = rhiD->dev->CreateTexture1D(&desc,
nullptr, &
tex1D);
3479 qWarning(
"Failed to create 1D texture: %s",
3480 qPrintable(QSystemError::windowsComString(hr)));
3487 D3D11_TEXTURE2D_DESC desc = {};
3488 desc.Width = UINT(
size.width());
3489 desc.Height = UINT(
size.height());
3491 desc.ArraySize = isCube ? 6 : (isArray ? UINT(
qMax(0,
m_arraySize)) : 1);
3494 desc.Usage = D3D11_USAGE_DEFAULT;
3495 desc.BindFlags = bindFlags;
3496 desc.MiscFlags = miscFlags;
3498 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, &
tex);
3500 qWarning(
"Failed to create 2D texture: %s",
3501 qPrintable(QSystemError::windowsComString(hr)));
3507 D3D11_TEXTURE3D_DESC desc = {};
3508 desc.Width = UINT(
size.width());
3509 desc.Height = UINT(
size.height());
3513 desc.Usage = D3D11_USAGE_DEFAULT;
3514 desc.BindFlags = bindFlags;
3515 desc.MiscFlags = miscFlags;
3517 HRESULT hr = rhiD->dev->CreateTexture3D(&desc,
nullptr, &
tex3D);
3519 qWarning(
"Failed to create 3D texture: %s",
3520 qPrintable(QSystemError::windowsComString(hr)));
3531 rhiD->registerResource(
this);
3544 tex3D =
reinterpret_cast<ID3D11Texture3D *
>(
src.object);
3546 tex1D =
reinterpret_cast<ID3D11Texture1D *
>(
src.object);
3548 tex =
reinterpret_cast<ID3D11Texture2D *
>(
src.object);
3555 rhiD->registerResource(
this);
3572 D3D11_UNORDERED_ACCESS_VIEW_DESC desc = {};
3575 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
3576 desc.Texture2DArray.MipSlice = UINT(
level);
3577 desc.Texture2DArray.FirstArraySlice = 0;
3578 desc.Texture2DArray.ArraySize = 6;
3579 }
else if (isArray) {
3580 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
3581 desc.Texture2DArray.MipSlice = UINT(
level);
3582 desc.Texture2DArray.FirstArraySlice = 0;
3585 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
3586 desc.Texture3D.MipSlice = UINT(
level);
3588 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
3589 desc.Texture2D.MipSlice = UINT(
level);
3593 ID3D11UnorderedAccessView *uav =
nullptr;
3596 qWarning(
"Failed to create UAV: %s",
3597 qPrintable(QSystemError::windowsComString(hr)));
3607 :
QRhiSampler(rhi, magFilter, minFilter, mipmapMode, u,
v,
w)
3626 rhiD->unregisterResource(
this);
3634 return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
3636 return D3D11_FILTER_MIN_MAG_MIP_POINT;
3639 return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
3641 return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
3646 return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
3648 return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
3651 return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
3653 return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
3658 return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
3665 return D3D11_TEXTURE_ADDRESS_WRAP;
3667 return D3D11_TEXTURE_ADDRESS_CLAMP;
3669 return D3D11_TEXTURE_ADDRESS_MIRROR;
3672 return D3D11_TEXTURE_ADDRESS_CLAMP;
3680 return D3D11_COMPARISON_NEVER;
3682 return D3D11_COMPARISON_LESS;
3684 return D3D11_COMPARISON_EQUAL;
3686 return D3D11_COMPARISON_LESS_EQUAL;
3688 return D3D11_COMPARISON_GREATER;
3690 return D3D11_COMPARISON_NOT_EQUAL;
3692 return D3D11_COMPARISON_GREATER_EQUAL;
3694 return D3D11_COMPARISON_ALWAYS;
3697 return D3D11_COMPARISON_NEVER;
3706 D3D11_SAMPLER_DESC desc = {};
3709 desc.Filter = D3D11_FILTER(desc.Filter | 0x80);
3713 desc.MaxAnisotropy = 1.0f;
3720 qWarning(
"Failed to create sampler state: %s",
3721 qPrintable(QSystemError::windowsComString(hr)));
3726 rhiD->registerResource(
this);
3745 rhiD->unregisterResource(
this);
3758 rhiD->registerResource(rpD,
false);
3836 rhiD->unregisterResource(
this);
3843 rhiD->registerResource(rpD,
false);
3868 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
3871 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
3872 rtvDesc.Texture2DArray.MipSlice = UINT(colorAtt.
level());
3873 rtvDesc.Texture2DArray.FirstArraySlice = UINT(colorAtt.
layer());
3874 rtvDesc.Texture2DArray.ArraySize = 1;
3877 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
3878 rtvDesc.Texture1DArray.MipSlice = UINT(colorAtt.
level());
3879 rtvDesc.Texture1DArray.FirstArraySlice = UINT(colorAtt.
layer());
3880 rtvDesc.Texture1DArray.ArraySize = 1;
3882 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
3883 rtvDesc.Texture1D.MipSlice = UINT(colorAtt.
level());
3886 if (texD->sampleDesc.Count > 1) {
3887 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
3888 rtvDesc.Texture2DMSArray.FirstArraySlice = UINT(colorAtt.
layer());
3889 rtvDesc.Texture2DMSArray.ArraySize = 1;
3891 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
3892 rtvDesc.Texture2DArray.MipSlice = UINT(colorAtt.
level());
3893 rtvDesc.Texture2DArray.FirstArraySlice = UINT(colorAtt.
layer());
3894 rtvDesc.Texture2DArray.ArraySize = 1;
3897 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
3898 rtvDesc.Texture3D.MipSlice = UINT(colorAtt.
level());
3899 rtvDesc.Texture3D.FirstWSlice = UINT(colorAtt.
layer());
3900 rtvDesc.Texture3D.WSize = 1;
3902 if (texD->sampleDesc.Count > 1) {
3903 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
3905 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
3906 rtvDesc.Texture2D.MipSlice = UINT(colorAtt.
level());
3909 HRESULT hr = rhiD->dev->CreateRenderTargetView(texD->textureResource(), &rtvDesc, &
rtv[attIndex]);
3911 qWarning(
"Failed to create rtv: %s",
3912 qPrintable(QSystemError::windowsComString(hr)));
3916 if (attIndex == 0) {
3917 d.
pixelSize = rhiD->q->sizeForMipLevel(colorAtt.
level(), texD->pixelSize());
3923 rtv[attIndex] = rbD->rtv;
3924 if (attIndex == 0) {
3932 if (hasDepthStencil) {
3936 D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
3938 dsvDesc.ViewDimension = depthTexD->sampleDesc.Count > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS
3939 : D3D11_DSV_DIMENSION_TEXTURE2D;
3941 if (depthTexD->sampleDesc.Count > 1) {
3942 dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
3943 if (depthTexD->arrayRangeStart() >= 0 && depthTexD->arrayRangeLength() >= 0) {
3944 dsvDesc.Texture2DMSArray.FirstArraySlice = UINT(depthTexD->arrayRangeStart());
3945 dsvDesc.Texture2DMSArray.ArraySize = UINT(depthTexD->arrayRangeLength());
3947 dsvDesc.Texture2DMSArray.FirstArraySlice = 0;
3948 dsvDesc.Texture2DMSArray.ArraySize = UINT(
qMax(0, depthTexD->arraySize()));
3951 dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
3952 if (depthTexD->arrayRangeStart() >= 0 && depthTexD->arrayRangeLength() >= 0) {
3953 dsvDesc.Texture2DArray.FirstArraySlice = UINT(depthTexD->arrayRangeStart());
3954 dsvDesc.Texture2DArray.ArraySize = UINT(depthTexD->arrayRangeLength());
3956 dsvDesc.Texture2DArray.FirstArraySlice = 0;
3957 dsvDesc.Texture2DArray.ArraySize = UINT(
qMax(0, depthTexD->arraySize()));
3961 HRESULT hr = rhiD->dev->CreateDepthStencilView(depthTexD->tex, &dsvDesc, &
dsv);
3963 qWarning(
"Failed to create dsv: %s",
3964 qPrintable(QSystemError::windowsComString(hr)));
3974 dsv = depthRbD->dsv;
3991 QRhiRenderTargetAttachmentTracker::updateResIdList<QD3D11Texture, QD3D11RenderBuffer>(
m_desc, &
d.
currentResIdList);
3993 rhiD->registerResource(
this);
3999 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QD3D11Texture, QD3D11RenderBuffer>(
m_desc,
d.
currentResIdList))
4032 rhiD->unregisterResource(
this);
4041 if (!rhiD->sanityCheckShaderResourceBindings(
this))
4044 rhiD->updateLayoutDesc(
this);
4064 rhiD->registerResource(
this,
false);
4096 s.shader->Release();
4099 s.nativeResourceBindingMap.clear();
4133 rhiD->unregisterResource(
this);
4140 return D3D11_CULL_NONE;
4142 return D3D11_CULL_FRONT;
4144 return D3D11_CULL_BACK;
4147 return D3D11_CULL_NONE;
4155 return D3D11_FILL_SOLID;
4157 return D3D11_FILL_WIREFRAME;
4160 return D3D11_FILL_SOLID;
4168 return D3D11_COMPARISON_NEVER;
4170 return D3D11_COMPARISON_LESS;
4172 return D3D11_COMPARISON_EQUAL;
4174 return D3D11_COMPARISON_LESS_EQUAL;
4176 return D3D11_COMPARISON_GREATER;
4178 return D3D11_COMPARISON_NOT_EQUAL;
4180 return D3D11_COMPARISON_GREATER_EQUAL;
4182 return D3D11_COMPARISON_ALWAYS;
4185 return D3D11_COMPARISON_ALWAYS;
4193 return D3D11_STENCIL_OP_ZERO;
4195 return D3D11_STENCIL_OP_KEEP;
4197 return D3D11_STENCIL_OP_REPLACE;
4199 return D3D11_STENCIL_OP_INCR_SAT;
4201 return D3D11_STENCIL_OP_DECR_SAT;
4203 return D3D11_STENCIL_OP_INVERT;
4205 return D3D11_STENCIL_OP_INCR;
4207 return D3D11_STENCIL_OP_DECR;
4210 return D3D11_STENCIL_OP_KEEP;
4218 return DXGI_FORMAT_R32G32B32A32_FLOAT;
4220 return DXGI_FORMAT_R32G32B32_FLOAT;
4222 return DXGI_FORMAT_R32G32_FLOAT;
4224 return DXGI_FORMAT_R32_FLOAT;
4226 return DXGI_FORMAT_R8G8B8A8_UNORM;
4228 return DXGI_FORMAT_R8G8_UNORM;
4230 return DXGI_FORMAT_R8_UNORM;
4232 return DXGI_FORMAT_R32G32B32A32_UINT;
4234 return DXGI_FORMAT_R32G32B32_UINT;
4236 return DXGI_FORMAT_R32G32_UINT;
4238 return DXGI_FORMAT_R32_UINT;
4240 return DXGI_FORMAT_R32G32B32A32_SINT;
4242 return DXGI_FORMAT_R32G32B32_SINT;
4244 return DXGI_FORMAT_R32G32_SINT;
4246 return DXGI_FORMAT_R32_SINT;
4250 return DXGI_FORMAT_R16G16B16A16_FLOAT;
4252 return DXGI_FORMAT_R16G16_FLOAT;
4254 return DXGI_FORMAT_R16_FLOAT;
4258 return DXGI_FORMAT_R16G16B16A16_UINT;
4260 return DXGI_FORMAT_R16G16_UINT;
4262 return DXGI_FORMAT_R16_UINT;
4266 return DXGI_FORMAT_R16G16B16A16_SINT;
4268 return DXGI_FORMAT_R16G16_SINT;
4270 return DXGI_FORMAT_R16_SINT;
4273 return DXGI_FORMAT_R32G32B32A32_FLOAT;
4281 return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
4283 return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
4285 return D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
4287 return D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP;
4289 return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
4291 Q_ASSERT(patchControlPointCount >= 1 && patchControlPointCount <= 32);
4292 return D3D11_PRIMITIVE_TOPOLOGY(D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + (patchControlPointCount - 1));
4295 return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
4303 f |= D3D11_COLOR_WRITE_ENABLE_RED;
4305 f |= D3D11_COLOR_WRITE_ENABLE_GREEN;
4307 f |= D3D11_COLOR_WRITE_ENABLE_BLUE;
4309 f |= D3D11_COLOR_WRITE_ENABLE_ALPHA;
4323 return D3D11_BLEND_ZERO;
4325 return D3D11_BLEND_ONE;
4327 return rgb ? D3D11_BLEND_SRC_COLOR : D3D11_BLEND_SRC_ALPHA;
4329 return rgb ? D3D11_BLEND_INV_SRC_COLOR : D3D11_BLEND_INV_SRC_ALPHA;
4331 return rgb ? D3D11_BLEND_DEST_COLOR : D3D11_BLEND_DEST_ALPHA;
4333 return rgb ? D3D11_BLEND_INV_DEST_COLOR : D3D11_BLEND_INV_DEST_ALPHA;
4335 return D3D11_BLEND_SRC_ALPHA;
4337 return D3D11_BLEND_INV_SRC_ALPHA;
4339 return D3D11_BLEND_DEST_ALPHA;
4341 return D3D11_BLEND_INV_DEST_ALPHA;
4344 return D3D11_BLEND_BLEND_FACTOR;
4347 return D3D11_BLEND_INV_BLEND_FACTOR;
4349 return D3D11_BLEND_SRC_ALPHA_SAT;
4351 return rgb ? D3D11_BLEND_SRC1_COLOR : D3D11_BLEND_SRC1_ALPHA;
4353 return rgb ? D3D11_BLEND_INV_SRC1_COLOR : D3D11_BLEND_INV_SRC1_ALPHA;
4355 return D3D11_BLEND_SRC1_ALPHA;
4357 return D3D11_BLEND_INV_SRC1_ALPHA;
4360 return D3D11_BLEND_ZERO;
4368 return D3D11_BLEND_OP_ADD;
4370 return D3D11_BLEND_OP_SUBTRACT;
4372 return D3D11_BLEND_OP_REV_SUBTRACT;
4374 return D3D11_BLEND_OP_MIN;
4376 return D3D11_BLEND_OP_MAX;
4379 return D3D11_BLEND_OP_ADD;
4387 keyBuilder.addData(
source);
4388 return keyBuilder.result().toHex();
4396 if (!dxbc.shader().isEmpty()) {
4398 *usedShaderKey =
key;
4399 return dxbc.shader();
4404 if (hlslSource.shader().isEmpty()) {
4405 qWarning() <<
"No HLSL (shader model 5.0) code found in baked shader" <<
shader;
4410 *usedShaderKey =
key;
4413 switch (
shader.stage()) {
4441 cacheKey.entryPoint = hlslSource.entryPoint();
4445 return cacheIt.value();
4449 if (d3dCompile ==
nullptr) {
4450 qWarning(
"Unable to resolve function D3DCompile()");
4454 ID3DBlob *bytecode =
nullptr;
4455 ID3DBlob *errors =
nullptr;
4456 HRESULT hr = d3dCompile(hlslSource.shader().constData(), SIZE_T(hlslSource.shader().size()),
4457 nullptr,
nullptr,
nullptr,
4458 hlslSource.entryPoint().constData(),
target,
flags, 0, &bytecode, &errors);
4459 if (FAILED(hr) || !bytecode) {
4460 qWarning(
"HLSL shader compilation failed: 0x%x",
uint(hr));
4463 int(errors->GetBufferSize()));
4470 result.resize(
int(bytecode->GetBufferSize()));
4471 memcpy(
result.data(), bytecode->GetBufferPointer(),
size_t(
result.size()));
4472 bytecode->Release();
4486 rhiD->pipelineCreationStart();
4487 if (!rhiD->sanityCheckGraphicsPipeline(
this))
4490 D3D11_RASTERIZER_DESC rastDesc = {};
4496 rastDesc.DepthClipEnable =
true;
4498 rastDesc.MultisampleEnable = rhiD->effectiveSampleDesc(
m_sampleCount).Count > 1;
4501 qWarning(
"Failed to create rasterizer state: %s",
4502 qPrintable(QSystemError::windowsComString(hr)));
4506 D3D11_DEPTH_STENCIL_DESC dsDesc = {};
4508 dsDesc.DepthWriteMask =
m_depthWrite ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
4523 hr = rhiD->dev->CreateDepthStencilState(&dsDesc, &
dsState);
4525 qWarning(
"Failed to create depth-stencil state: %s",
4526 qPrintable(QSystemError::windowsComString(hr)));
4530 D3D11_BLEND_DESC blendDesc = {};
4534 D3D11_RENDER_TARGET_BLEND_DESC blend = {};
4535 blend.BlendEnable =
b.enable;
4543 blendDesc.RenderTarget[
i] = blend;
4546 D3D11_RENDER_TARGET_BLEND_DESC blend = {};
4547 blend.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4548 blendDesc.RenderTarget[0] = blend;
4550 hr = rhiD->dev->CreateBlendState(&blendDesc, &
blendState);
4552 qWarning(
"Failed to create blend state: %s",
4553 qPrintable(QSystemError::windowsComString(hr)));
4559 auto cacheIt = rhiD->m_shaderCache.constFind(shaderStage);
4560 if (cacheIt != rhiD->m_shaderCache.constEnd()) {
4561 switch (shaderStage.type()) {
4563 vs.shader =
static_cast<ID3D11VertexShader *
>(cacheIt->s);
4564 vs.shader->AddRef();
4565 vsByteCode = cacheIt->bytecode;
4566 vs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4569 hs.shader =
static_cast<ID3D11HullShader *
>(cacheIt->s);
4570 hs.shader->AddRef();
4571 hs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4574 ds.shader =
static_cast<ID3D11DomainShader *
>(cacheIt->s);
4575 ds.shader->AddRef();
4576 ds.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4579 gs.shader =
static_cast<ID3D11GeometryShader *
>(cacheIt->s);
4580 gs.shader->AddRef();
4581 gs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4584 fs.shader =
static_cast<ID3D11PixelShader *
>(cacheIt->s);
4585 fs.shader->AddRef();
4586 fs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4594 UINT compileFlags = 0;
4596 compileFlags |= D3DCOMPILE_DEBUG;
4598 const QByteArray bytecode = rhiD->compileHlslShaderSource(shaderStage.shader(), shaderStage.shaderVariant(), compileFlags,
4599 &
error, &shaderKey);
4607 rhiD->clearShaderCache();
4610 switch (shaderStage.type()) {
4612 hr = rhiD->dev->CreateVertexShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
vs.shader);
4614 qWarning(
"Failed to create vertex shader: %s",
4615 qPrintable(QSystemError::windowsComString(hr)));
4618 vsByteCode = bytecode;
4619 vs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4620 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
vs.shader, bytecode,
vs.nativeResourceBindingMap));
4621 vs.shader->AddRef();
4624 hr = rhiD->dev->CreateHullShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
hs.shader);
4626 qWarning(
"Failed to create hull shader: %s",
4627 qPrintable(QSystemError::windowsComString(hr)));
4630 hs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4631 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
hs.shader, bytecode,
hs.nativeResourceBindingMap));
4632 hs.shader->AddRef();
4635 hr = rhiD->dev->CreateDomainShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
ds.shader);
4637 qWarning(
"Failed to create domain shader: %s",
4638 qPrintable(QSystemError::windowsComString(hr)));
4641 ds.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4642 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
ds.shader, bytecode,
ds.nativeResourceBindingMap));
4643 ds.shader->AddRef();
4646 hr = rhiD->dev->CreateGeometryShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
gs.shader);
4648 qWarning(
"Failed to create geometry shader: %s",
4649 qPrintable(QSystemError::windowsComString(hr)));
4652 gs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4653 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
gs.shader, bytecode,
gs.nativeResourceBindingMap));
4654 gs.shader->AddRef();
4657 hr = rhiD->dev->CreatePixelShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
fs.shader);
4659 qWarning(
"Failed to create pixel shader: %s",
4660 qPrintable(QSystemError::windowsComString(hr)));
4663 fs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4664 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
fs.shader, bytecode,
fs.nativeResourceBindingMap));
4665 fs.shader->AddRef();
4675 if (!vsByteCode.isEmpty()) {
4677 QVarLengthArray<D3D11_INPUT_ELEMENT_DESC, 4> inputDescs;
4681 D3D11_INPUT_ELEMENT_DESC desc = {};
4686 const int matrixSlice =
it->matrixSlice();
4687 if (matrixSlice < 0) {
4688 desc.SemanticName =
"TEXCOORD";
4689 desc.SemanticIndex = UINT(
it->location());
4694 matrixSliceSemantics.append(
sem);
4695 desc.SemanticName = matrixSliceSemantics.last().constData();
4696 desc.SemanticIndex = UINT(matrixSlice);
4699 desc.InputSlot = UINT(
it->binding());
4700 desc.AlignedByteOffset =
it->offset();
4703 desc.InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
4704 desc.InstanceDataStepRate = inputBinding->instanceStepRate();
4706 desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
4708 inputDescs.append(desc);
4710 if (!inputDescs.isEmpty()) {
4711 hr = rhiD->dev->CreateInputLayout(inputDescs.constData(), UINT(inputDescs.count()),
4712 vsByteCode, SIZE_T(vsByteCode.size()), &
inputLayout);
4714 qWarning(
"Failed to create input layout: %s",
4715 qPrintable(QSystemError::windowsComString(hr)));
4721 rhiD->pipelineCreationEnd();
4723 rhiD->registerResource(
this);
4742 cs.shader->Release();
4743 cs.shader =
nullptr;
4744 cs.nativeResourceBindingMap.clear();
4748 rhiD->unregisterResource(
this);
4757 rhiD->pipelineCreationStart();
4759 auto cacheIt = rhiD->m_shaderCache.constFind(
m_shaderStage);
4760 if (cacheIt != rhiD->m_shaderCache.constEnd()) {
4761 cs.shader =
static_cast<ID3D11ComputeShader *
>(cacheIt->s);
4762 cs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4766 UINT compileFlags = 0;
4768 compileFlags |= D3DCOMPILE_DEBUG;
4771 &
error, &shaderKey);
4777 HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
cs.shader);
4779 qWarning(
"Failed to create compute shader: %s",
4780 qPrintable(QSystemError::windowsComString(hr)));
4787 rhiD->clearShaderCache();
4792 cs.shader->AddRef();
4794 rhiD->pipelineCreationEnd();
4796 rhiD->registerResource(
this);
4821 D3D11_QUERY_DESC queryDesc = {};
4824 queryDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4827 qWarning(
"Failed to create timestamp disjoint query: %s",
4828 qPrintable(QSystemError::windowsComString(hr)));
4832 queryDesc.Query = D3D11_QUERY_TIMESTAMP;
4833 for (
int j = 0;
j < 2; ++
j) {
4834 const int idx = 2 *
i +
j;
4836 HRESULT hr = rhiD->dev->CreateQuery(&queryDesc, &
query[idx]);
4838 qWarning(
"Failed to create timestamp query: %s",
4839 qPrintable(QSystemError::windowsComString(hr)));
4856 for (
int j = 0;
j < 2; ++
j) {
4859 query[idx]->Release();
4860 query[idx] =
nullptr;
4873 ID3D11Query *tsStart =
query[pairIndex * 2];
4874 ID3D11Query *tsEnd =
query[pairIndex * 2 + 1];
4876 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT dj;
4879 ok &= context->GetData(tsDisjoint, &dj,
sizeof(dj), D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_OK;
4880 ok &= context->GetData(tsEnd, ×tamps[1],
sizeof(
quint64), D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_OK;
4881 ok &= context->GetData(tsStart, ×tamps[0],
sizeof(
quint64), D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_OK;
4884 if (!dj.Disjoint && dj.Frequency) {
4885 const float elapsedMs = (timestamps[1] - timestamps[0]) /
float(dj.Frequency) * 1000.0f;
4886 *elapsedSec = elapsedMs / 1000.0;
4889 active[pairIndex] =
false;
4961 rhiD->unregisterResource(
this);
4964 rhiD->context->Flush();
4995 qWarning(
"Attempted to call isFormatSupported() without a window set");
5000 DXGI_OUTPUT_DESC1 desc1;
5002 if (desc1.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020)
5015 DXGI_OUTPUT_DESC1 hdrOutputDesc;
5018 info.limits.luminanceInNits.minLuminance = hdrOutputDesc.MinLuminance;
5019 info.limits.luminanceInNits.maxLuminance = hdrOutputDesc.MaxLuminance;
5031 rhiD->registerResource(rpD,
false);
5036 ID3D11Texture2D **tex, ID3D11RenderTargetView **rtv)
const
5038 D3D11_TEXTURE2D_DESC desc = {};
5039 desc.Width = UINT(
size.width());
5040 desc.Height = UINT(
size.height());
5045 desc.Usage = D3D11_USAGE_DEFAULT;
5046 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5049 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, tex);
5051 qWarning(
"Failed to create color buffer texture: %s",
5052 qPrintable(QSystemError::windowsComString(hr)));
5056 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
5058 rtvDesc.ViewDimension =
sampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D;
5059 hr = rhiD->dev->CreateRenderTargetView(*tex, &rtvDesc, rtv);
5061 qWarning(
"Failed to create color buffer rtv: %s",
5062 qPrintable(QSystemError::windowsComString(hr)));
5076 qCDebug(QRHI_LOG_INFO,
"Creating Direct Composition device (needed for semi-transparent windows)");
5104 HWND hwnd =
reinterpret_cast<HWND
>(
window->winId());
5110 if (!rhiD->useLegacySwapchainModel && rhiD->ensureDirectCompositionDevice()) {
5112 hr = rhiD->dcompDevice->CreateTargetForHwnd(hwnd,
false, &
dcompTarget);
5114 qWarning(
"Failed to create Direct Compsition target for the window: %s",
5115 qPrintable(QSystemError::windowsComString(hr)));
5119 hr = rhiD->dcompDevice->CreateVisual(&
dcompVisual);
5121 qWarning(
"Failed to create DirectComposition visual: %s",
5122 qPrintable(QSystemError::windowsComString(hr)));
5128 qWarning(
"Swapchain says surface has alpha but the window has no alphaBufferSize set. "
5129 "This may lead to problems.");
5147 DXGI_COLOR_SPACE_TYPE hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
5148 DXGI_OUTPUT_DESC1 hdrOutputDesc;
5151 if (hdrOutputDesc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) {
5155 hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709;
5160 hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020;
5170 qWarning(
"The output associated with the window is not HDR capable "
5171 "(or Use HDR is Off in the Display Settings), ignoring HDR format request");
5181 DXGI_SWAP_CHAIN_DESC1 desc = {};
5185 desc.SampleDesc.Count = 1;
5186 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
5189 desc.Scaling = rhiD->useLegacySwapchainModel ? DXGI_SCALING_STRETCH : DXGI_SCALING_NONE;
5190 desc.SwapEffect = rhiD->useLegacySwapchainModel ? DXGI_SWAP_EFFECT_DISCARD : DXGI_SWAP_EFFECT_FLIP_DISCARD;
5191 desc.Stereo = stereo;
5197 desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
5202 desc.Scaling = DXGI_SCALING_STRETCH;
5205 IDXGIFactory2 *fac =
static_cast<IDXGIFactory2 *
>(rhiD->dxgiFactory);
5206 IDXGISwapChain1 *sc1;
5209 hr = fac->CreateSwapChainForComposition(rhiD->dev, &desc,
nullptr, &sc1);
5211 hr = fac->CreateSwapChainForHwnd(rhiD->dev, hwnd, &desc,
nullptr,
nullptr, &sc1);
5220 hr = fac->CreateSwapChainForComposition(rhiD->dev, &desc,
nullptr, &sc1);
5222 hr = fac->CreateSwapChainForHwnd(rhiD->dev, hwnd, &desc,
nullptr,
nullptr, &sc1);
5225 if (SUCCEEDED(hr)) {
5228 IDXGISwapChain3 *sc3 =
nullptr;
5229 if (SUCCEEDED(sc1->QueryInterface(__uuidof(IDXGISwapChain3),
reinterpret_cast<void **
>(&sc3)))) {
5230 hr = sc3->SetColorSpace1(hdrColorSpace);
5232 qWarning(
"Failed to set color space on swapchain: %s",
5233 qPrintable(QSystemError::windowsComString(hr)));
5236 qWarning(
"IDXGISwapChain3 not available, HDR swapchain will not work as expected");
5241 if (SUCCEEDED(hr)) {
5244 qWarning(
"Failed to associate Direct Composition visual with the target: %s",
5245 qPrintable(QSystemError::windowsComString(hr)));
5248 qWarning(
"Failed to set content for Direct Composition visual: %s",
5249 qPrintable(QSystemError::windowsComString(hr)));
5253 rhiD->dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_WINDOW_CHANGES);
5257 qWarning(
"Failed to create D3D11 swapchain: %s"
5258 " (Width=%u Height=%u Format=%u SampleCount=%u BufferCount=%u Scaling=%u SwapEffect=%u Stereo=%u)",
5259 qPrintable(QSystemError::windowsComString(hr)),
5260 desc.Width, desc.Height, UINT(desc.Format), desc.SampleDesc.Count,
5261 desc.BufferCount, UINT(desc.Scaling), UINT(desc.SwapEffect), UINT(desc.Stereo));
5269 if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) {
5270 qWarning(
"Device loss detected in ResizeBuffers()");
5271 rhiD->deviceLost =
true;
5273 }
else if (FAILED(hr)) {
5274 qWarning(
"Failed to resize D3D11 swapchain: %s",
5275 qPrintable(QSystemError::windowsComString(hr)));
5296 qWarning(
"Failed to query swapchain backbuffer: %s",
5297 qPrintable(QSystemError::windowsComString(hr)));
5300 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
5302 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
5305 qWarning(
"Failed to create rtv for swapchain backbuffer: %s",
5306 qPrintable(QSystemError::windowsComString(hr)));
5312 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
5313 rtvDesc.Texture2DArray.FirstArraySlice = 1;
5314 rtvDesc.Texture2DArray.ArraySize = 1;
5317 qWarning(
"Failed to create rtv for swapchain backbuffer (right eye): %s",
5318 qPrintable(QSystemError::windowsComString(hr)));
5332 qWarning(
"Depth-stencil buffer's sampleCount (%d) does not match color buffers' sample count (%d). Expect problems.",
5339 qWarning(
"Failed to rebuild swapchain's associated depth-stencil buffer for size %dx%d",
5342 qWarning(
"Depth-stencil buffer's size (%dx%d) does not match the surface size (%dx%d). Expect problems.",
5356 rtD->d.dpr = float(
window->devicePixelRatio());
5358 rtD->d.colorAttCount = 1;
5365 rtD->d.dpr = float(
window->devicePixelRatio());
5367 rtD->d.colorAttCount = 1;
5370 rtD->d.dsv =
ds ?
ds->
dsv :
nullptr;
5378 if (needsRegistration)
5379 rhiD->registerResource(
this);
IOBluetoothDevice * device
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
The QColor class provides colors based on RGB, HSV or CMYK values.
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
iterator insert(const Key &key, const T &value)
const_iterator cend() const
const_iterator constFind(const Key &key) const
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
\inmodule QtCore\reentrant
constexpr bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
const char * constData() const
Type
Specifies storage type of buffer resource.
QRhiRenderBuffer * renderBuffer() const
QRhiTexture * texture() const
QRhiTexture * resolveTexture() const
QPair< int, quint32 > DynamicOffset
Synonym for QPair<int, quint32>.
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, quint32>.
IndexFormat
Specifies the index data type.
QRhiShaderStage m_shaderStage
@ CompileShadersWithDebugInfo
\variable QRhiD3D11InitParams::enableDebugLayer
struct QRhiD3D11::@261 contextState
void setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) override
void debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) override
QRhiD3D11NativeHandles nativeHandlesStruct
bool isYUpInNDC() const override
QRhiSwapChain * createSwapChain() override
void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates)
bool isFeatureSupported(QRhi::Feature feature) const override
QRhi::FrameOpResult endOffscreenFrame(QRhi::EndFrameFlags flags) override
bool isDeviceLost() const override
void executeBufferHostWrites(QD3D11Buffer *bufD)
void resetShaderResources()
void updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD, const QShader::NativeResourceBindingMap *nativeResourceBindingMaps[])
QRhiStats statistics() override
QHash< BytecodeCacheKey, QByteArray > m_bytecodeCache
QRhiComputePipeline * createComputePipeline() override
void debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) override
QRhi::FrameOpResult finish() override
void setVertexInput(QRhiCommandBuffer *cb, int startBinding, int bindingCount, const QRhiCommandBuffer::VertexInput *bindings, QRhiBuffer *indexBuf, quint32 indexOffset, QRhiCommandBuffer::IndexFormat indexFormat) override
IDXGIAdapter1 * activeAdapter
QRhiGraphicsPipeline * createGraphicsPipeline() override
QRhiShaderResourceBindings * createShaderResourceBindings() override
QVarLengthArray< BufferReadback, 2 > activeBufferReadbacks
QRhi::FrameOpResult beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) override
ID3D11DeviceContext1 * context
QList< int > supportedSampleCounts() const override
QRhiTextureRenderTarget * createTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags) override
QByteArray compileHlslShaderSource(const QShader &shader, QShader::Variant shaderVariant, uint flags, QString *error, QShaderKey *usedShaderKey)
void setBlendConstants(QRhiCommandBuffer *cb, const QColor &c) override
bool isClipDepthZeroToOne() const override
IDCompositionDevice * dcompDevice
QRhiDriverInfo driverInfoStruct
QHash< QRhiShaderStage, Shader > m_shaderCache
bool ensureDirectCompositionDevice()
void beginComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
void draw(QRhiCommandBuffer *cb, quint32 vertexCount, quint32 instanceCount, quint32 firstVertex, quint32 firstInstance) override
void enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc)
void reportLiveObjects(ID3D11Device *device)
void resourceUpdate(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
QMatrix4x4 clipSpaceCorrMatrix() const override
struct QRhiD3D11::OffscreenFrame ofr
bool isYUpInFramebuffer() const override
int resourceLimit(QRhi::ResourceLimit limit) const override
void beginExternal(QRhiCommandBuffer *cb) override
QRhiTexture * createTexture(QRhiTexture::Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, QRhiTexture::Flags flags) override
void setPipelineCacheData(const QByteArray &data) override
void bindShaderResources(QD3D11ShaderResourceBindings *srbD, const uint *dynOfsPairs, int dynOfsPairCount, bool offsetOnlyChange)
void executeCommandBuffer(QD3D11CommandBuffer *cbD)
void debugMarkEnd(QRhiCommandBuffer *cb) override
void releaseCachedResources() override
double lastCompletedGpuTime(QRhiCommandBuffer *cb) override
ID3DUserDefinedAnnotation * annotations
bool importedDeviceAndContext
QRhi::FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi::BeginFrameFlags flags) override
QRhiBuffer * createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size) override
bool supportsAllowTearing
void dispatch(QRhiCommandBuffer *cb, int x, int y, int z) override
void endExternal(QRhiCommandBuffer *cb) override
void setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) override
QVarLengthArray< TextureReadback, 2 > activeTextureReadbacks
void setComputePipeline(QRhiCommandBuffer *cb, QRhiComputePipeline *ps) override
QRhi::FrameOpResult endFrame(QRhiSwapChain *swapChain, QRhi::EndFrameFlags flags) override
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override
void setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBindings *srb, int dynamicOffsetCount, const QRhiCommandBuffer::DynamicOffset *dynamicOffsets) override
D3D_FEATURE_LEVEL featureLevel
bool useLegacySwapchainModel
void endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
bool makeThreadLocalNativeContextCurrent() override
bool create(QRhi::Flags flags) override
void finishActiveReadbacks()
IDXGIFactory1 * dxgiFactory
QByteArray pipelineCacheData() override
const QRhiNativeHandles * nativeHandles() override
QRhiDriverInfo driverInfo() const override
void endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates) override
int ubufAlignment() const override
void beginPass(QRhiCommandBuffer *cb, QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates, QRhiCommandBuffer::BeginPassFlags flags) override
void drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, quint32 instanceCount, quint32 firstIndex, qint32 vertexOffset, quint32 firstInstance) override
QRhiSampler * createSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode u, QRhiSampler::AddressMode v, QRhiSampler::AddressMode w) override
QRhiRenderBuffer * createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint) override
void setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline *ps) override
QRhiD3D11(QRhiD3D11InitParams *params, QRhiD3D11NativeHandles *importDevice=nullptr)
DXGI_SAMPLE_DESC effectiveSampleDesc(int sampleCount) const
void setStencilRef(QRhiCommandBuffer *cb, quint32 refValue) override
quint32 m_stencilReadMask
@ CompileShadersWithDebugInfo
BlendOp
Specifies the blend operation.
PolygonMode
Specifies the polygon rasterization mode.
BlendFactor
Specifies the blend factor.
StencilOpState m_stencilFront
quint32 m_stencilWriteMask
CompareOp
Specifies the depth or stencil comparison function.
CullMode
Specifies the culling mode.
QVarLengthArray< QRhiShaderStage, 4 > m_shaderStages
QRhiVertexInputLayout m_vertexInputLayout
QVarLengthArray< TargetBlend, 8 > m_targetBlends
PolygonMode m_polygonMode
float m_slopeScaledDepthBias
Topology
Specifies the primitive topology.
StencilOpState m_stencilBack
StencilOp
Specifies the stencil operation.
int m_patchControlPointCount
int effectiveSampleCount(int sampleCount) const
bool isCompressedFormat(QRhiTexture::Format format) const
static const QRhiShaderResourceBinding::Data * shaderResourceBindingData(const QRhiShaderResourceBinding &binding)
quint32 pipelineCacheRhiId() const
void compressedFormatInfo(QRhiTexture::Format format, const QSize &size, quint32 *bpl, quint32 *byteSize, QSize *blockDim) const
static const int MAX_SHADER_CACHE_ENTRIES
static bool sortedBindingLessThan(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b)
qint64 totalPipelineCreationTime() const
void textureFormatInfo(QRhiTexture::Format format, const QSize &size, quint32 *bpl, quint32 *byteSize, quint32 *bytesPerPixel) const
QRhiTexture * texture() const
void setPixelSize(const QSize &sz)
Sets the size (in pixels) to sz.
QRhiTexture::Format m_backingFormatHint
Type
Specifies the type of the renderbuffer.
virtual bool create()=0
Creates the corresponding native graphics resources.
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc)
Sets the QRhiRenderPassDescriptor desc for use with this render target.
virtual QSize pixelSize() const =0
QRhiRenderPassDescriptor * m_renderPassDesc
static QRhiResourceUpdateBatchPrivate * get(QRhiResourceUpdateBatch *b)
virtual Type resourceType() const =0
QRhiImplementation * m_rhi
Filter
Specifies the minification, magnification, or mipmap filtering.
AddressMode
Specifies the addressing mode.
CompareOp
Specifies the texture comparison function.
std::array< int, 4 > scissor() const
@ TessellationEvaluationStage
@ TessellationControlStage
QVarLengthArray< QRhiShaderResourceBinding, BINDING_PREALLOC > m_bindings
QShader::Variant shaderVariant() const
@ SurfaceHasNonPreMulAlpha
QRhiRenderPassDescriptor * m_renderPassDesc
Format
Describes the swapchain format.
StereoTargetBuffer
Selects the backbuffer to use with a stereoscopic swapchain.
virtual QRhiSwapChainHdrInfo hdrInfo()
\variable QRhiSwapChainHdrInfo::limitsType
QRhiRenderBuffer * m_depthStencil
QPoint destinationTopLeft() const
QPoint sourceTopLeft() const
int destinationLevel() const
int destinationLayer() const
const QRhiColorAttachment * cbeginColorAttachments() const
QRhiTexture * depthTexture() const
const QRhiColorAttachment * cendColorAttachments() const
QRhiRenderBuffer * depthStencilBuffer() const
qsizetype colorAttachmentCount() const
QRhiTextureRenderTargetDescription m_desc
@ PreserveDepthStencilContents
quint32 dataStride() const
QPoint sourceTopLeft() const
QPoint destinationTopLeft() const
Format
Specifies the texture format.
static constexpr int MAX_MIP_LEVELS
ResourceLimit
Describes the resource limit to query.
@ MaxThreadsPerThreadGroup
@ MaxThreadGroupsPerDimension
Feature
Flag values to indicate what features are supported by the backend currently in use.
@ NonDynamicUniformBuffers
@ RenderToNonBaseMipLevel
@ MultisampleRenderBuffer
@ PipelineCacheDataLoadSave
@ ReadBackNonUniformBuffer
@ RenderToOneDimensionalTexture
@ OneDimensionalTextureMipmaps
@ ReadBackNonBaseMipLevel
@ ThreeDimensionalTextureMipmaps
@ NonFourAlignedEffectiveIndexBufferOffset
@ ThreeDimensionalTextures
@ ReadBackAnyTextureFormat
FrameOpResult
Describes the result of operations that can have a soft failure.
@ EnablePipelineCacheDataSave
@ SuppressSmokeTestWarnings
QByteArray shader() const
NativeResourceBindingMap nativeResourceBindingMap(const QShaderKey &key) const
Variant
Describes what kind of shader code an entry contains.
@ TessellationEvaluationStage
@ TessellationControlStage
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromUtf16(const char16_t *, qsizetype size=-1)
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_iterator cbegin() const noexcept
const_iterator cend() const noexcept
iterator begin() noexcept
QSurfaceFormat format() const override
Returns the actual format of this window.
QSize size() const override
Returns the size of the window excluding any window frame.
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
float sdrWhiteLevelInNits(const DXGI_OUTPUT_DESC1 &outputDesc)
pD3DCompile resolveD3DCompile()
bool outputDesc1ForWindow(QWindow *w, IDXGIAdapter1 *adapter, DXGI_OUTPUT_DESC1 *result)
IDCompositionDevice * createDirectCompositionDevice()
void fillDriverInfo(QRhiDriverInfo *info, const DXGI_ADAPTER_DESC1 &desc)
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
Q_CORE_EXPORT char * qstrncpy(char *dst, const char *src, size_t len)
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
static QString header(const QString &name)
static const qint64 headerSize
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
static QByteArray cacheKey(Args &&...args)
#define qCDebug(category,...)
QT_BEGIN_NAMESPACE constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLuint const GLuint * buffers
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint const GLuint GLuint const GLuint * textures
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLsizei const GLint * box
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLuint GLsizei const GLuint const GLintptr * offsets
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum colorFormat
GLsizeiptr const void GLenum usage
static const int RBM_VERTEX
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 D3D11_TEXTURE_ADDRESS_MODE toD3DAddressMode(QRhiSampler::AddressMode m)
#define SETUAVBATCH(stagePrefixL, stagePrefixU)
static QByteArray sourceHash(const QByteArray &source)
#define SETSAMPLERBATCH(stagePrefixL, stagePrefixU)
static uint toD3DBufferUsage(QRhiBuffer::UsageFlags usage)
#define SETUBUFBATCH(stagePrefixL, stagePrefixU)
static const int RBM_DOMAIN
static const DXGI_FORMAT DEFAULT_SRGB_FORMAT
Int aligned(Int v, Int byteAlign)
static DXGI_FORMAT toD3DDepthTextureDSVFormat(QRhiTexture::Format format)
static const DXGI_FORMAT DEFAULT_FORMAT
static D3D11_BLEND toD3DBlendFactor(QRhiGraphicsPipeline::BlendFactor f, bool rgb)
static D3D11_BLEND_OP toD3DBlendOp(QRhiGraphicsPipeline::BlendOp op)
static D3D11_FILTER toD3DFilter(QRhiSampler::Filter minFilter, QRhiSampler::Filter magFilter, QRhiSampler::Filter mipFilter)
static QD3D11RenderTargetData * rtData(QRhiRenderTarget *rt)
static UINT8 toD3DColorWriteMask(QRhiGraphicsPipeline::ColorMask c)
static const int RBM_COMPUTE
static D3D11_STENCIL_OP toD3DStencilOp(QRhiGraphicsPipeline::StencilOp op)
void releasePipelineShader(T &s)
static D3D11_COMPARISON_FUNC toD3DTextureComparisonFunc(QRhiSampler::CompareOp op)
static DXGI_FORMAT toD3DAttributeFormat(QRhiVertexInputAttribute::Format format)
static D3D11_PRIMITIVE_TOPOLOGY toD3DTopology(QRhiGraphicsPipeline::Topology t, int patchControlPointCount)
static const int RBM_HULL
static const int RBM_FRAGMENT
static IDXGIFactory1 * createDXGIFactory2()
static D3D11_FILL_MODE toD3DFillMode(QRhiGraphicsPipeline::PolygonMode mode)
static bool isDepthTextureFormat(QRhiTexture::Format format)
static D3D11_CULL_MODE toD3DCullMode(QRhiGraphicsPipeline::CullMode c)
#define SETSHADER(StageL, StageU)
static DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTexture::Flags flags)
static uint clampedResourceCount(uint startSlot, int countSlots, uint maxSlots, const char *resType)
static const int RBM_SUPPORTED_STAGES
#define D3D11_VS_INPUT_REGISTER_COUNT
#define DXGI_ADAPTER_FLAG_SOFTWARE
\variable QRhiD3D11NativeHandles::dev
static QRhiTexture::Format swapchainReadbackTextureFormat(DXGI_FORMAT format, QRhiTexture::Flags *flags)
static D3D11_COMPARISON_FUNC toD3DCompareOp(QRhiGraphicsPipeline::CompareOp op)
static DXGI_FORMAT toD3DDepthTextureSRVFormat(QRhiTexture::Format format)
static const int RBM_GEOMETRY
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define qPrintable(string)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
unsigned long long quint64
view viewport() -> scroll(dx, dy, deviceRect)
bool hasPendingDynamicUpdates
void endFullDynamicBufferUpdateForCurrentFrame() override
To be called when the entire contents of the buffer data has been updated in the memory block returne...
QD3D11Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
char * beginFullDynamicBufferUpdateForCurrentFrame() override
bool create() override
Creates the corresponding native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QHash< quint32, ID3D11UnorderedAccessView * > uavs
QRhiBuffer::NativeBuffer nativeBuffer() override
ID3D11UnorderedAccessView * unorderedAccessView(quint32 offset)
union QD3D11CommandBuffer::Command::Args args
QRhiRenderTarget * currentTarget
static const int MAX_DYNAMIC_OFFSET_COUNT
const uchar * retainBufferData(const QRhiBufferData &data)
ID3D11Buffer * currentVertexBuffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]
static const int MAX_VERTEX_BUFFER_BINDING_COUNT
QRhiShaderResourceBindings * currentGraphicsSrb
const uchar * retainImage(const QImage &image)
QD3D11CommandBuffer(QRhiImplementation *rhi)
const uchar * retainData(const QByteArray &data)
QRhiShaderResourceBindings * currentComputeSrb
QRhiBackendCommandList< Command > commands
uint currentPipelineGeneration
quint32 currentIndexOffset
uint currentSrbGeneration
QRhiComputePipeline * currentComputePipeline
ID3D11Buffer * currentIndexBuffer
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
DXGI_FORMAT currentIndexFormat
quint32 currentVertexOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]
QRhiGraphicsPipeline * currentGraphicsPipeline
QD3D11ComputePipeline(QRhiImplementation *rhi)
struct QD3D11ComputePipeline::@238 cs
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
struct QD3D11GraphicsPipeline::@236 gs
struct QD3D11GraphicsPipeline::@233 vs
struct QD3D11GraphicsPipeline::@237 fs
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QD3D11GraphicsPipeline(QRhiImplementation *rhi)
struct QD3D11GraphicsPipeline::@234 hs
ID3D11InputLayout * inputLayout
ID3D11BlendState * blendState
ID3D11RasterizerState * rastState
D3D11_PRIMITIVE_TOPOLOGY d3dTopology
~QD3D11GraphicsPipeline()
bool create() override
Creates the corresponding native graphics resources.
ID3D11DepthStencilState * dsState
struct QD3D11GraphicsPipeline::@235 ds
QD3D11RenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize, int sampleCount, QRhiRenderBuffer::Flags flags, QRhiTexture::Format backingFormatHint)
ID3D11RenderTargetView * rtv
ID3D11DepthStencilView * dsv
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
DXGI_SAMPLE_DESC sampleDesc
bool create() override
Creates the corresponding native graphics resources.
QRhiTexture::Format backingFormat() const override
QD3D11RenderPassDescriptor(QRhiImplementation *rhi)
~QD3D11RenderPassDescriptor()
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool isCompatible(const QRhiRenderPassDescriptor *other) const override
QVector< quint32 > serializedFormat() const override
static const int MAX_COLOR_ATTACHMENTS
ID3D11RenderTargetView * rtv[MAX_COLOR_ATTACHMENTS]
ID3D11DepthStencilView * dsv
QD3D11RenderPassDescriptor * rp
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QD3D11Sampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode, AddressMode u, AddressMode v, AddressMode w)
ID3D11SamplerState * samplerState
QRhiBatchedBindings< ID3D11SamplerState * > samplers
QRhiBatchedBindings< ID3D11ShaderResourceView * > shaderresources
QRhiBatchedBindings< ID3D11UnorderedAccessView * > uavs
QVarLengthArray< BoundResourceData, 8 > boundResourceData
QVarLengthArray< QRhiShaderResourceBinding, 8 > sortedBindings
~QD3D11ShaderResourceBindings()
void updateResources(UpdateFlags flags) override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QD3D11ShaderResourceBindings(QRhiImplementation *rhi)
int sampleCount() const override
~QD3D11SwapChainRenderTarget()
QD3D11SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
float devicePixelRatio() const override
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
QSize pixelSize() const override
bool prepare(QRhiD3D11 *rhiD)
bool tryQueryTimestamps(int idx, ID3D11DeviceContext *context, double *elapsedSec)
bool active[TIMESTAMP_PAIRS]
ID3D11Query * disjointQuery[TIMESTAMP_PAIRS]
static const int TIMESTAMP_PAIRS
QRhiSwapChainHdrInfo hdrInfo() override
\variable QRhiSwapChainHdrInfo::limitsType
QD3D11SwapChainTimestamps timestamps
ID3D11RenderTargetView * backBufferRtv
QRhiRenderTarget * currentFrameRenderTarget() override
QD3D11SwapChainRenderTarget rtRight
ID3D11RenderTargetView * backBufferRtvRight
ID3D11Texture2D * msaaTex[BUFFER_COUNT]
QD3D11SwapChain(QRhiImplementation *rhi)
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
IDCompositionTarget * dcompTarget
ID3D11RenderTargetView * msaaRtv[BUFFER_COUNT]
bool createOrResize() override
Creates the swapchain if not already done and resizes the swapchain buffers to match the current size...
QSize surfacePixelSize() override
bool newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI_SAMPLE_DESC sampleDesc, ID3D11Texture2D **tex, ID3D11RenderTargetView **rtv) const
static const int BUFFER_COUNT
QD3D11SwapChainRenderTarget rt
bool isFormatSupported(Format f) override
DXGI_SAMPLE_DESC sampleDesc
IDCompositionVisual * dcompVisual
QRhiCommandBuffer * currentFrameCommandBuffer() override
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
IDXGISwapChain * swapChain
DXGI_FORMAT srgbAdjustedColorFormat
ID3D11Texture2D * backBufferTex
QSize pixelSize() const override
QD3D11TextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc, Flags flags)
ID3D11DepthStencilView * dsv
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
float devicePixelRatio() const override
QRhiRenderPassDescriptor * newCompatibleRenderPassDescriptor() override
int sampleCount() const override
bool ownsRtv[QD3D11RenderTargetData::MAX_COLOR_ATTACHMENTS]
ID3D11RenderTargetView * rtv[QD3D11RenderTargetData::MAX_COLOR_ATTACHMENTS]
bool create() override
Creates the corresponding native graphics resources.
~QD3D11TextureRenderTarget()
bool create() override
Creates the corresponding native graphics resources.
void destroy() override
Releases (or requests deferred releasing of) the underlying native graphics resources.
bool createFrom(NativeTexture src) override
Similar to create(), except that no new native textures are created.
NativeTexture nativeTexture() override
ID3D11UnorderedAccessView * perLevelViews[QRhi::MAX_MIP_LEVELS]
bool prepareCreate(QSize *adjustedSize=nullptr)
QD3D11Texture(QRhiImplementation *rhi, Format format, const QSize &pixelSize, int depth, int arraySize, int sampleCount, Flags flags)
ID3D11UnorderedAccessView * unorderedAccessViewForLevel(int level)
DXGI_SAMPLE_DESC sampleDesc
ID3D11ShaderResourceView * srv
ID3D11Resource * textureResource() const
void feed(int binding, T resource)
QRhiReadbackResult * result
QRhiReadbackDescription desc
\variable QRhiReadbackResult::completed
std::function< void()> completed
QRhiReadbackResult * result
QRhiTextureCopyDescription desc
QRhiReadbackDescription rb
QVarLengthArray< MipLevelUploadList, 6 > subresDesc
QRhiReadbackResult * result