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;
1560 return srgb ? DXGI_FORMAT_BC1_UNORM_SRGB : DXGI_FORMAT_BC1_UNORM;
1562 return srgb ? DXGI_FORMAT_BC2_UNORM_SRGB : DXGI_FORMAT_BC2_UNORM;
1564 return srgb ? DXGI_FORMAT_BC3_UNORM_SRGB : DXGI_FORMAT_BC3_UNORM;
1566 return DXGI_FORMAT_BC4_UNORM;
1568 return DXGI_FORMAT_BC5_UNORM;
1570 return DXGI_FORMAT_BC6H_UF16;
1572 return srgb ? DXGI_FORMAT_BC7_UNORM_SRGB : DXGI_FORMAT_BC7_UNORM;
1577 qWarning(
"QRhiD3D11 does not support ETC2 textures");
1578 return DXGI_FORMAT_R8G8B8A8_UNORM;
1594 qWarning(
"QRhiD3D11 does not support ASTC textures");
1595 return DXGI_FORMAT_R8G8B8A8_UNORM;
1599 return DXGI_FORMAT_R8G8B8A8_UNORM;
1606 case DXGI_FORMAT_R8G8B8A8_UNORM:
1608 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
1612 case DXGI_FORMAT_B8G8R8A8_UNORM:
1614 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
1618 case DXGI_FORMAT_R16G16B16A16_FLOAT:
1620 case DXGI_FORMAT_R32G32B32A32_FLOAT:
1622 case DXGI_FORMAT_R10G10B10A2_UNORM:
1652 ofr.cbWrapper.resetCommands();
1670 UINT subres = D3D11CalcSubresource(UINT(
level), is3D ? 0u : UINT(
layer), texD->mipLevelCount);
1672 box.front = is3D ? UINT(
layer) : 0u;
1674 box.back =
box.front + 1;
1677 cmd.
args.updateSubRes.dst = texD->textureResource();
1678 cmd.
args.updateSubRes.dstSubRes = subres;
1684 int bpl =
img.bytesPerLine();
1689 if (
img.depth() == 32) {
1690 const int offset =
sp.y() *
img.bytesPerLine() +
sp.x() * 4;
1694 bpl =
img.bytesPerLine();
1700 box.left = UINT(dp.x());
1701 box.top = UINT(dp.y());
1702 box.right = UINT(dp.x() +
size.width());
1703 box.bottom = UINT(dp.y() +
size.height());
1704 cmd.
args.updateSubRes.hasDstBox =
true;
1705 cmd.
args.updateSubRes.dstBox =
box;
1706 cmd.
args.updateSubRes.srcRowPitch = UINT(bpl);
1716 box.left = UINT(
aligned(dp.x(), blockDim.width()));
1717 box.top = UINT(
aligned(dp.y(), blockDim.height()));
1718 box.right = UINT(
aligned(dp.x() +
size.width(), blockDim.width()));
1719 box.bottom = UINT(
aligned(dp.y() +
size.height(), blockDim.height()));
1720 cmd.
args.updateSubRes.hasDstBox =
true;
1721 cmd.
args.updateSubRes.dstBox =
box;
1723 cmd.
args.updateSubRes.srcRowPitch = bpl;
1732 box.left = UINT(dp.x());
1733 box.top = UINT(dp.y());
1734 box.right = UINT(dp.x() +
size.width());
1735 box.bottom = UINT(dp.y() +
size.height());
1736 cmd.
args.updateSubRes.hasDstBox =
true;
1737 cmd.
args.updateSubRes.dstBox =
box;
1739 cmd.
args.updateSubRes.srcRowPitch = bpl;
1751 for (
int opIdx = 0; opIdx < ud->activeBufferOpCount; ++opIdx) {
1757 bufD->hasPendingDynamicUpdates =
true;
1764 cmd.
args.updateSubRes.dst = bufD->buffer;
1765 cmd.
args.updateSubRes.dstSubRes = 0;
1767 cmd.
args.updateSubRes.srcRowPitch = 0;
1774 box.back =
box.bottom = 1;
1776 cmd.
args.updateSubRes.hasDstBox =
true;
1777 cmd.
args.updateSubRes.dstBox =
box;
1790 D3D11_BUFFER_DESC desc = {};
1791 desc.ByteWidth = readback.byteSize;
1792 desc.Usage = D3D11_USAGE_STAGING;
1793 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
1794 HRESULT hr =
dev->CreateBuffer(&desc,
nullptr, &readback.stagingBuf);
1796 qWarning(
"Failed to create buffer: %s",
1797 qPrintable(QSystemError::windowsComString(hr)));
1803 cmd.
args.copySubRes.dst = readback.stagingBuf;
1804 cmd.
args.copySubRes.dstSubRes = 0;
1805 cmd.
args.copySubRes.dstX = 0;
1806 cmd.
args.copySubRes.dstY = 0;
1807 cmd.
args.copySubRes.dstZ = 0;
1808 cmd.
args.copySubRes.src = bufD->buffer;
1809 cmd.
args.copySubRes.srcSubRes = 0;
1810 cmd.
args.copySubRes.hasSrcBox =
true;
1814 box.back =
box.bottom = 1;
1816 cmd.
args.copySubRes.srcBox =
box;
1822 for (
int opIdx = 0; opIdx < ud->activeTextureOpCount; ++opIdx) {
1845 srcBox.left = UINT(
sp.x());
1846 srcBox.top = UINT(
sp.y());
1849 srcBox.right = srcBox.left + UINT(copySize.width());
1850 srcBox.bottom = srcBox.top + UINT(copySize.height());
1851 srcBox.back = srcBox.front + 1;
1854 cmd.
args.copySubRes.dst = dstD->textureResource();
1855 cmd.
args.copySubRes.dstSubRes = dstSubRes;
1856 cmd.
args.copySubRes.dstX = UINT(dp.x());
1857 cmd.
args.copySubRes.dstY = UINT(dp.y());
1859 cmd.
args.copySubRes.src = srcD->textureResource();
1860 cmd.
args.copySubRes.srcSubRes = srcSubRes;
1861 cmd.
args.copySubRes.hasSrcBox =
true;
1862 cmd.
args.copySubRes.srcBox = srcBox;
1866 readback.result = u.
result;
1868 ID3D11Resource *
src;
1869 DXGI_FORMAT dxgiFormat;
1878 if (texD->sampleDesc.Count > 1) {
1879 qWarning(
"Multisample texture cannot be read back");
1882 src = texD->textureResource();
1883 dxgiFormat = texD->dxgiFormat;
1884 pixelSize =
q->sizeForMipLevel(u.
rb.
level(), texD->m_pixelSize);
1887 subres = D3D11CalcSubresource(UINT(u.
rb.
level()), UINT(is3D ? 0 : u.
rb.
layer()), texD->mipLevelCount);
1891 if (swapChainD->sampleDesc.Count > 1) {
1896 rcmd.args.resolveSubRes.dst = swapChainD->backBufferTex;
1897 rcmd.args.resolveSubRes.dstSubRes = 0;
1898 rcmd.args.resolveSubRes.src = swapChainD->msaaTex[swapChainD->currentFrameSlot];
1899 rcmd.args.resolveSubRes.srcSubRes = 0;
1900 rcmd.args.resolveSubRes.format = swapChainD->colorFormat;
1902 src = swapChainD->backBufferTex;
1903 dxgiFormat = swapChainD->colorFormat;
1904 pixelSize = swapChainD->pixelSize;
1913 D3D11_TEXTURE2D_DESC desc = {};
1914 desc.Width = UINT(pixelSize.
width());
1915 desc.Height = UINT(pixelSize.
height());
1918 desc.Format = dxgiFormat;
1919 desc.SampleDesc.Count = 1;
1920 desc.Usage = D3D11_USAGE_STAGING;
1921 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
1922 ID3D11Texture2D *stagingTex;
1923 HRESULT hr =
dev->CreateTexture2D(&desc,
nullptr, &stagingTex);
1925 qWarning(
"Failed to create readback staging texture: %s",
1926 qPrintable(QSystemError::windowsComString(hr)));
1932 cmd.
args.copySubRes.dst = stagingTex;
1933 cmd.
args.copySubRes.dstSubRes = 0;
1934 cmd.
args.copySubRes.dstX = 0;
1935 cmd.
args.copySubRes.dstY = 0;
1936 cmd.
args.copySubRes.dstZ = 0;
1937 cmd.
args.copySubRes.src =
src;
1938 cmd.
args.copySubRes.srcSubRes = subres;
1940 D3D11_BOX srcBox = {};
1941 srcBox.front = UINT(u.
rb.
layer());
1942 srcBox.right = desc.Width;
1943 srcBox.bottom = desc.Height;
1944 srcBox.back = srcBox.front + 1;
1945 cmd.
args.copySubRes.hasSrcBox =
true;
1946 cmd.
args.copySubRes.srcBox = srcBox;
1948 cmd.
args.copySubRes.hasSrcBox =
false;
1951 readback.stagingTex = stagingTex;
1952 readback.byteSize = byteSize;
1954 readback.pixelSize = pixelSize;
1955 readback.format =
format;
1975 readback.result->format = readback.format;
1976 readback.result->pixelSize = readback.pixelSize;
1978 D3D11_MAPPED_SUBRESOURCE mp;
1979 HRESULT hr =
context->Map(readback.stagingTex, 0, D3D11_MAP_READ, 0, &mp);
1980 if (SUCCEEDED(hr)) {
1981 readback.result->data.resize(
int(readback.byteSize));
1984 char *
dst = readback.result->data.data();
1985 char *
src =
static_cast<char *
>(mp.pData);
1986 for (
int y = 0,
h = readback.pixelSize.height();
y !=
h; ++
y) {
1987 memcpy(
dst,
src, readback.bpl);
1988 dst += readback.bpl;
1991 context->Unmap(readback.stagingTex, 0);
1993 qWarning(
"Failed to map readback staging texture: %s",
1994 qPrintable(QSystemError::windowsComString(hr)));
1997 readback.stagingTex->Release();
1999 if (readback.result->completed)
2000 completedCallbacks.append(readback.result->completed);
2008 D3D11_MAPPED_SUBRESOURCE mp;
2009 HRESULT hr =
context->Map(readback.stagingBuf, 0, D3D11_MAP_READ, 0, &mp);
2010 if (SUCCEEDED(hr)) {
2011 readback.result->data.resize(
int(readback.byteSize));
2012 memcpy(readback.result->data.data(), mp.pData, readback.byteSize);
2013 context->Unmap(readback.stagingBuf, 0);
2015 qWarning(
"Failed to map readback staging texture: %s",
2016 qPrintable(QSystemError::windowsComString(hr)));
2019 readback.stagingBuf->Release();
2021 if (readback.result->completed)
2022 completedCallbacks.append(readback.result->completed);
2027 for (
auto f : completedCallbacks)
2040 const QColor &colorClearValue,
2043 QRhiCommandBuffer::BeginPassFlags)
2048 if (resourceUpdates)
2051 bool wantsColorClear =
true;
2052 bool wantsDsClear =
true;
2058 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QD3D11Texture, QD3D11RenderBuffer>(rtTex->description(), rtD->currentResIdList))
2066 fbCmd.args.setRenderTarget.rt = rt;
2070 clearCmd.args.clear.rt = rt;
2071 clearCmd.args.clear.mask = 0;
2072 if (rtD->colorAttCount && wantsColorClear)
2074 if (rtD->dsAttCount && wantsDsClear)
2077 clearCmd.args.clear.c[0] = float(colorClearValue.redF());
2078 clearCmd.args.clear.c[1] = float(colorClearValue.greenF());
2079 clearCmd.args.clear.c[2] = float(colorClearValue.blueF());
2080 clearCmd.args.clear.c[3] = float(colorClearValue.alphaF());
2081 clearCmd.args.clear.d = depthStencilClearValue.depthClearValue();
2082 clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue();
2097 for (
auto it = rtTex->m_desc.cbeginColorAttachments(), itEnd = rtTex->m_desc.cendColorAttachments();
2110 cmd.
args.resolveSubRes.dst = dstTexD->textureResource();
2111 cmd.
args.resolveSubRes.dstSubRes = D3D11CalcSubresource(UINT(colorAtt.
resolveLevel()),
2113 dstTexD->mipLevelCount);
2115 cmd.
args.resolveSubRes.src = srcTexD->textureResource();
2116 if (srcTexD->dxgiFormat != dstTexD->dxgiFormat) {
2117 qWarning(
"Resolve source (%d) and destination (%d) formats do not match",
2118 int(srcTexD->dxgiFormat),
int(dstTexD->dxgiFormat));
2122 if (srcTexD->sampleDesc.Count <= 1) {
2123 qWarning(
"Cannot resolve a non-multisample texture");
2127 if (srcTexD->m_pixelSize != dstTexD->m_pixelSize) {
2128 qWarning(
"Resolve source and destination sizes do not match");
2133 cmd.
args.resolveSubRes.src = srcRbD->tex;
2134 if (srcRbD->dxgiFormat != dstTexD->dxgiFormat) {
2135 qWarning(
"Resolve source (%d) and destination (%d) formats do not match",
2136 int(srcRbD->dxgiFormat),
int(dstTexD->dxgiFormat));
2140 if (srcRbD->m_pixelSize != dstTexD->m_pixelSize) {
2141 qWarning(
"Resolve source and destination sizes do not match");
2146 cmd.
args.resolveSubRes.srcSubRes = D3D11CalcSubresource(0, UINT(colorAtt.
layer()), 1);
2147 cmd.
args.resolveSubRes.format = dstTexD->dxgiFormat;
2149 if (rtTex->m_desc.depthResolveTexture())
2150 qWarning(
"Resolving multisample depth-stencil buffers is not supported with D3D");
2156 if (resourceUpdates)
2162 QRhiCommandBuffer::BeginPassFlags)
2167 if (resourceUpdates)
2185 if (resourceUpdates)
2196 if (pipelineChanged) {
2203 cmd.
args.bindComputePipeline.ps = psD;
2214 cmd.
args.dispatch.x = UINT(
x);
2215 cmd.
args.dispatch.y = UINT(
y);
2216 cmd.
args.dispatch.z = UINT(
z);
2225 return { binding, binding };
2240 srbD->vsUniformBufferBatches.
clear();
2241 srbD->hsUniformBufferBatches.clear();
2242 srbD->dsUniformBufferBatches.clear();
2243 srbD->gsUniformBufferBatches.clear();
2244 srbD->fsUniformBufferBatches.clear();
2245 srbD->csUniformBufferBatches.clear();
2247 srbD->vsSamplerBatches.clear();
2248 srbD->hsSamplerBatches.clear();
2249 srbD->dsSamplerBatches.clear();
2250 srbD->gsSamplerBatches.clear();
2251 srbD->fsSamplerBatches.clear();
2252 srbD->csSamplerBatches.clear();
2254 srbD->csUavBatches.clear();
2261 uint offsetInConstants;
2262 uint sizeInConstants;
2266 ID3D11ShaderResourceView *srv;
2274 ID3D11UnorderedAccessView *uav;
2276 QVarLengthArray<Buffer, 8>
buffers;
2277 QVarLengthArray<Texture, 8>
textures;
2278 QVarLengthArray<Sampler, 8>
samplers;
2279 QVarLengthArray<Uav, 8> uavs;
2300 for (
const Stage::Uav &u : uavs)
2306 for (
int i = 0, ie = srbD->sortedBindings.count();
i != ie; ++
i) {
2314 bd.ubuf.id = bufD->m_id;
2315 bd.ubuf.generation = bufD->generation;
2322 const quint32 offsetInConstants =
b->u.ubuf.offset / 16;
2326 const quint32 sizeInConstants =
aligned(
b->u.ubuf.maybeSize ?
b->u.ubuf.maybeSize : bufD->m_size, 256u) / 16;
2329 if (nativeBinding.first >= 0)
2330 res[
RBM_VERTEX].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2333 QPair<int, int> nativeBinding =
mapBinding(
b->binding,
RBM_HULL, nativeResourceBindingMaps);
2334 if (nativeBinding.first >= 0)
2335 res[
RBM_HULL].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2339 if (nativeBinding.first >= 0)
2340 res[
RBM_DOMAIN].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2344 if (nativeBinding.first >= 0)
2345 res[
RBM_GEOMETRY].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2349 if (nativeBinding.first >= 0)
2350 res[
RBM_FRAGMENT].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2354 if (nativeBinding.first >= 0)
2355 res[
RBM_COMPUTE].buffers.append({
b->binding, nativeBinding.first, bufD->buffer, offsetInConstants, sizeInConstants });
2365 const QPair<int, int> nativeBindingVert =
mapBinding(
b->binding,
RBM_VERTEX, nativeResourceBindingMaps);
2366 const QPair<int, int> nativeBindingHull =
mapBinding(
b->binding,
RBM_HULL, nativeResourceBindingMaps);
2367 const QPair<int, int> nativeBindingDomain =
mapBinding(
b->binding,
RBM_DOMAIN, nativeResourceBindingMaps);
2370 const QPair<int, int> nativeBindingComp =
mapBinding(
b->binding,
RBM_COMPUTE, nativeResourceBindingMaps);
2374 for (
int elem = 0; elem <
data->count; ++elem) {
2377 bd.stex.d[elem].texId = texD ? texD->m_id : 0;
2378 bd.stex.d[elem].texGeneration = texD ? texD->generation : 0;
2379 bd.stex.d[elem].samplerId = samplerD ? samplerD->m_id : 0;
2380 bd.stex.d[elem].samplerGeneration = samplerD ? samplerD->generation : 0;
2386 const int samplerBinding = texD && samplerD ? nativeBindingVert.second
2387 : (samplerD ? nativeBindingVert.first : -1);
2388 if (nativeBindingVert.first >= 0 && texD)
2389 res[
RBM_VERTEX].textures.append({ nativeBindingVert.first + elem, texD->srv });
2390 if (samplerBinding >= 0)
2391 res[
RBM_VERTEX].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2394 const int samplerBinding = texD && samplerD ? nativeBindingHull.second
2395 : (samplerD ? nativeBindingHull.first : -1);
2396 if (nativeBindingHull.first >= 0 && texD)
2397 res[
RBM_HULL].textures.append({ nativeBindingHull.first + elem, texD->srv });
2398 if (samplerBinding >= 0)
2399 res[
RBM_HULL].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2402 const int samplerBinding = texD && samplerD ? nativeBindingDomain.second
2403 : (samplerD ? nativeBindingDomain.first : -1);
2404 if (nativeBindingDomain.first >= 0 && texD)
2405 res[
RBM_DOMAIN].textures.append({ nativeBindingDomain.first + elem, texD->srv });
2406 if (samplerBinding >= 0)
2407 res[
RBM_DOMAIN].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2410 const int samplerBinding = texD && samplerD ? nativeBindingGeom.second
2411 : (samplerD ? nativeBindingGeom.first : -1);
2412 if (nativeBindingGeom.first >= 0 && texD)
2413 res[
RBM_GEOMETRY].textures.append({ nativeBindingGeom.first + elem, texD->srv });
2414 if (samplerBinding >= 0)
2415 res[
RBM_GEOMETRY].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2418 const int samplerBinding = texD && samplerD ? nativeBindingFrag.second
2419 : (samplerD ? nativeBindingFrag.first : -1);
2420 if (nativeBindingFrag.first >= 0 && texD)
2421 res[
RBM_FRAGMENT].textures.append({ nativeBindingFrag.first + elem, texD->srv });
2422 if (samplerBinding >= 0)
2423 res[
RBM_FRAGMENT].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2426 const int samplerBinding = texD && samplerD ? nativeBindingComp.second
2427 : (samplerD ? nativeBindingComp.first : -1);
2428 if (nativeBindingComp.first >= 0 && texD)
2429 res[
RBM_COMPUTE].textures.append({ nativeBindingComp.first + elem, texD->srv });
2430 if (samplerBinding >= 0)
2431 res[
RBM_COMPUTE].samplers.append({ samplerBinding + elem, samplerD->samplerState });
2441 bd.simage.id = texD->m_id;
2442 bd.simage.generation = texD->generation;
2445 if (nativeBinding.first >= 0) {
2446 ID3D11UnorderedAccessView *uav = texD->unorderedAccessViewForLevel(
b->u.simage.level);
2451 qWarning(
"Unordered access only supported at compute stage");
2460 bd.sbuf.id = bufD->m_id;
2461 bd.sbuf.generation = bufD->generation;
2464 if (nativeBinding.first >= 0) {
2465 ID3D11UnorderedAccessView *uav = bufD->unorderedAccessView(
b->u.sbuf.offset);
2470 qWarning(
"Unordered access only supported at compute stage");
2485 std::sort(
res[stage].
buffers.begin(),
res[stage].buffers.end(), [](
const Stage::Buffer &
a,
const Stage::Buffer &
b) {
2486 return a.breg < b.breg;
2488 std::sort(
res[stage].
textures.begin(),
res[stage].textures.end(), [](
const Stage::Texture &
a,
const Stage::Texture &
b) {
2489 return a.treg < b.treg;
2491 std::sort(
res[stage].
samplers.begin(),
res[stage].samplers.end(), [](
const Stage::Sampler &
a,
const Stage::Sampler &
b) {
2492 return a.sreg < b.sreg;
2494 std::sort(
res[stage].uavs.begin(),
res[stage].uavs.end(), [](
const Stage::Uav &
a,
const Stage::Uav &
b) {
2495 return a.ureg < b.ureg;
2499 res[
RBM_VERTEX].buildBufferBatches(srbD->vsUniformBufferBatches);
2500 res[
RBM_HULL].buildBufferBatches(srbD->hsUniformBufferBatches);
2501 res[
RBM_DOMAIN].buildBufferBatches(srbD->dsUniformBufferBatches);
2504 res[
RBM_COMPUTE].buildBufferBatches(srbD->csUniformBufferBatches);
2506 res[
RBM_VERTEX].buildSamplerBatches(srbD->vsSamplerBatches);
2507 res[
RBM_HULL].buildSamplerBatches(srbD->hsSamplerBatches);
2508 res[
RBM_DOMAIN].buildSamplerBatches(srbD->dsSamplerBatches);
2518 if (!bufD->hasPendingDynamicUpdates || bufD->m_size < 1)
2522 bufD->hasPendingDynamicUpdates =
false;
2523 D3D11_MAPPED_SUBRESOURCE mp;
2524 HRESULT hr =
context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
2525 if (SUCCEEDED(hr)) {
2526 memcpy(mp.pData, bufD->dynBuf, bufD->m_size);
2527 context->Unmap(bufD->buffer, 0);
2529 qWarning(
"Failed to map buffer: %s",
2530 qPrintable(QSystemError::windowsComString(hr)));
2536 const QRhiBatchedBindings<UINT> *originalBindings,
2537 const QRhiBatchedBindings<UINT> *staticOffsets,
2538 const uint *dynOfsPairs,
int dynOfsPairCount)
2540 const int count = staticOffsets->batches[batchIndex].resources.count();
2544 offsets[
b] = staticOffsets->batches[batchIndex].resources[
b];
2545 for (
int di = 0; di < dynOfsPairCount; ++di) {
2546 const uint binding = dynOfsPairs[2 * di];
2549 if (binding == originalBindings->batches[batchIndex].resources[
b]) {
2550 const uint offsetInConstants = dynOfsPairs[2 * di + 1];
2560 if (startSlot + countSlots > maxSlots) {
2561 qWarning(
"Not enough D3D11 %s slots to bind %d resources starting at slot %d, max slots is %d",
2562 resType, countSlots, startSlot, maxSlots);
2563 countSlots = maxSlots > startSlot ? maxSlots - startSlot : 0;
2568#define SETUBUFBATCH(stagePrefixL, stagePrefixU) \
2569 if (srbD->stagePrefixL##UniformBufferBatches.present) { \
2570 const QD3D11ShaderResourceBindings::StageUniformBufferBatches &batches(srbD->stagePrefixL##UniformBufferBatches); \
2571 for (int i = 0, ie = batches.ubufs.batches.count(); i != ie; ++i) { \
2572 const uint count = clampedResourceCount(batches.ubufs.batches[i].startBinding, \
2573 batches.ubufs.batches[i].resources.count(), \
2574 D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, \
2575 #stagePrefixU " cbuf"); \
2577 if (!dynOfsPairCount) { \
2578 context->stagePrefixU##SetConstantBuffers1(batches.ubufs.batches[i].startBinding, \
2580 batches.ubufs.batches[i].resources.constData(), \
2581 batches.ubufoffsets.batches[i].resources.constData(), \
2582 batches.ubufsizes.batches[i].resources.constData()); \
2584 applyDynamicOffsets(offsets, i, \
2585 &batches.ubuforigbindings, &batches.ubufoffsets, \
2586 dynOfsPairs, dynOfsPairCount); \
2587 context->stagePrefixU##SetConstantBuffers1(batches.ubufs.batches[i].startBinding, \
2589 batches.ubufs.batches[i].resources.constData(), \
2591 batches.ubufsizes.batches[i].resources.constData()); \
2597#define SETSAMPLERBATCH(stagePrefixL, stagePrefixU) \
2598 if (srbD->stagePrefixL##SamplerBatches.present) { \
2599 for (const auto &batch : srbD->stagePrefixL##SamplerBatches.samplers.batches) { \
2600 const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
2601 D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, #stagePrefixU " sampler"); \
2603 context->stagePrefixU##SetSamplers(batch.startBinding, count, batch.resources.constData()); \
2605 for (const auto &batch : srbD->stagePrefixL##SamplerBatches.shaderresources.batches) { \
2606 const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
2607 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, #stagePrefixU " SRV"); \
2609 context->stagePrefixU##SetShaderResources(batch.startBinding, count, batch.resources.constData()); \
2610 contextState.stagePrefixL##HighestActiveSrvBinding = qMax(contextState.stagePrefixL##HighestActiveSrvBinding, \
2611 int(batch.startBinding + count) - 1); \
2616#define SETUAVBATCH(stagePrefixL, stagePrefixU) \
2617 if (srbD->stagePrefixL##UavBatches.present) { \
2618 for (const auto &batch : srbD->stagePrefixL##UavBatches.uavs.batches) { \
2619 const uint count = clampedResourceCount(batch.startBinding, batch.resources.count(), \
2620 D3D11_1_UAV_SLOT_COUNT, #stagePrefixU " UAV"); \
2622 context->stagePrefixU##SetUnorderedAccessViews(batch.startBinding, \
2624 batch.resources.constData(), \
2626 contextState.stagePrefixL##HighestActiveUavBinding = qMax(contextState.stagePrefixL##HighestActiveUavBinding, \
2627 int(batch.startBinding + count) - 1); \
2633 const uint *dynOfsPairs,
int dynOfsPairCount,
2634 bool offsetOnlyChange)
2645 if (!offsetOnlyChange) {
2662 context->IASetIndexBuffer(
nullptr, DXGI_FORMAT_R16_UINT, 0);
2666 if (
contextState.vsHighestActiveVertexBufferBinding >= 0) {
2668 QVarLengthArray<ID3D11Buffer *, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nullbufs(
count);
2670 nullbufs[
i] =
nullptr;
2671 QVarLengthArray<UINT, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nullstrides(
count);
2674 QVarLengthArray<UINT, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nulloffsets(
count);
2677 context->IASetVertexBuffers(0, UINT(
count), nullbufs.constData(), nullstrides.constData(), nulloffsets.constData());
2687 if (nullsrvCount > 0) {
2689 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> nullsrvs(nullsrvCount);
2690 for (
int i = 0;
i < nullsrvs.count(); ++
i)
2691 nullsrvs[
i] =
nullptr;
2693 context->VSSetShaderResources(0, UINT(
contextState.vsHighestActiveSrvBinding + 1), nullsrvs.constData());
2697 context->HSSetShaderResources(0, UINT(
contextState.hsHighestActiveSrvBinding + 1), nullsrvs.constData());
2701 context->DSSetShaderResources(0, UINT(
contextState.dsHighestActiveSrvBinding + 1), nullsrvs.constData());
2705 context->GSSetShaderResources(0, UINT(
contextState.gsHighestActiveSrvBinding + 1), nullsrvs.constData());
2709 context->PSSetShaderResources(0, UINT(
contextState.fsHighestActiveSrvBinding + 1), nullsrvs.constData());
2713 context->CSSetShaderResources(0, UINT(
contextState.csHighestActiveSrvBinding + 1), nullsrvs.constData());
2719 const int nulluavCount =
contextState.csHighestActiveUavBinding + 1;
2721 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> nulluavs(nulluavCount);
2722 for (
int i = 0;
i < nulluavCount; ++
i)
2723 nulluavs[
i] =
nullptr;
2724 context->CSSetUnorderedAccessViews(0, UINT(nulluavCount), nulluavs.constData(),
nullptr);
2729#define SETSHADER(StageL, StageU) \
2730 if (psD->StageL.shader) { \
2731 context->StageU##SetShader(psD->StageL.shader, nullptr, 0); \
2732 currentShaderMask |= StageU##MaskBit; \
2733 } else if (currentShaderMask & StageU##MaskBit) { \
2734 context->StageU##SetShader(nullptr, nullptr, 0); \
2735 currentShaderMask &= ~StageU##MaskBit; \
2741 float blendConstants[] = { 1, 1, 1, 1 };
2742 enum ActiveShaderMask {
2749 int currentShaderMask = 0xFF;
2755 if (cmd.
args.beginFrame.tsDisjointQuery)
2756 context->Begin(cmd.
args.beginFrame.tsDisjointQuery);
2757 if (cmd.
args.beginFrame.tsQuery) {
2758 if (cmd.
args.beginFrame.swapchainData) {
2764 context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv :
nullptr, rtD->dsv);
2770 if (cmd.
args.endFrame.tsQuery)
2772 if (cmd.
args.endFrame.tsDisjointQuery)
2781 context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv :
nullptr, rtD->dsv);
2788 for (
int i = 0;
i < rtD->colorAttCount; ++
i)
2789 context->ClearRenderTargetView(rtD->rtv[
i], cmd.
args.clear.c);
2793 ds |= D3D11_CLEAR_DEPTH;
2795 ds |= D3D11_CLEAR_STENCIL;
2797 context->ClearDepthStencilView(rtD->dsv, ds, cmd.
args.clear.d, UINT8(cmd.
args.clear.s));
2803 v.TopLeftX = cmd.
args.viewport.x;
2804 v.TopLeftY = cmd.
args.viewport.y;
2805 v.Width = cmd.
args.viewport.w;
2806 v.Height = cmd.
args.viewport.h;
2807 v.MinDepth = cmd.
args.viewport.d0;
2808 v.MaxDepth = cmd.
args.viewport.d1;
2815 r.left = cmd.
args.scissor.x;
2816 r.top = cmd.
args.scissor.y;
2818 r.right = cmd.
args.scissor.x + cmd.
args.scissor.w;
2819 r.bottom = cmd.
args.scissor.y + cmd.
args.scissor.h;
2824 contextState.vsHighestActiveVertexBufferBinding = qMax<int>(
2826 cmd.
args.bindVertexBuffers.startSlot + cmd.
args.bindVertexBuffers.slotCount - 1);
2827 context->IASetVertexBuffers(UINT(cmd.
args.bindVertexBuffers.startSlot),
2828 UINT(cmd.
args.bindVertexBuffers.slotCount),
2829 cmd.
args.bindVertexBuffers.buffers,
2830 cmd.
args.bindVertexBuffers.strides,
2831 cmd.
args.bindVertexBuffers.offsets);
2835 context->IASetIndexBuffer(cmd.
args.bindIndexBuffer.buffer,
2836 cmd.
args.bindIndexBuffer.format,
2837 cmd.
args.bindIndexBuffer.offset);
2847 context->IASetPrimitiveTopology(psD->d3dTopology);
2848 context->IASetInputLayout(psD->inputLayout);
2849 context->OMSetDepthStencilState(psD->dsState, stencilRef);
2850 context->OMSetBlendState(psD->blendState, blendConstants, 0xffffffff);
2851 context->RSSetState(psD->rastState);
2856 cmd.
args.bindShaderResources.dynamicOffsetPairs,
2857 cmd.
args.bindShaderResources.dynamicOffsetCount,
2858 cmd.
args.bindShaderResources.offsetOnlyChange);
2861 stencilRef = cmd.
args.stencilRef.ref;
2862 context->OMSetDepthStencilState(cmd.
args.stencilRef.ps->dsState, stencilRef);
2865 memcpy(blendConstants, cmd.
args.blendConstants.c, 4 *
sizeof(
float));
2866 context->OMSetBlendState(cmd.
args.blendConstants.ps->blendState, blendConstants, 0xffffffff);
2869 if (cmd.
args.draw.ps) {
2870 if (cmd.
args.draw.instanceCount == 1)
2873 context->DrawInstanced(cmd.
args.draw.vertexCount, cmd.
args.draw.instanceCount,
2874 cmd.
args.draw.firstVertex, cmd.
args.draw.firstInstance);
2876 qWarning(
"No graphics pipeline active for draw; ignored");
2880 if (cmd.
args.drawIndexed.ps) {
2881 if (cmd.
args.drawIndexed.instanceCount == 1)
2882 context->DrawIndexed(cmd.
args.drawIndexed.indexCount, cmd.
args.drawIndexed.firstIndex,
2883 cmd.
args.drawIndexed.vertexOffset);
2885 context->DrawIndexedInstanced(cmd.
args.drawIndexed.indexCount, cmd.
args.drawIndexed.instanceCount,
2886 cmd.
args.drawIndexed.firstIndex, cmd.
args.drawIndexed.vertexOffset,
2887 cmd.
args.drawIndexed.firstInstance);
2889 qWarning(
"No graphics pipeline active for drawIndexed; ignored");
2893 context->UpdateSubresource(cmd.
args.updateSubRes.dst, cmd.
args.updateSubRes.dstSubRes,
2894 cmd.
args.updateSubRes.hasDstBox ? &cmd.
args.updateSubRes.dstBox :
nullptr,
2895 cmd.
args.updateSubRes.src, cmd.
args.updateSubRes.srcRowPitch, 0);
2898 context->CopySubresourceRegion(cmd.
args.copySubRes.dst, cmd.
args.copySubRes.dstSubRes,
2899 cmd.
args.copySubRes.dstX, cmd.
args.copySubRes.dstY, cmd.
args.copySubRes.dstZ,
2900 cmd.
args.copySubRes.src, cmd.
args.copySubRes.srcSubRes,
2901 cmd.
args.copySubRes.hasSrcBox ? &cmd.
args.copySubRes.srcBox :
nullptr);
2904 context->ResolveSubresource(cmd.
args.resolveSubRes.dst, cmd.
args.resolveSubRes.dstSubRes,
2905 cmd.
args.resolveSubRes.src, cmd.
args.resolveSubRes.srcSubRes,
2906 cmd.
args.resolveSubRes.format);
2921 context->CSSetShader(cmd.
args.bindComputePipeline.ps->cs.shader,
nullptr, 0);
2954 it.value()->Release();
2959 rhiD->unregisterResource(
this);
2966 u |= D3D11_BIND_VERTEX_BUFFER;
2968 u |= D3D11_BIND_INDEX_BUFFER;
2970 u |= D3D11_BIND_CONSTANT_BUFFER;
2972 u |= D3D11_BIND_UNORDERED_ACCESS;
2982 qWarning(
"UniformBuffer must always be combined with Dynamic on D3D11");
2987 qWarning(
"StorageBuffer cannot be combined with Dynamic");
2994 D3D11_BUFFER_DESC desc = {};
2995 desc.ByteWidth = roundedSize;
2996 desc.Usage =
m_type ==
Dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
2998 desc.CPUAccessFlags =
m_type ==
Dynamic ? D3D11_CPU_ACCESS_WRITE : 0;
3002 HRESULT hr = rhiD->dev->CreateBuffer(&desc,
nullptr, &
buffer);
3004 qWarning(
"Failed to create buffer: %s",
3005 qPrintable(QSystemError::windowsComString(hr)));
3010 dynBuf =
new char[nonZeroSize];
3018 rhiD->registerResource(
this);
3026 rhiD->executeBufferHostWrites(
this);
3028 return { { &
buffer }, 1 };
3040 D3D11_MAPPED_SUBRESOURCE mp;
3042 HRESULT hr = rhiD->context->Map(
buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
3044 qWarning(
"Failed to map buffer: %s",
3045 qPrintable(QSystemError::windowsComString(hr)));
3048 return static_cast<char *
>(mp.pData);
3054 rhiD->context->Unmap(
buffer, 0);
3064 D3D11_UNORDERED_ACCESS_VIEW_DESC desc = {};
3065 desc.Format = DXGI_FORMAT_R32_TYPELESS;
3066 desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
3067 desc.Buffer.FirstElement =
offset / 4u;
3069 desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
3072 ID3D11UnorderedAccessView *uav =
nullptr;
3073 HRESULT hr = rhiD->dev->CreateUnorderedAccessView(
buffer, &desc, &uav);
3075 qWarning(
"Failed to create UAV: %s",
3076 qPrintable(QSystemError::windowsComString(hr)));
3085 int sampleCount, QRhiRenderBuffer::Flags
flags,
3116 rhiD->unregisterResource(
this);
3130 D3D11_TEXTURE2D_DESC desc = {};
3136 desc.Usage = D3D11_USAGE_DEFAULT;
3142 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3143 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, &
tex);
3145 qWarning(
"Failed to create color renderbuffer: %s",
3146 qPrintable(QSystemError::windowsComString(hr)));
3149 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
3151 rtvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS
3152 : D3D11_RTV_DIMENSION_TEXTURE2D;
3153 hr = rhiD->dev->CreateRenderTargetView(
tex, &rtvDesc, &
rtv);
3155 qWarning(
"Failed to create rtv: %s",
3156 qPrintable(QSystemError::windowsComString(hr)));
3162 desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3163 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, &
tex);
3165 qWarning(
"Failed to create depth-stencil buffer: %s",
3166 qPrintable(QSystemError::windowsComString(hr)));
3169 D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
3171 dsvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS
3172 : D3D11_DSV_DIMENSION_TEXTURE2D;
3173 hr = rhiD->dev->CreateDepthStencilView(
tex, &dsvDesc, &
dsv);
3175 qWarning(
"Failed to create dsv: %s",
3176 qPrintable(QSystemError::windowsComString(hr)));
3187 rhiD->registerResource(
this);
3244 rhiD->unregisterResource(
this);
3251 return DXGI_FORMAT_R16_FLOAT;
3253 return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
3255 return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
3257 return DXGI_FORMAT_R32_FLOAT;
3260 return DXGI_FORMAT_R32_FLOAT;
3268 return DXGI_FORMAT_D16_UNORM;
3270 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3272 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3274 return DXGI_FORMAT_D32_FLOAT;
3277 return DXGI_FORMAT_D32_FLOAT;
3302 qWarning(
"Cubemap texture cannot be multisample");
3306 qWarning(
"3D texture cannot be multisample");
3310 qWarning(
"Multisample texture cannot have mipmaps");
3314 if (isDepth && hasMipMaps) {
3315 qWarning(
"Depth texture cannot have mipmaps");
3318 if (isCube && is3D) {
3319 qWarning(
"Texture cannot be both cube and 3D");
3322 if (isArray && is3D) {
3323 qWarning(
"Texture cannot be both array and 3D");
3326 if (isCube && is1D) {
3327 qWarning(
"Texture cannot be both cube and 1D");
3331 qWarning(
"Texture cannot be both 1D and 3D");
3335 qWarning(
"Texture cannot have a depth of %d when it is not 3D",
m_depth);
3348 *adjustedSize =
size;
3362 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
3365 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
3370 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
3376 srvDesc.Texture1DArray.FirstArraySlice = 0;
3380 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
3383 }
else if (isArray) {
3385 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
3390 srvDesc.Texture2DMSArray.FirstArraySlice = 0;
3394 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
3400 srvDesc.Texture2DArray.FirstArraySlice = 0;
3406 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
3408 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
3411 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
3419 qWarning(
"Failed to create srv: %s",
3420 qPrintable(QSystemError::windowsComString(hr)));
3440 uint bindFlags = D3D11_BIND_SHADER_RESOURCE;
3441 uint miscFlags = isCube ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0;
3444 bindFlags |= D3D11_BIND_DEPTH_STENCIL;
3446 bindFlags |= D3D11_BIND_RENDER_TARGET;
3450 qWarning(
"Depth texture cannot have mipmaps generated");
3453 bindFlags |= D3D11_BIND_RENDER_TARGET;
3454 miscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
3457 bindFlags |= D3D11_BIND_UNORDERED_ACCESS;
3461 D3D11_TEXTURE1D_DESC desc = {};
3462 desc.Width = UINT(
size.width());
3466 desc.Usage = D3D11_USAGE_DEFAULT;
3467 desc.BindFlags = bindFlags;
3468 desc.MiscFlags = miscFlags;
3470 HRESULT hr = rhiD->dev->CreateTexture1D(&desc,
nullptr, &
tex1D);
3472 qWarning(
"Failed to create 1D texture: %s",
3473 qPrintable(QSystemError::windowsComString(hr)));
3480 D3D11_TEXTURE2D_DESC desc = {};
3481 desc.Width = UINT(
size.width());
3482 desc.Height = UINT(
size.height());
3484 desc.ArraySize = isCube ? 6 : (isArray ? UINT(
qMax(0,
m_arraySize)) : 1);
3487 desc.Usage = D3D11_USAGE_DEFAULT;
3488 desc.BindFlags = bindFlags;
3489 desc.MiscFlags = miscFlags;
3491 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, &
tex);
3493 qWarning(
"Failed to create 2D texture: %s",
3494 qPrintable(QSystemError::windowsComString(hr)));
3500 D3D11_TEXTURE3D_DESC desc = {};
3501 desc.Width = UINT(
size.width());
3502 desc.Height = UINT(
size.height());
3506 desc.Usage = D3D11_USAGE_DEFAULT;
3507 desc.BindFlags = bindFlags;
3508 desc.MiscFlags = miscFlags;
3510 HRESULT hr = rhiD->dev->CreateTexture3D(&desc,
nullptr, &
tex3D);
3512 qWarning(
"Failed to create 3D texture: %s",
3513 qPrintable(QSystemError::windowsComString(hr)));
3524 rhiD->registerResource(
this);
3537 tex3D =
reinterpret_cast<ID3D11Texture3D *
>(
src.object);
3539 tex1D =
reinterpret_cast<ID3D11Texture1D *
>(
src.object);
3541 tex =
reinterpret_cast<ID3D11Texture2D *
>(
src.object);
3548 rhiD->registerResource(
this);
3565 D3D11_UNORDERED_ACCESS_VIEW_DESC desc = {};
3568 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
3569 desc.Texture2DArray.MipSlice = UINT(
level);
3570 desc.Texture2DArray.FirstArraySlice = 0;
3571 desc.Texture2DArray.ArraySize = 6;
3572 }
else if (isArray) {
3573 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
3574 desc.Texture2DArray.MipSlice = UINT(
level);
3575 desc.Texture2DArray.FirstArraySlice = 0;
3578 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
3579 desc.Texture3D.MipSlice = UINT(
level);
3581 desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
3582 desc.Texture2D.MipSlice = UINT(
level);
3586 ID3D11UnorderedAccessView *uav =
nullptr;
3589 qWarning(
"Failed to create UAV: %s",
3590 qPrintable(QSystemError::windowsComString(hr)));
3600 :
QRhiSampler(rhi, magFilter, minFilter, mipmapMode, u,
v,
w)
3619 rhiD->unregisterResource(
this);
3627 return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
3629 return D3D11_FILTER_MIN_MAG_MIP_POINT;
3632 return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
3634 return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
3639 return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
3641 return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
3644 return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
3646 return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
3651 return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
3658 return D3D11_TEXTURE_ADDRESS_WRAP;
3660 return D3D11_TEXTURE_ADDRESS_CLAMP;
3662 return D3D11_TEXTURE_ADDRESS_MIRROR;
3665 return D3D11_TEXTURE_ADDRESS_CLAMP;
3673 return D3D11_COMPARISON_NEVER;
3675 return D3D11_COMPARISON_LESS;
3677 return D3D11_COMPARISON_EQUAL;
3679 return D3D11_COMPARISON_LESS_EQUAL;
3681 return D3D11_COMPARISON_GREATER;
3683 return D3D11_COMPARISON_NOT_EQUAL;
3685 return D3D11_COMPARISON_GREATER_EQUAL;
3687 return D3D11_COMPARISON_ALWAYS;
3690 return D3D11_COMPARISON_NEVER;
3699 D3D11_SAMPLER_DESC desc = {};
3702 desc.Filter = D3D11_FILTER(desc.Filter | 0x80);
3706 desc.MaxAnisotropy = 1.0f;
3713 qWarning(
"Failed to create sampler state: %s",
3714 qPrintable(QSystemError::windowsComString(hr)));
3719 rhiD->registerResource(
this);
3738 rhiD->unregisterResource(
this);
3751 rhiD->registerResource(rpD,
false);
3829 rhiD->unregisterResource(
this);
3836 rhiD->registerResource(rpD,
false);
3861 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
3864 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
3865 rtvDesc.Texture2DArray.MipSlice = UINT(colorAtt.
level());
3866 rtvDesc.Texture2DArray.FirstArraySlice = UINT(colorAtt.
layer());
3867 rtvDesc.Texture2DArray.ArraySize = 1;
3870 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
3871 rtvDesc.Texture1DArray.MipSlice = UINT(colorAtt.
level());
3872 rtvDesc.Texture1DArray.FirstArraySlice = UINT(colorAtt.
layer());
3873 rtvDesc.Texture1DArray.ArraySize = 1;
3875 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
3876 rtvDesc.Texture1D.MipSlice = UINT(colorAtt.
level());
3879 if (texD->sampleDesc.Count > 1) {
3880 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
3881 rtvDesc.Texture2DMSArray.FirstArraySlice = UINT(colorAtt.
layer());
3882 rtvDesc.Texture2DMSArray.ArraySize = 1;
3884 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
3885 rtvDesc.Texture2DArray.MipSlice = UINT(colorAtt.
level());
3886 rtvDesc.Texture2DArray.FirstArraySlice = UINT(colorAtt.
layer());
3887 rtvDesc.Texture2DArray.ArraySize = 1;
3890 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
3891 rtvDesc.Texture3D.MipSlice = UINT(colorAtt.
level());
3892 rtvDesc.Texture3D.FirstWSlice = UINT(colorAtt.
layer());
3893 rtvDesc.Texture3D.WSize = 1;
3895 if (texD->sampleDesc.Count > 1) {
3896 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
3898 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
3899 rtvDesc.Texture2D.MipSlice = UINT(colorAtt.
level());
3902 HRESULT hr = rhiD->dev->CreateRenderTargetView(texD->textureResource(), &rtvDesc, &
rtv[attIndex]);
3904 qWarning(
"Failed to create rtv: %s",
3905 qPrintable(QSystemError::windowsComString(hr)));
3909 if (attIndex == 0) {
3910 d.
pixelSize = rhiD->q->sizeForMipLevel(colorAtt.
level(), texD->pixelSize());
3916 rtv[attIndex] = rbD->rtv;
3917 if (attIndex == 0) {
3925 if (hasDepthStencil) {
3929 D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
3931 dsvDesc.ViewDimension = depthTexD->sampleDesc.Count > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS
3932 : D3D11_DSV_DIMENSION_TEXTURE2D;
3934 if (depthTexD->sampleDesc.Count > 1) {
3935 dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
3936 if (depthTexD->arrayRangeStart() >= 0 && depthTexD->arrayRangeLength() >= 0) {
3937 dsvDesc.Texture2DMSArray.FirstArraySlice = UINT(depthTexD->arrayRangeStart());
3938 dsvDesc.Texture2DMSArray.ArraySize = UINT(depthTexD->arrayRangeLength());
3940 dsvDesc.Texture2DMSArray.FirstArraySlice = 0;
3941 dsvDesc.Texture2DMSArray.ArraySize = UINT(
qMax(0, depthTexD->arraySize()));
3944 dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
3945 if (depthTexD->arrayRangeStart() >= 0 && depthTexD->arrayRangeLength() >= 0) {
3946 dsvDesc.Texture2DArray.FirstArraySlice = UINT(depthTexD->arrayRangeStart());
3947 dsvDesc.Texture2DArray.ArraySize = UINT(depthTexD->arrayRangeLength());
3949 dsvDesc.Texture2DArray.FirstArraySlice = 0;
3950 dsvDesc.Texture2DArray.ArraySize = UINT(
qMax(0, depthTexD->arraySize()));
3954 HRESULT hr = rhiD->dev->CreateDepthStencilView(depthTexD->tex, &dsvDesc, &
dsv);
3956 qWarning(
"Failed to create dsv: %s",
3957 qPrintable(QSystemError::windowsComString(hr)));
3967 dsv = depthRbD->dsv;
3984 QRhiRenderTargetAttachmentTracker::updateResIdList<QD3D11Texture, QD3D11RenderBuffer>(
m_desc, &
d.
currentResIdList);
3986 rhiD->registerResource(
this);
3992 if (!QRhiRenderTargetAttachmentTracker::isUpToDate<QD3D11Texture, QD3D11RenderBuffer>(
m_desc,
d.
currentResIdList))
4025 rhiD->unregisterResource(
this);
4034 if (!rhiD->sanityCheckShaderResourceBindings(
this))
4037 rhiD->updateLayoutDesc(
this);
4057 rhiD->registerResource(
this,
false);
4089 s.shader->Release();
4092 s.nativeResourceBindingMap.clear();
4126 rhiD->unregisterResource(
this);
4133 return D3D11_CULL_NONE;
4135 return D3D11_CULL_FRONT;
4137 return D3D11_CULL_BACK;
4140 return D3D11_CULL_NONE;
4148 return D3D11_FILL_SOLID;
4150 return D3D11_FILL_WIREFRAME;
4153 return D3D11_FILL_SOLID;
4161 return D3D11_COMPARISON_NEVER;
4163 return D3D11_COMPARISON_LESS;
4165 return D3D11_COMPARISON_EQUAL;
4167 return D3D11_COMPARISON_LESS_EQUAL;
4169 return D3D11_COMPARISON_GREATER;
4171 return D3D11_COMPARISON_NOT_EQUAL;
4173 return D3D11_COMPARISON_GREATER_EQUAL;
4175 return D3D11_COMPARISON_ALWAYS;
4178 return D3D11_COMPARISON_ALWAYS;
4186 return D3D11_STENCIL_OP_ZERO;
4188 return D3D11_STENCIL_OP_KEEP;
4190 return D3D11_STENCIL_OP_REPLACE;
4192 return D3D11_STENCIL_OP_INCR_SAT;
4194 return D3D11_STENCIL_OP_DECR_SAT;
4196 return D3D11_STENCIL_OP_INVERT;
4198 return D3D11_STENCIL_OP_INCR;
4200 return D3D11_STENCIL_OP_DECR;
4203 return D3D11_STENCIL_OP_KEEP;
4211 return DXGI_FORMAT_R32G32B32A32_FLOAT;
4213 return DXGI_FORMAT_R32G32B32_FLOAT;
4215 return DXGI_FORMAT_R32G32_FLOAT;
4217 return DXGI_FORMAT_R32_FLOAT;
4219 return DXGI_FORMAT_R8G8B8A8_UNORM;
4221 return DXGI_FORMAT_R8G8_UNORM;
4223 return DXGI_FORMAT_R8_UNORM;
4225 return DXGI_FORMAT_R32G32B32A32_UINT;
4227 return DXGI_FORMAT_R32G32B32_UINT;
4229 return DXGI_FORMAT_R32G32_UINT;
4231 return DXGI_FORMAT_R32_UINT;
4233 return DXGI_FORMAT_R32G32B32A32_SINT;
4235 return DXGI_FORMAT_R32G32B32_SINT;
4237 return DXGI_FORMAT_R32G32_SINT;
4239 return DXGI_FORMAT_R32_SINT;
4243 return DXGI_FORMAT_R16G16B16A16_FLOAT;
4245 return DXGI_FORMAT_R16G16_FLOAT;
4247 return DXGI_FORMAT_R16_FLOAT;
4251 return DXGI_FORMAT_R16G16B16A16_UINT;
4253 return DXGI_FORMAT_R16G16_UINT;
4255 return DXGI_FORMAT_R16_UINT;
4259 return DXGI_FORMAT_R16G16B16A16_SINT;
4261 return DXGI_FORMAT_R16G16_SINT;
4263 return DXGI_FORMAT_R16_SINT;
4266 return DXGI_FORMAT_R32G32B32A32_FLOAT;
4274 return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
4276 return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
4278 return D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
4280 return D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP;
4282 return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
4284 Q_ASSERT(patchControlPointCount >= 1 && patchControlPointCount <= 32);
4285 return D3D11_PRIMITIVE_TOPOLOGY(D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + (patchControlPointCount - 1));
4288 return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
4296 f |= D3D11_COLOR_WRITE_ENABLE_RED;
4298 f |= D3D11_COLOR_WRITE_ENABLE_GREEN;
4300 f |= D3D11_COLOR_WRITE_ENABLE_BLUE;
4302 f |= D3D11_COLOR_WRITE_ENABLE_ALPHA;
4316 return D3D11_BLEND_ZERO;
4318 return D3D11_BLEND_ONE;
4320 return rgb ? D3D11_BLEND_SRC_COLOR : D3D11_BLEND_SRC_ALPHA;
4322 return rgb ? D3D11_BLEND_INV_SRC_COLOR : D3D11_BLEND_INV_SRC_ALPHA;
4324 return rgb ? D3D11_BLEND_DEST_COLOR : D3D11_BLEND_DEST_ALPHA;
4326 return rgb ? D3D11_BLEND_INV_DEST_COLOR : D3D11_BLEND_INV_DEST_ALPHA;
4328 return D3D11_BLEND_SRC_ALPHA;
4330 return D3D11_BLEND_INV_SRC_ALPHA;
4332 return D3D11_BLEND_DEST_ALPHA;
4334 return D3D11_BLEND_INV_DEST_ALPHA;
4337 return D3D11_BLEND_BLEND_FACTOR;
4340 return D3D11_BLEND_INV_BLEND_FACTOR;
4342 return D3D11_BLEND_SRC_ALPHA_SAT;
4344 return rgb ? D3D11_BLEND_SRC1_COLOR : D3D11_BLEND_SRC1_ALPHA;
4346 return rgb ? D3D11_BLEND_INV_SRC1_COLOR : D3D11_BLEND_INV_SRC1_ALPHA;
4348 return D3D11_BLEND_SRC1_ALPHA;
4350 return D3D11_BLEND_INV_SRC1_ALPHA;
4353 return D3D11_BLEND_ZERO;
4361 return D3D11_BLEND_OP_ADD;
4363 return D3D11_BLEND_OP_SUBTRACT;
4365 return D3D11_BLEND_OP_REV_SUBTRACT;
4367 return D3D11_BLEND_OP_MIN;
4369 return D3D11_BLEND_OP_MAX;
4372 return D3D11_BLEND_OP_ADD;
4380 keyBuilder.addData(
source);
4381 return keyBuilder.result().toHex();
4389 if (!dxbc.shader().isEmpty()) {
4391 *usedShaderKey =
key;
4392 return dxbc.shader();
4397 if (hlslSource.shader().isEmpty()) {
4398 qWarning() <<
"No HLSL (shader model 5.0) code found in baked shader" <<
shader;
4403 *usedShaderKey =
key;
4406 switch (
shader.stage()) {
4434 cacheKey.entryPoint = hlslSource.entryPoint();
4438 return cacheIt.value();
4442 if (d3dCompile ==
nullptr) {
4443 qWarning(
"Unable to resolve function D3DCompile()");
4447 ID3DBlob *bytecode =
nullptr;
4448 ID3DBlob *errors =
nullptr;
4449 HRESULT hr = d3dCompile(hlslSource.shader().constData(), SIZE_T(hlslSource.shader().size()),
4450 nullptr,
nullptr,
nullptr,
4451 hlslSource.entryPoint().constData(),
target,
flags, 0, &bytecode, &errors);
4452 if (FAILED(hr) || !bytecode) {
4453 qWarning(
"HLSL shader compilation failed: 0x%x",
uint(hr));
4456 int(errors->GetBufferSize()));
4463 result.resize(
int(bytecode->GetBufferSize()));
4464 memcpy(
result.data(), bytecode->GetBufferPointer(),
size_t(
result.size()));
4465 bytecode->Release();
4479 rhiD->pipelineCreationStart();
4480 if (!rhiD->sanityCheckGraphicsPipeline(
this))
4483 D3D11_RASTERIZER_DESC rastDesc = {};
4489 rastDesc.DepthClipEnable =
true;
4491 rastDesc.MultisampleEnable = rhiD->effectiveSampleDesc(
m_sampleCount).Count > 1;
4494 qWarning(
"Failed to create rasterizer state: %s",
4495 qPrintable(QSystemError::windowsComString(hr)));
4499 D3D11_DEPTH_STENCIL_DESC dsDesc = {};
4501 dsDesc.DepthWriteMask =
m_depthWrite ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
4516 hr = rhiD->dev->CreateDepthStencilState(&dsDesc, &
dsState);
4518 qWarning(
"Failed to create depth-stencil state: %s",
4519 qPrintable(QSystemError::windowsComString(hr)));
4523 D3D11_BLEND_DESC blendDesc = {};
4527 D3D11_RENDER_TARGET_BLEND_DESC blend = {};
4528 blend.BlendEnable =
b.enable;
4536 blendDesc.RenderTarget[
i] = blend;
4539 D3D11_RENDER_TARGET_BLEND_DESC blend = {};
4540 blend.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4541 blendDesc.RenderTarget[0] = blend;
4543 hr = rhiD->dev->CreateBlendState(&blendDesc, &
blendState);
4545 qWarning(
"Failed to create blend state: %s",
4546 qPrintable(QSystemError::windowsComString(hr)));
4552 auto cacheIt = rhiD->m_shaderCache.constFind(shaderStage);
4553 if (cacheIt != rhiD->m_shaderCache.constEnd()) {
4554 switch (shaderStage.type()) {
4556 vs.shader =
static_cast<ID3D11VertexShader *
>(cacheIt->s);
4557 vs.shader->AddRef();
4558 vsByteCode = cacheIt->bytecode;
4559 vs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4562 hs.shader =
static_cast<ID3D11HullShader *
>(cacheIt->s);
4563 hs.shader->AddRef();
4564 hs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4567 ds.shader =
static_cast<ID3D11DomainShader *
>(cacheIt->s);
4568 ds.shader->AddRef();
4569 ds.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4572 gs.shader =
static_cast<ID3D11GeometryShader *
>(cacheIt->s);
4573 gs.shader->AddRef();
4574 gs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4577 fs.shader =
static_cast<ID3D11PixelShader *
>(cacheIt->s);
4578 fs.shader->AddRef();
4579 fs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4587 UINT compileFlags = 0;
4589 compileFlags |= D3DCOMPILE_DEBUG;
4591 const QByteArray bytecode = rhiD->compileHlslShaderSource(shaderStage.shader(), shaderStage.shaderVariant(), compileFlags,
4592 &
error, &shaderKey);
4600 rhiD->clearShaderCache();
4603 switch (shaderStage.type()) {
4605 hr = rhiD->dev->CreateVertexShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
vs.shader);
4607 qWarning(
"Failed to create vertex shader: %s",
4608 qPrintable(QSystemError::windowsComString(hr)));
4611 vsByteCode = bytecode;
4612 vs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4613 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
vs.shader, bytecode,
vs.nativeResourceBindingMap));
4614 vs.shader->AddRef();
4617 hr = rhiD->dev->CreateHullShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
hs.shader);
4619 qWarning(
"Failed to create hull shader: %s",
4620 qPrintable(QSystemError::windowsComString(hr)));
4623 hs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4624 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
hs.shader, bytecode,
hs.nativeResourceBindingMap));
4625 hs.shader->AddRef();
4628 hr = rhiD->dev->CreateDomainShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
ds.shader);
4630 qWarning(
"Failed to create domain shader: %s",
4631 qPrintable(QSystemError::windowsComString(hr)));
4634 ds.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4635 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
ds.shader, bytecode,
ds.nativeResourceBindingMap));
4636 ds.shader->AddRef();
4639 hr = rhiD->dev->CreateGeometryShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
gs.shader);
4641 qWarning(
"Failed to create geometry shader: %s",
4642 qPrintable(QSystemError::windowsComString(hr)));
4645 gs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4646 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
gs.shader, bytecode,
gs.nativeResourceBindingMap));
4647 gs.shader->AddRef();
4650 hr = rhiD->dev->CreatePixelShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
fs.shader);
4652 qWarning(
"Failed to create pixel shader: %s",
4653 qPrintable(QSystemError::windowsComString(hr)));
4656 fs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
4657 rhiD->m_shaderCache.insert(shaderStage,
QRhiD3D11::Shader(
fs.shader, bytecode,
fs.nativeResourceBindingMap));
4658 fs.shader->AddRef();
4668 if (!vsByteCode.isEmpty()) {
4670 QVarLengthArray<D3D11_INPUT_ELEMENT_DESC, 4> inputDescs;
4674 D3D11_INPUT_ELEMENT_DESC desc = {};
4679 const int matrixSlice =
it->matrixSlice();
4680 if (matrixSlice < 0) {
4681 desc.SemanticName =
"TEXCOORD";
4682 desc.SemanticIndex = UINT(
it->location());
4687 matrixSliceSemantics.append(
sem);
4688 desc.SemanticName = matrixSliceSemantics.last().constData();
4689 desc.SemanticIndex = UINT(matrixSlice);
4692 desc.InputSlot = UINT(
it->binding());
4693 desc.AlignedByteOffset =
it->offset();
4696 desc.InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
4697 desc.InstanceDataStepRate = inputBinding->instanceStepRate();
4699 desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
4701 inputDescs.append(desc);
4703 if (!inputDescs.isEmpty()) {
4704 hr = rhiD->dev->CreateInputLayout(inputDescs.constData(), UINT(inputDescs.count()),
4705 vsByteCode, SIZE_T(vsByteCode.size()), &
inputLayout);
4707 qWarning(
"Failed to create input layout: %s",
4708 qPrintable(QSystemError::windowsComString(hr)));
4714 rhiD->pipelineCreationEnd();
4716 rhiD->registerResource(
this);
4735 cs.shader->Release();
4736 cs.shader =
nullptr;
4737 cs.nativeResourceBindingMap.clear();
4741 rhiD->unregisterResource(
this);
4750 rhiD->pipelineCreationStart();
4752 auto cacheIt = rhiD->m_shaderCache.constFind(
m_shaderStage);
4753 if (cacheIt != rhiD->m_shaderCache.constEnd()) {
4754 cs.shader =
static_cast<ID3D11ComputeShader *
>(cacheIt->s);
4755 cs.nativeResourceBindingMap = cacheIt->nativeResourceBindingMap;
4759 UINT compileFlags = 0;
4761 compileFlags |= D3DCOMPILE_DEBUG;
4764 &
error, &shaderKey);
4770 HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.
constData(), SIZE_T(bytecode.
size()),
nullptr, &
cs.shader);
4772 qWarning(
"Failed to create compute shader: %s",
4773 qPrintable(QSystemError::windowsComString(hr)));
4780 rhiD->clearShaderCache();
4785 cs.shader->AddRef();
4787 rhiD->pipelineCreationEnd();
4789 rhiD->registerResource(
this);
4814 D3D11_QUERY_DESC queryDesc = {};
4817 queryDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4820 qWarning(
"Failed to create timestamp disjoint query: %s",
4821 qPrintable(QSystemError::windowsComString(hr)));
4825 queryDesc.Query = D3D11_QUERY_TIMESTAMP;
4826 for (
int j = 0;
j < 2; ++
j) {
4827 const int idx = 2 *
i +
j;
4829 HRESULT hr = rhiD->dev->CreateQuery(&queryDesc, &
query[idx]);
4831 qWarning(
"Failed to create timestamp query: %s",
4832 qPrintable(QSystemError::windowsComString(hr)));
4849 for (
int j = 0;
j < 2; ++
j) {
4852 query[idx]->Release();
4853 query[idx] =
nullptr;
4866 ID3D11Query *tsStart =
query[pairIndex * 2];
4867 ID3D11Query *tsEnd =
query[pairIndex * 2 + 1];
4869 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT dj;
4872 ok &=
context->GetData(tsDisjoint, &dj,
sizeof(dj), D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_OK;
4873 ok &=
context->GetData(tsEnd, ×tamps[1],
sizeof(
quint64), D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_OK;
4874 ok &=
context->GetData(tsStart, ×tamps[0],
sizeof(
quint64), D3D11_ASYNC_GETDATA_DONOTFLUSH) == S_OK;
4877 if (!dj.Disjoint && dj.Frequency) {
4878 const float elapsedMs = (timestamps[1] - timestamps[0]) /
float(dj.Frequency) * 1000.0f;
4879 *elapsedSec = elapsedMs / 1000.0;
4882 active[pairIndex] =
false;
4954 rhiD->unregisterResource(
this);
4957 rhiD->context->Flush();
4988 qWarning(
"Attempted to call isFormatSupported() without a window set");
4993 DXGI_OUTPUT_DESC1 desc1;
4995 if (desc1.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020)
5008 DXGI_OUTPUT_DESC1 hdrOutputDesc;
5011 info.limits.luminanceInNits.minLuminance = hdrOutputDesc.MinLuminance;
5012 info.limits.luminanceInNits.maxLuminance = hdrOutputDesc.MaxLuminance;
5024 rhiD->registerResource(rpD,
false);
5029 ID3D11Texture2D **tex, ID3D11RenderTargetView **rtv)
const
5031 D3D11_TEXTURE2D_DESC desc = {};
5032 desc.Width = UINT(
size.width());
5033 desc.Height = UINT(
size.height());
5038 desc.Usage = D3D11_USAGE_DEFAULT;
5039 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5042 HRESULT hr = rhiD->dev->CreateTexture2D(&desc,
nullptr, tex);
5044 qWarning(
"Failed to create color buffer texture: %s",
5045 qPrintable(QSystemError::windowsComString(hr)));
5049 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
5051 rtvDesc.ViewDimension =
sampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D;
5052 hr = rhiD->dev->CreateRenderTargetView(*tex, &rtvDesc, rtv);
5054 qWarning(
"Failed to create color buffer rtv: %s",
5055 qPrintable(QSystemError::windowsComString(hr)));
5069 qCDebug(QRHI_LOG_INFO,
"Creating Direct Composition device (needed for semi-transparent windows)");
5097 HWND hwnd =
reinterpret_cast<HWND
>(
window->winId());
5103 if (!rhiD->useLegacySwapchainModel && rhiD->ensureDirectCompositionDevice()) {
5105 hr = rhiD->dcompDevice->CreateTargetForHwnd(hwnd,
false, &
dcompTarget);
5107 qWarning(
"Failed to create Direct Compsition target for the window: %s",
5108 qPrintable(QSystemError::windowsComString(hr)));
5112 hr = rhiD->dcompDevice->CreateVisual(&
dcompVisual);
5114 qWarning(
"Failed to create DirectComposition visual: %s",
5115 qPrintable(QSystemError::windowsComString(hr)));
5121 qWarning(
"Swapchain says surface has alpha but the window has no alphaBufferSize set. "
5122 "This may lead to problems.");
5140 DXGI_COLOR_SPACE_TYPE hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;
5141 DXGI_OUTPUT_DESC1 hdrOutputDesc;
5144 if (hdrOutputDesc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) {
5148 hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709;
5153 hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020;
5163 qWarning(
"The output associated with the window is not HDR capable "
5164 "(or Use HDR is Off in the Display Settings), ignoring HDR format request");
5174 DXGI_SWAP_CHAIN_DESC1 desc = {};
5178 desc.SampleDesc.Count = 1;
5179 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
5182 desc.Scaling = rhiD->useLegacySwapchainModel ? DXGI_SCALING_STRETCH : DXGI_SCALING_NONE;
5183 desc.SwapEffect = rhiD->useLegacySwapchainModel ? DXGI_SWAP_EFFECT_DISCARD : DXGI_SWAP_EFFECT_FLIP_DISCARD;
5184 desc.Stereo = stereo;
5190 desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
5195 desc.Scaling = DXGI_SCALING_STRETCH;
5198 IDXGIFactory2 *fac =
static_cast<IDXGIFactory2 *
>(rhiD->dxgiFactory);
5199 IDXGISwapChain1 *sc1;
5202 hr = fac->CreateSwapChainForComposition(rhiD->dev, &desc,
nullptr, &sc1);
5204 hr = fac->CreateSwapChainForHwnd(rhiD->dev, hwnd, &desc,
nullptr,
nullptr, &sc1);
5213 hr = fac->CreateSwapChainForComposition(rhiD->dev, &desc,
nullptr, &sc1);
5215 hr = fac->CreateSwapChainForHwnd(rhiD->dev, hwnd, &desc,
nullptr,
nullptr, &sc1);
5218 if (SUCCEEDED(hr)) {
5221 IDXGISwapChain3 *sc3 =
nullptr;
5222 if (SUCCEEDED(sc1->QueryInterface(__uuidof(IDXGISwapChain3),
reinterpret_cast<void **
>(&sc3)))) {
5223 hr = sc3->SetColorSpace1(hdrColorSpace);
5225 qWarning(
"Failed to set color space on swapchain: %s",
5226 qPrintable(QSystemError::windowsComString(hr)));
5229 qWarning(
"IDXGISwapChain3 not available, HDR swapchain will not work as expected");
5234 if (SUCCEEDED(hr)) {
5237 qWarning(
"Failed to associate Direct Composition visual with the target: %s",
5238 qPrintable(QSystemError::windowsComString(hr)));
5241 qWarning(
"Failed to set content for Direct Composition visual: %s",
5242 qPrintable(QSystemError::windowsComString(hr)));
5246 rhiD->dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_WINDOW_CHANGES);
5250 qWarning(
"Failed to create D3D11 swapchain: %s"
5251 " (Width=%u Height=%u Format=%u SampleCount=%u BufferCount=%u Scaling=%u SwapEffect=%u Stereo=%u)",
5252 qPrintable(QSystemError::windowsComString(hr)),
5253 desc.Width, desc.Height, UINT(desc.Format), desc.SampleDesc.Count,
5254 desc.BufferCount, UINT(desc.Scaling), UINT(desc.SwapEffect), UINT(desc.Stereo));
5262 if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) {
5263 qWarning(
"Device loss detected in ResizeBuffers()");
5264 rhiD->deviceLost =
true;
5266 }
else if (FAILED(hr)) {
5267 qWarning(
"Failed to resize D3D11 swapchain: %s",
5268 qPrintable(QSystemError::windowsComString(hr)));
5289 qWarning(
"Failed to query swapchain backbuffer: %s",
5290 qPrintable(QSystemError::windowsComString(hr)));
5293 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
5295 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
5298 qWarning(
"Failed to create rtv for swapchain backbuffer: %s",
5299 qPrintable(QSystemError::windowsComString(hr)));
5305 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
5306 rtvDesc.Texture2DArray.FirstArraySlice = 1;
5307 rtvDesc.Texture2DArray.ArraySize = 1;
5310 qWarning(
"Failed to create rtv for swapchain backbuffer (right eye): %s",
5311 qPrintable(QSystemError::windowsComString(hr)));
5325 qWarning(
"Depth-stencil buffer's sampleCount (%d) does not match color buffers' sample count (%d). Expect problems.",
5332 qWarning(
"Failed to rebuild swapchain's associated depth-stencil buffer for size %dx%d",
5335 qWarning(
"Depth-stencil buffer's size (%dx%d) does not match the surface size (%dx%d). Expect problems.",
5349 rtD->d.dpr = float(
window->devicePixelRatio());
5351 rtD->d.colorAttCount = 1;
5358 rtD->d.dpr = float(
window->devicePixelRatio());
5360 rtD->d.colorAttCount = 1;
5363 rtD->d.dsv =
ds ?
ds->
dsv :
nullptr;
5371 if (needsRegistration)
5372 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,...)
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