426void QSSGRhiShaderPipeline::addStage(
const QRhiShaderStage &stage, StageFlags flags)
428 m_stages.append(stage);
432 if (stage.type() == QRhiShaderStage::Vertex || stage.type() == QRhiShaderStage::Compute) {
437 const QVector<QShaderDescription::UniformBlock> uniformBlocks = stage.shader().description().uniformBlocks();
438 for (
const QShaderDescription::UniformBlock &blk : uniformBlocks) {
439 if (blk.binding == 0) {
440 m_ub0Size = blk.size;
441 m_ub0NextUBufOffset = m_context.rhi()->ubufAligned(m_ub0Size);
442 for (
const QShaderDescription::BlockVariable &var : blk.members)
443 m_ub0[var.name] = var;
448 if (!flags.testFlag(UsedWithoutIa)) {
449 const QVector<QShaderDescription::InOutVariable> inputs = stage.shader().description().inputVariables();
450 for (
const QShaderDescription::InOutVariable &var : inputs) {
451 if (var.name == QSSGMesh::MeshInternal::getPositionAttrName()) {
452 m_vertexInputs[QSSGRhiInputAssemblerState::PositionSemantic] = var;
453 }
else if (var.name == QSSGMesh::MeshInternal::getNormalAttrName()) {
454 m_vertexInputs[QSSGRhiInputAssemblerState::NormalSemantic] = var;
455 }
else if (var.name == QSSGMesh::MeshInternal::getUV0AttrName()) {
456 m_vertexInputs[QSSGRhiInputAssemblerState::TexCoord0Semantic] = var;
457 }
else if (var.name == QSSGMesh::MeshInternal::getUV1AttrName()) {
458 m_vertexInputs[QSSGRhiInputAssemblerState::TexCoord1Semantic] = var;
459 }
else if (var.name == QSSGMesh::MeshInternal::getLightmapUVAttrName()) {
460 m_vertexInputs[QSSGRhiInputAssemblerState::TexCoordLightmapSemantic] = var;
461 }
else if (var.name == QSSGMesh::MeshInternal::getTexTanAttrName()) {
462 m_vertexInputs[QSSGRhiInputAssemblerState::TangentSemantic] = var;
463 }
else if (var.name == QSSGMesh::MeshInternal::getTexBinormalAttrName()) {
464 m_vertexInputs[QSSGRhiInputAssemblerState::BinormalSemantic] = var;
465 }
else if (var.name == QSSGMesh::MeshInternal::getColorAttrName()) {
466 m_vertexInputs[QSSGRhiInputAssemblerState::ColorSemantic] = var;
467 }
else if (var.name == QSSGMesh::MeshInternal::getJointAttrName()) {
468 m_vertexInputs[QSSGRhiInputAssemblerState::JointSemantic] = var;
469 }
else if (var.name == QSSGMesh::MeshInternal::getWeightAttrName()) {
470 m_vertexInputs[QSSGRhiInputAssemblerState::WeightSemantic] = var;
471 }
else if (var.name ==
"qt_instanceTransform0") {
472 instanceLocations.transform0 = var.location;
473 }
else if (var.name ==
"qt_instanceTransform1") {
474 instanceLocations.transform1 = var.location;
475 }
else if (var.name ==
"qt_instanceTransform2") {
476 instanceLocations.transform2 = var.location;
477 }
else if (var.name ==
"qt_instanceColor") {
478 instanceLocations.color = var.location;
479 }
else if (var.name ==
"qt_instanceData") {
480 instanceLocations.data = var.location;
481 }
else if (var.name ==
"qt_instanceIndex") {
482 instanceLocations.index = var.location;
484 qWarning(
"Ignoring vertex input %s in shader", var.name.constData());
489 const QVector<QShaderDescription::StorageBlock> storageBlocks = stage.shader().description().storageBlocks();
490 for (
const QShaderDescription::StorageBlock &blk : storageBlocks) {
492 m_storageBuffers[blk.blockName] = blk;
495 const QVector<QShaderDescription::InOutVariable> combinedImageSamplers = stage.shader().description().combinedImageSamplers();
496 for (
const QShaderDescription::InOutVariable &var : combinedImageSamplers)
497 m_combinedImageSamplers[var.name] = var;
499 const QVector<QShaderDescription::InOutVariable> storageImages = stage.shader().description().storageImages() + stage.shader().description().separateImages();
500 for (
const QShaderDescription::InOutVariable &var : storageImages)
501 m_storageImages[var.name] = var;
503 std::fill(m_materialImageSamplerBindings,
504 m_materialImageSamplerBindings + size_t(QSSGRhiSamplerBindingHints::BindingMapSize),
549void QSSGRhiShaderPipeline::setUniformValue(
char *ubufData,
const char *name,
const QVariant &inValue, QSSGRenderShaderValue::Type inType)
551 using namespace QSSGRenderShaderValue;
553 case QSSGRenderShaderValue::Integer:
555 const qint32 v = inValue.toInt();
556 setUniform(ubufData, name, &v,
sizeof(qint32));
559 case QSSGRenderShaderValue::IntegerVec2:
561 const ivec2 v = inValue.value<ivec2>();
562 setUniform(ubufData, name, &v, 2 *
sizeof(qint32));
565 case QSSGRenderShaderValue::IntegerVec3:
567 const ivec3 v = inValue.value<ivec3>();
568 setUniform(ubufData, name, &v, 3 *
sizeof(qint32));
571 case QSSGRenderShaderValue::IntegerVec4:
573 const ivec4 v = inValue.value<ivec4>();
574 setUniform(ubufData, name, &v, 4 *
sizeof(qint32));
577 case QSSGRenderShaderValue::Boolean:
580 const qint32 v = inValue.value<
bool>();
581 setUniform(ubufData, name, &v,
sizeof(qint32));
584 case QSSGRenderShaderValue::BooleanVec2:
586 const bvec2 b = inValue.value<bvec2>();
587 const ivec2 v(b.x, b.y);
588 setUniform(ubufData, name, &v, 2 *
sizeof(qint32));
591 case QSSGRenderShaderValue::BooleanVec3:
593 const bvec3 b = inValue.value<bvec3>();
594 const ivec3 v(b.x, b.y, b.z);
595 setUniform(ubufData, name, &v, 3 *
sizeof(qint32));
598 case QSSGRenderShaderValue::BooleanVec4:
600 const bvec4 b = inValue.value<bvec4>();
601 const ivec4 v(b.x, b.y, b.z, b.w);
602 setUniform(ubufData, name, &v, 4 *
sizeof(qint32));
605 case QSSGRenderShaderValue::Float:
607 const float v = inValue.value<
float>();
608 setUniform(ubufData, name, &v,
sizeof(
float));
611 case QSSGRenderShaderValue::Vec2:
613 const QVector2D v = inValue.value<QVector2D>();
614 setUniform(ubufData, name, &v, 2 *
sizeof(
float));
617 case QSSGRenderShaderValue::Vec3:
619 const QVector3D v = inValue.value<QVector3D>();
620 setUniform(ubufData, name, &v, 3 *
sizeof(
float));
623 case QSSGRenderShaderValue::Vec4:
625 const QVector4D v = inValue.value<QVector4D>();
626 setUniform(ubufData, name, &v, 4 *
sizeof(
float));
629 case QSSGRenderShaderValue::Rgba:
631 const QVector4D v = QSSGUtils::color::sRGBToLinear(inValue.value<QColor>());
632 setUniform(ubufData, name, &v, 4 *
sizeof(
float));
635 case QSSGRenderShaderValue::UnsignedInteger:
637 const quint32 v = inValue.value<quint32>();
638 setUniform(ubufData, name, &v,
sizeof(quint32));
641 case QSSGRenderShaderValue::UnsignedIntegerVec2:
643 const uvec2 v = inValue.value<uvec2>();
644 setUniform(ubufData, name, &v, 2 *
sizeof(quint32));
647 case QSSGRenderShaderValue::UnsignedIntegerVec3:
649 const uvec3 v = inValue.value<uvec3>();
650 setUniform(ubufData, name, &v, 3 *
sizeof(quint32));
653 case QSSGRenderShaderValue::UnsignedIntegerVec4:
655 const uvec4 v = inValue.value<uvec4>();
656 setUniform(ubufData, name, &v, 4 *
sizeof(quint32));
659 case QSSGRenderShaderValue::Matrix3x3:
661 const QMatrix3x3 m = inValue.value<QMatrix3x3>();
662 setUniform(ubufData, name, m.constData(), 12 *
sizeof(
float),
nullptr, QSSGRhiShaderPipeline::UniformFlag::Mat3);
665 case QSSGRenderShaderValue::Matrix4x4:
667 const QMatrix4x4 v = inValue.value<QMatrix4x4>();
668 setUniform(ubufData, name, v.constData(), 16 *
sizeof(
float));
671 case QSSGRenderShaderValue::Size:
673 const QSize s = inValue.value<QSize>();
674 float v[2] = {
float(s.width()),
float(s.height()) };
675 setUniform(ubufData, name, v, 2 *
sizeof(
float));
678 case QSSGRenderShaderValue::SizeF:
680 const QSizeF s = inValue.value<QSizeF>();
681 float v[2] = {
float(s.width()),
float(s.height()) };
682 setUniform(ubufData, name, v, 2 *
sizeof(
float));
685 case QSSGRenderShaderValue::Point:
687 const QPoint p = inValue.value<QPoint>();
688 float v[2] = {
float(p.x()),
float(p.y()) };
689 setUniform(ubufData, name, v, 2 *
sizeof(
float));
692 case QSSGRenderShaderValue::PointF:
694 const QPointF p = inValue.value<QPointF>();
695 float v[2] = {
float(p.x()),
float(p.y()) };
696 setUniform(ubufData, name, v, 2 *
sizeof(
float));
699 case QSSGRenderShaderValue::Rect:
701 const QRect r = inValue.value<QRect>();
702 float v[4] = {
float(r.x()),
float(r.y()),
float(r.width()),
float(r.height()) };
703 setUniform(ubufData, name, v, 4 *
sizeof(
float));
706 case QSSGRenderShaderValue::RectF:
708 const QRectF r = inValue.value<QRectF>();
709 float v[4] = {
float(r.x()),
float(r.y()),
float(r.width()),
float(r.height()) };
710 setUniform(ubufData, name, v, 4 *
sizeof(
float));
713 case QSSGRenderShaderValue::Quaternion:
715 const QQuaternion q = inValue.value<QQuaternion>();
716 float v[4] = {
float(q.x()),
float(q.y()),
float(q.z()),
float(q.scalar()) };
717 setUniform(ubufData, name, v, 4 *
sizeof(
float));
721 qWarning(
"Attempted to set uniform %s value with unsupported data type %i",
802void QSSGRhiShaderPipeline::setUniformArray(
char *ubufData,
const char *name,
const void *data, size_t itemCount, QSSGRenderShaderValue::Type type,
int *storeIndex)
804 using namespace QSSGRenderShaderValue;
806 QSSGRhiShaderUniformArray *ua =
nullptr;
807 constexpr size_t std140BaseTypeSize = 4 *
sizeof(
float);
809 static const auto checkSize = [std140BaseTypeSize](QSSGRhiShaderUniformArray *ua) ->
bool {
810 Q_UNUSED(std140BaseTypeSize);
811 const size_t uniformSize = std140BaseTypeSize < ua->typeSize ? ua->typeSize * ua->itemCount : std140BaseTypeSize * ua->itemCount;
812 QSSG_ASSERT_X(uniformSize == ua->size, qPrintable(getUBMemberSizeWarning(QLatin1StringView(ua->name), uniformSize, ua->size)),
return false);
816 if (!storeIndex || *storeIndex == -1) {
818 const QByteArray ba = QByteArray::fromRawData(name, strlen(name));
819 auto it = m_uniformIndex.constFind(ba);
820 if (it != m_uniformIndex.cend()) {
822 ua = &m_uniformArrays[index];
823 }
else if (ba.size() < qsizetype(
sizeof(QSSGRhiShaderUniformArray::name))) {
824 index = m_uniformArrays.size();
825 m_uniformArrays.push_back(QSSGRhiShaderUniformArray());
826 m_uniformIndex[name] = index;
827 ua = &m_uniformArrays.last();
828 memcpy(ua->name, name, ba.size() + 1);
830 qWarning(
"Attempted to set uniform array with too long name: %s", name);
836 ua = &m_uniformArrays[*storeIndex];
842 if (ua->offset == SIZE_MAX && ua->maybeExists) {
843 auto it = m_ub0.constFind(QByteArray::fromRawData(ua->name, strlen(ua->name)));
844 if (it != m_ub0.constEnd()) {
845 ua->offset = it->offset;
849 if (ua->offset == SIZE_MAX) {
851 ua->maybeExists =
false;
855 char *p = ubufData + ua->offset;
858 case QSSGRenderShaderValue::Integer:
860 const qint32 *v =
static_cast<
const qint32 *>(data);
861 if (
sizeof(qint32) != ua->typeSize || itemCount != ua->itemCount) {
862 ua->typeSize =
sizeof(qint32);
863 ua->itemCount = itemCount;
866 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
868 for (size_t i = 0; i < itemCount; ++i)
869 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
872 case QSSGRenderShaderValue::IntegerVec2:
874 const ivec2 *v =
static_cast<
const ivec2 *>(data);
875 if (2 *
sizeof(qint32) != ua->typeSize || itemCount != ua->itemCount) {
876 ua->typeSize = 2 *
sizeof(qint32);
877 ua->itemCount = itemCount;
880 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
882 for (size_t i = 0; i < itemCount; ++i)
883 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
886 case QSSGRenderShaderValue::IntegerVec3:
888 const QSSGRenderShaderValue::ivec3 *v =
static_cast<
const QSSGRenderShaderValue::ivec3 *>(data);
889 if (3 *
sizeof(qint32) != ua->typeSize || itemCount != ua->itemCount) {
890 ua->typeSize = 3 *
sizeof(qint32);
891 ua->itemCount = itemCount;
894 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
896 for (size_t i = 0; i < itemCount; ++i)
897 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
900 case QSSGRenderShaderValue::IntegerVec4:
902 const ivec4 *v =
static_cast<
const ivec4 *>(data);
903 if (4 *
sizeof(qint32) != ua->typeSize || itemCount != ua->itemCount) {
904 ua->typeSize = 4 *
sizeof(qint32);
905 ua->itemCount = itemCount;
908 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
910 memcpy(p, v, ua->typeSize * ua->itemCount);
913 case QSSGRenderShaderValue::Float:
915 const float *v =
static_cast<
const float *>(data);
916 if (
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
917 ua->typeSize =
sizeof(
float);
918 ua->itemCount = itemCount;
921 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
923 for (size_t i = 0; i < itemCount; ++i)
924 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
927 case QSSGRenderShaderValue::Vec2:
929 const QVector2D *v =
static_cast<
const QVector2D *>(data);
930 if (2 *
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
931 ua->typeSize = 2 *
sizeof(
float);
932 ua->itemCount = itemCount;
935 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
937 for (size_t i = 0; i < itemCount; ++i)
938 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
941 case QSSGRenderShaderValue::Vec3:
943 const QVector3D *v =
static_cast<
const QVector3D *>(data);
944 if (3 *
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
945 ua->typeSize = 3 *
sizeof(
float);
946 ua->itemCount = itemCount;
949 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
951 for (size_t i = 0; i < itemCount; ++i)
952 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
955 case QSSGRenderShaderValue::Vec4:
957 const QVector4D *v =
static_cast<
const QVector4D *>(data);
958 if (4 *
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
959 ua->typeSize = 4 *
sizeof(
float);
960 ua->itemCount = itemCount;
963 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
965 memcpy(p, v, ua->typeSize * ua->itemCount);
968 case QSSGRenderShaderValue::Rgba:
970 const QColor *v =
static_cast<
const QColor *>(data);
971 if (4 *
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
972 ua->typeSize = 4 *
sizeof(
float);
973 ua->itemCount = itemCount;
976 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
978 for (size_t i = 0; i < itemCount; ++i) {
979 const QVector4D vi = QSSGUtils::color::sRGBToLinear(v[i]);
980 memcpy(p + i * std140BaseTypeSize, &vi, ua->typeSize);
984 case QSSGRenderShaderValue::UnsignedInteger:
986 const quint32 *v =
static_cast<
const quint32 *>(data);
987 if (
sizeof(quint32) != ua->typeSize || itemCount != ua->itemCount) {
988 ua->typeSize =
sizeof(quint32);
989 ua->itemCount = itemCount;
992 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
994 for (size_t i = 0; i < itemCount; ++i)
995 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
998 case QSSGRenderShaderValue::UnsignedIntegerVec2:
1000 const uvec2 *v =
static_cast<
const uvec2 *>(data);
1001 if (2 *
sizeof(quint32) != ua->typeSize || itemCount != ua->itemCount) {
1002 ua->typeSize = 2 *
sizeof(quint32);
1003 ua->itemCount = itemCount;
1006 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
1008 for (size_t i = 0; i < itemCount; ++i)
1009 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
1012 case QSSGRenderShaderValue::UnsignedIntegerVec3:
1014 const uvec3 *v =
static_cast<
const uvec3 *>(data);
1015 if (3 *
sizeof(quint32) != ua->typeSize || itemCount != ua->itemCount) {
1016 ua->typeSize = 3 *
sizeof(quint32);
1017 ua->itemCount = itemCount;
1020 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
1022 for (size_t i = 0; i < itemCount; ++i)
1023 memcpy(p + i * std140BaseTypeSize, &v[i], ua->typeSize);
1026 case QSSGRenderShaderValue::UnsignedIntegerVec4:
1028 const uvec4 *v =
static_cast<
const uvec4 *>(data);
1029 if (4 *
sizeof(quint32) != ua->typeSize || itemCount != ua->itemCount) {
1030 ua->typeSize = 4 *
sizeof(quint32);
1031 ua->itemCount = itemCount;
1034 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
1036 memcpy(p, v, ua->typeSize * ua->itemCount);
1039 case QSSGRenderShaderValue::Matrix3x3:
1041 const QMatrix3x3 *v =
static_cast<
const QMatrix3x3 *>(data);
1042 if (12 *
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
1043 ua->typeSize = 12 *
sizeof(
float);
1044 ua->itemCount = itemCount;
1047 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
1049 for (uint i = 0; i < ua->itemCount; ++i) {
1050 memcpy(p + i * ua->typeSize, v[i].constData(), 3 *
sizeof(
float));
1051 memcpy(p + i * ua->typeSize + 4 *
sizeof(
float), v[i].constData() + 3, 3 *
sizeof(
float));
1052 memcpy(p + i * ua->typeSize + 8 *
sizeof(
float), v[i].constData() + 6, 3 *
sizeof(
float));
1056 case QSSGRenderShaderValue::Matrix4x4:
1058 const QMatrix4x4 *v =
static_cast<
const QMatrix4x4 *>(data);
1059 if (16 *
sizeof(
float) != ua->typeSize || itemCount != ua->itemCount) {
1060 ua->typeSize = 16 *
sizeof(
float);
1061 ua->itemCount = itemCount;
1064 QSSG_ASSERT(QSSG_DEBUG_COND(checkSize(ua)),
return);
1066 for (uint i = 0; i < ua->itemCount; ++i)
1067 memcpy(p + i * ua->typeSize, &v[i] , ua->typeSize);
1070 case QSSGRenderShaderValue::Boolean:
1071 case QSSGRenderShaderValue::BooleanVec2:
1072 case QSSGRenderShaderValue::BooleanVec3:
1073 case QSSGRenderShaderValue::BooleanVec4:
1074 case QSSGRenderShaderValue::Size:
1075 case QSSGRenderShaderValue::SizeF:
1076 case QSSGRenderShaderValue::Point:
1077 case QSSGRenderShaderValue::PointF:
1078 case QSSGRenderShaderValue::Rect:
1079 case QSSGRenderShaderValue::RectF:
1080 case QSSGRenderShaderValue::Quaternion:
1082 qWarning(
"Attempted to set uniform %s value with type %d that is unsupported for uniform arrays",
1149void QSSGRhiShaderPipeline::setShaderResources(
char *ubufData,
1150 QSSGBufferManager &theBufferManager,
1151 const QByteArray &inPropertyName,
1152 const QVariant &propertyValue,
1153 QSSGRenderShaderValue::Type inPropertyType)
1155 if (inPropertyType == QSSGRenderShaderValue::Texture) {
1156 QSSGRenderImage *image = propertyValue.value<QSSGRenderImage *>();
1158 const QSSGRenderImageTexture texture = theBufferManager.loadRenderImage(image);
1159 if (texture.m_texture) {
1160 const QSSGRhiTexture t = {
1163 { QSSGRhiHelpers::toRhi(image->m_minFilterType),
1164 QSSGRhiHelpers::toRhi(image->m_magFilterType),
1165 image->m_mipFilterType != QSSGRenderTextureFilterOp::None ? QSSGRhiHelpers::toRhi(image->m_mipFilterType) : QRhiSampler::None,
1166 QSSGRhiHelpers::toRhi(image->m_horizontalTilingMode),
1167 QSSGRhiHelpers::toRhi(image->m_verticalTilingMode),
1168 QSSGRhiHelpers::toRhi(image->m_depthTilingMode)
1174 }
else if (inPropertyType == QSSGRenderShaderValue::StorageBuffer) {
1175 int binding = bindingForStorageBuffer(inPropertyName);
1177 const QSSGShaderBuffer buffer(propertyValue.value<QSSGShaderBuffer>());
1178 QRhiBuffer *rhiBuf = buffer.buffer ? theBufferManager.loadBuffer(*buffer.buffer) :
nullptr;
1180 if (buffer.qualifiers.testFlag(QSSGMemoryQualifier::Readonly))
1181 addStorageBufferBinding(inPropertyName, QRhiShaderResourceBinding::BufferLoad, rhiBuf, binding);
1182 else if (buffer.qualifiers.testFlag(QSSGMemoryQualifier::Writeonly))
1183 addStorageBufferBinding(inPropertyName, QRhiShaderResourceBinding::BufferStore, rhiBuf, binding);
1185 addStorageBufferBinding(inPropertyName, QRhiShaderResourceBinding::BufferLoadStore, rhiBuf, binding);
1187 qWarning() <<
"Buffer binding failed: " << inPropertyName;
1190 }
else if (inPropertyType == QSSGRenderShaderValue::Image) {
1191 int binding = bindingForStorageImage(inPropertyName);
1193 const QSSGShaderImage image(propertyValue.value<QSSGShaderImage>());
1194 const QSSGRenderImageTexture texture = image.image ? theBufferManager.loadRenderImage(image.image) : QSSGRenderImageTexture();
1195 if (texture.m_texture) {
1196 if (image.imageType.contains(
"Cube") && !(texture.m_texture->flags() & QRhiTexture::CubeMap)) {
1197 qWarning() <<
"Image type is not CubeMap: " << inPropertyName;
1200 if (image.qualifiers.testFlag(QSSGMemoryQualifier::Readonly))
1201 addStorageImageBinding(inPropertyName, QRhiShaderResourceBinding::ImageLoad, texture.m_texture, binding);
1202 else if (image.qualifiers.testFlag(QSSGMemoryQualifier::Writeonly))
1203 addStorageImageBinding(inPropertyName, QRhiShaderResourceBinding::ImageStore, texture.m_texture, binding);
1205 addStorageImageBinding(inPropertyName, QRhiShaderResourceBinding::ImageLoadStore, texture.m_texture, binding);
1207 qWarning() <<
"Image binding failed: " << inPropertyName;
1211 setUniformValue(ubufData, inPropertyName, propertyValue, inPropertyType);
2122QRhiGraphicsPipeline *QSSGRhiContextPrivate::pipeline(
const QSSGGraphicsPipelineStateKey &key,
2123 QRhiRenderPassDescriptor *rpDesc,
2124 QRhiShaderResourceBindings *srb)
2126 auto it = m_pipelines.constFind(key);
2127 if (it != m_pipelines.constEnd())
2131 QRhiGraphicsPipeline *ps = m_rhi->newGraphicsPipeline();
2132 const auto &ia = QSSGRhiInputAssemblerStatePrivate::get(key.state);
2134 const auto *shaderPipeline = QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(key.state);
2135 ps->setShaderStages(shaderPipeline->cbeginStages(), shaderPipeline->cendStages());
2136 ps->setVertexInputLayout(ia.inputLayout);
2137 ps->setShaderResourceBindings(srb);
2138 ps->setRenderPassDescriptor(rpDesc);
2140 QRhiGraphicsPipeline::Flags flags;
2141 if (key.state.flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::UsesScissor))
2142 flags |= QRhiGraphicsPipeline::UsesScissor;
2144 static const bool shaderDebugInfo = qEnvironmentVariableIntValue(
"QT_QUICK3D_SHADER_DEBUG_INFO");
2145 if (shaderDebugInfo)
2146 flags |= QRhiGraphicsPipeline::CompileShadersWithDebugInfo;
2147 ps->setFlags(flags);
2149 ps->setTopology(ia.topology);
2150 ps->setCullMode(key.state.cullMode);
2151 if (ia.topology == QRhiGraphicsPipeline::Lines || ia.topology == QRhiGraphicsPipeline::LineStrip)
2152 ps->setLineWidth(key.state.lineWidth);
2154 const bool blendEnabled = key.state.flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::BlendEnabled);
2155 QVarLengthArray<QRhiGraphicsPipeline::TargetBlend, 8> targetBlends(key.state.colorAttachmentCount);
2156 for (
int i = 0; i < key.state.colorAttachmentCount; ++i) {
2157 targetBlends[i] = key.state.targetBlend[i];
2158 targetBlends[i].enable = blendEnabled;
2160 ps->setTargetBlends(targetBlends.cbegin(), targetBlends.cend());
2162 ps->setSampleCount(key.state.samples);
2163 ps->setMultiViewCount(key.state.viewCount);
2165 ps->setDepthTest(key.state.flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled));
2166 ps->setDepthWrite(key.state.flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled));
2167 ps->setDepthOp(key.state.depthFunc);
2169 ps->setDepthBias(key.state.depthBias);
2170 ps->setSlopeScaledDepthBias(key.state.slopeScaledDepthBias);
2171 ps->setPolygonMode(key.state.polygonMode);
2173 const bool usesStencilRef = (key.state.flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::UsesStencilRef));
2175 flags |= QRhiGraphicsPipeline::UsesStencilRef;
2176 ps->setFlags(flags);
2177 ps->setStencilFront(key.state.stencilOpFrontState);
2178 ps->setStencilTest(usesStencilRef);
2179 ps->setStencilWriteMask(key.state.stencilWriteMask);
2181 if (!ps->create()) {
2182 qWarning(
"Failed to build graphics pipeline state");
2187 m_pipelines.insert(key, ps);