summaryrefslogtreecommitdiffstats
path: root/src/angle
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@digia.com>2014-01-06 23:07:36 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-18 04:39:19 +0100
commit603eac2dfbd14e05a810873c1417aa8dcfa246b4 (patch)
tree498e605b337d33a221447a010ae5650b9301f04f /src/angle
parenta69525243f1355c7a6b68f00af0fe4fbfd1765e0 (diff)
d3dcompiler_qt: Place compiler options in the shader file name
The compiler service needs to know what options to pass to the compiler, and these options can affect the outcome of the shader blob. Runtime compiled shader output must match this file name in the binary directory. Pre-compiled shader blobs (e.g. those placed in a resource file) are permitted to drop options from the file name if the implementor can ensure the blob is compatible with the target. Defines are not written out as options, but written into the shader source, and therefore affect the cache key. Change-Id: I11e4a43fcf6818ddb29aca5eba3d8647ba4021a1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'src/angle')
-rw-r--r--src/angle/src/d3dcompiler/main.cpp43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/angle/src/d3dcompiler/main.cpp b/src/angle/src/d3dcompiler/main.cpp
index 3f00df63eb..d2bb43ea9f 100644
--- a/src/angle/src/d3dcompiler/main.cpp
+++ b/src/angle/src/d3dcompiler/main.cpp
@@ -224,24 +224,45 @@ HRESULT WINAPI D3DCompile(
initialized = true;
}
- const QByteArray sourceData = QByteArray::fromRawData(reinterpret_cast<const char *>(data), data_size);
- const QString cacheKey = D3DCompiler::cacheKeyFor(sourceData);
+ QByteArray macros;
+ if (const D3D_SHADER_MACRO *macro = defines) {
+ while (macro) {
+ macros.append('#').append(macro->Name).append(' ').append(macro->Definition).append('\n');
+ ++macro;
+ }
+ }
+
+ const QByteArray sourceData = macros + QByteArray::fromRawData(reinterpret_cast<const char *>(data), data_size);
+ const QString fileName = D3DCompiler::cacheKeyFor(sourceData)
+ + QLatin1Char('!') + QString::fromUtf8(entrypoint)
+ + QLatin1Char('!') + QString::fromUtf8(target)
+ + QLatin1Char('!') + QString::number(sflags);
// Check if pre-compiled shader blob is available
if (!binaryPath.isEmpty()) {
- QFile blob(binaryPath + cacheKey);
- if (blob.open(QFile::ReadOnly)) {
- qCDebug(QT_D3DCOMPILER) << "Opening precompiled shader blob at" << blob.fileName();
- *shader = new D3DCompiler::Blob(blob.readAll());
- return S_FALSE;
+ QString blobName = binaryPath + fileName;
+ QFile blob(blobName);
+ while (!blob.exists()) {
+ // Progressively drop optional parts
+ blobName.truncate(blobName.lastIndexOf(QLatin1Char('!')));
+ if (blobName.isEmpty())
+ break;
+ blob.setFileName(blobName);
+ }
+ if (blob.exists()) {
+ if (blob.open(QFile::ReadOnly)) {
+ qCDebug(QT_D3DCOMPILER) << "Opening precompiled shader blob at" << blob.fileName();
+ *shader = new D3DCompiler::Blob(blob.readAll());
+ return S_FALSE;
+ }
+ qCDebug(QT_D3DCOMPILER) << "Found, but unable to open, precompiled shader blob at" << blob.fileName();
}
- qCDebug(QT_D3DCOMPILER) << "Found, but unable to open, precompiled shader blob at" << blob.fileName();
}
// Shader blob is not available, compile with compilation service if possible
if (!sourcePath.isEmpty() && serviceAvailable) {
// Dump source to source path; wait for blob to appear
- QFile source(sourcePath + cacheKey);
+ QFile source(sourcePath + fileName);
if (!source.open(QFile::WriteOnly)) {
qCDebug(QT_D3DCOMPILER) << "Unable to write shader source to file:" << source.fileName() << source.errorString();
return E_ACCESSDENIED;
@@ -257,7 +278,7 @@ HRESULT WINAPI D3DCompile(
QElapsedTimer timer;
timer.start();
- QFile blob(binaryPath + cacheKey);
+ QFile blob(binaryPath + fileName);
while (!(blob.exists() && blob.open(QFile::ReadOnly)) && timer.elapsed() < timeout)
QThread::msleep(100);
@@ -280,7 +301,7 @@ HRESULT WINAPI D3DCompile(
const QByteArray blobContents = QByteArray::fromRawData(
reinterpret_cast<const char *>((*shader)->GetBufferPointer()), (*shader)->GetBufferSize());
- QFile blob(binaryPath + cacheKey);
+ QFile blob(binaryPath + fileName);
if (blob.open(QFile::WriteOnly) && blob.write(blobContents))
qCDebug(QT_D3DCOMPILER) << "Cached shader blob at" << blob.fileName();
else