summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Guichard <nicolas.guichard@kdab.com>2020-07-16 15:25:41 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-07-16 17:04:38 +0000
commit923c00c21a78dca999bf66ec3ea2888de9beee85 (patch)
tree71acd3af379062f6a01fb7a7fc173816bb9dcbb0
parenta622e52d29146fe229928d398ebb50373279ae15 (diff)
rhi: fix SubmissionContext::loadShader for Unicode files
QRegularExpression::match takes a QString and not a QByteArray, so QRegularExpressionMatch::capturedStart is not reliable to locate bytes in a QByteArray which might contain Unicode data. This fixes the issue by explicitly working on QStrings. Change-Id: Ia32ee169718d98e7197d7bfa19ca23e6e243dc25 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> (cherry picked from commit 13067bf7313e2e0e9c16e952bc97dd8854695967) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp19
-rw-r--r--tests/manual/rhi/main.cpp8
2 files changed, 20 insertions, 7 deletions
diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
index 5b217929c..1eefe645f 100644
--- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
+++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
@@ -1679,7 +1679,7 @@ void preprocessRHIShader(QVector<QByteArray> &shaderCodes)
"\\s*,\\s*std140.*)\\)\\s*uniform\\s*([a-zA-Z0-9_]+)"));
auto replaceBinding = [&bindings, &assignedBindings](
- int &offset, QRegularExpressionMatch &match, QByteArray &code,
+ int &offset, QRegularExpressionMatch &match, QString &code,
int indexCapture, int variableCapture) noexcept {
int index = match.captured(indexCapture).toInt();
QByteArray variable = match.captured(variableCapture).toUtf8();
@@ -1714,27 +1714,32 @@ void preprocessRHIShader(QVector<QByteArray> &shaderCodes)
};
for (QByteArray &shaderCode : shaderCodes) {
+ // Since QRegularExpression::match takes a QString anyway, convert once beforehand
+ QString shaderString = shaderCode;
+
// Regex for the sampler variables
int offset = 0;
- auto match = samplerRegex.match(shaderCode, offset);
+ auto match = samplerRegex.match(shaderString, offset);
while (match.hasMatch()) {
const int indexCapture = 1;
const int variableCapture = 2;
- replaceBinding(offset, match, shaderCode, indexCapture, variableCapture);
+ replaceBinding(offset, match, shaderString, indexCapture, variableCapture);
- match = samplerRegex.match(shaderCode, offset);
+ match = samplerRegex.match(shaderString, offset);
}
// Regex for the UBOs
offset = 0;
- match = uboRegex.match(shaderCode, offset);
+ match = uboRegex.match(shaderString, offset);
while (match.hasMatch()) {
const int indexCapture = !match.capturedView(1).isEmpty() ? 1 : 2;
const int variableCapture = 3;
- replaceBinding(offset, match, shaderCode, indexCapture, variableCapture);
+ replaceBinding(offset, match, shaderString, indexCapture, variableCapture);
- match = uboRegex.match(shaderCode, offset);
+ match = uboRegex.match(shaderString, offset);
}
+
+ shaderCode = shaderString.toUtf8();
}
}
diff --git a/tests/manual/rhi/main.cpp b/tests/manual/rhi/main.cpp
index f80ccc1c8..b5c89895c 100644
--- a/tests/manual/rhi/main.cpp
+++ b/tests/manual/rhi/main.cpp
@@ -98,6 +98,10 @@
static const constexpr auto vertex_shader = R"_(#version 450
+/**
+ * Unicode comment: Ѧ𝙱ƇᗞΣ
+ */
+
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexColor;
layout(location = 0) out vec3 color;
@@ -136,6 +140,10 @@ void main()
static const constexpr auto fragment_shader = R"_(#version 450
+/**
+ * Unicode comment: Ѧ𝙱ƇᗞΣ
+ */
+
layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec3 color;