diff options
author | Nicolas Guichard <nicolas.guichard@kdab.com> | 2020-07-16 15:25:41 +0200 |
---|---|---|
committer | Nicolas Guichard <nicolas.guichard@kdab.com> | 2020-07-16 16:15:12 +0200 |
commit | 13067bf7313e2e0e9c16e952bc97dd8854695967 (patch) | |
tree | e1ae00eae71d4e169ec326c2a680a80ecfff8a34 | |
parent | 81d4c607660dd1eb116ada95b5878fd51531442c (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.
Pick-to: 5.15
Change-Id: Ia32ee169718d98e7197d7bfa19ca23e6e243dc25
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp | 19 | ||||
-rw-r--r-- | tests/manual/rhi/main.cpp | 8 |
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 ef308588f..276d71348 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp @@ -1530,7 +1530,7 @@ void preprocessRHIShader(std::vector<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(); @@ -1565,27 +1565,32 @@ void preprocessRHIShader(std::vector<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 bca544a20..123647ac1 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; |