Improve handling of compilers & command line for edited shaders

* We store the compiler used (when known) in shader debug info and use that to
  select the compiler for editing as even higher priority than the default for a
  given language/encoding combination.
* We also ensure that for known tools we add the input and output parameters
  last, after any custom parameters, so that they are always present regardless
  of what the user puts in.
This commit is contained in:
baldurk
2022-08-10 14:56:44 +01:00
parent e29d48a2a8
commit e061ea3b2e
22 changed files with 333 additions and 203 deletions
@@ -978,10 +978,12 @@ void PipelineStateViewer::shaderEdit_clicked()
IShaderViewer *PipelineStateViewer::EditShader(ResourceId id, ShaderStage shaderType,
const rdcstr &entry, ShaderCompileFlags compileFlags,
ShaderEncoding encoding, const rdcstrpairs &files)
KnownShaderTool knownTool,
ShaderEncoding shaderEncoding,
const rdcstrpairs &files)
{
IShaderViewer *sv =
m_Ctx.EditShader(id, shaderType, entry, files, encoding, compileFlags, NULL, NULL);
IShaderViewer *sv = m_Ctx.EditShader(id, shaderType, entry, files, knownTool, shaderEncoding,
compileFlags, NULL, NULL);
m_Ctx.AddDockWindow(sv->Widget(), DockReference::AddTo, this);
@@ -1025,7 +1027,8 @@ IShaderViewer *PipelineStateViewer::EditOriginalShaderSource(ResourceId id,
}
return EditShader(id, shaderDetails->stage, shaderDetails->entryPoint,
shaderDetails->debugInfo.compileFlags, shaderDetails->debugInfo.encoding, files);
shaderDetails->debugInfo.compileFlags, shaderDetails->debugInfo.compiler,
shaderDetails->debugInfo.encoding, files);
}
IShaderViewer *PipelineStateViewer::EditDecompiledSource(const ShaderProcessingTool &tool,
@@ -1040,8 +1043,8 @@ IShaderViewer *PipelineStateViewer::EditDecompiledSource(const ShaderProcessingT
rdcstrpairs files;
files.push_back(rdcpair<rdcstr, rdcstr>("decompiled", source));
IShaderViewer *sv =
EditShader(id, shaderDetails->stage, shaderDetails->entryPoint, {}, tool.output, files);
IShaderViewer *sv = EditShader(id, shaderDetails->stage, shaderDetails->entryPoint, {},
KnownShaderTool::Unknown, tool.output, files);
sv->ShowErrors(out.log);
@@ -1133,7 +1136,8 @@ void PipelineStateViewer::SetupShaderEditButton(QToolButton *button, ResourceId
files.push_back(rdcpair<rdcstr, rdcstr>("pseudocode", editeddisasm));
EditShader(shaderId, shaderDetails->stage, shaderDetails->entryPoint,
shaderDetails->debugInfo.compileFlags, ShaderEncoding::Unknown, files);
shaderDetails->debugInfo.compileFlags, KnownShaderTool::Unknown,
ShaderEncoding::Unknown, files);
});
});
}
@@ -1147,7 +1151,7 @@ void PipelineStateViewer::SetupShaderEditButton(QToolButton *button, ResourceId
"decompiled_stub.hlsl", GenerateHLSLStub(bindpointMapping, shaderDetails, entry)));
EditShader(shaderId, shaderDetails->stage, entry, shaderDetails->debugInfo.compileFlags,
ShaderEncoding::HLSL, files);
KnownShaderTool::Unknown, ShaderEncoding::HLSL, files);
}
});
@@ -146,8 +146,8 @@ private:
QString GenerateHLSLStub(const ShaderBindpointMapping &bindpointMapping,
const ShaderReflection *shaderDetails, const QString &entryFunc);
IShaderViewer *EditShader(ResourceId id, ShaderStage shaderType, const rdcstr &entry,
ShaderCompileFlags compileFlags, ShaderEncoding encoding,
const rdcstrpairs &files);
ShaderCompileFlags compileFlags, KnownShaderTool knownTool,
ShaderEncoding shaderEncoding, const rdcstrpairs &files);
IShaderViewer *EditOriginalShaderSource(ResourceId id, const ShaderReflection *shaderDetails);
IShaderViewer *EditDecompiledSource(const ShaderProcessingTool &tool, ResourceId id,
const ShaderReflection *shaderDetails);
+3 -3
View File
@@ -754,13 +754,13 @@ struct CaptureContextInvoker : ObjectForwarder<ICaptureContext>
InvokeVoidFunction(&ICaptureContext::ShowResourceInspector);
}
virtual IShaderViewer *EditShader(ResourceId id, ShaderStage stage, const rdcstr &entryPoint,
const rdcstrpairs &files, ShaderEncoding shaderEncoding,
ShaderCompileFlags flags,
const rdcstrpairs &files, KnownShaderTool knownTool,
ShaderEncoding shaderEncoding, ShaderCompileFlags flags,
IShaderViewer::SaveCallback saveCallback,
IShaderViewer::RevertCallback revertCallback) override
{
return InvokeRetFunction<IShaderViewer *>(&ICaptureContext::EditShader, id, stage, entryPoint,
files, shaderEncoding, flags, saveCallback,
files, knownTool, shaderEncoding, flags, saveCallback,
revertCallback);
}
+29 -5
View File
@@ -191,8 +191,8 @@ ShaderViewer::ShaderViewer(ICaptureContext &ctx, QWidget *parent)
}
void ShaderViewer::editShader(ResourceId id, ShaderStage stage, const QString &entryPoint,
const rdcstrpairs &files, ShaderEncoding shaderEncoding,
ShaderCompileFlags flags)
const rdcstrpairs &files, KnownShaderTool knownTool,
ShaderEncoding shaderEncoding, ShaderCompileFlags flags)
{
m_Scintillas.removeOne(m_DisassemblyView);
ui->docking->removeToolWindow(m_DisassemblyFrame);
@@ -236,6 +236,28 @@ void ShaderViewer::editShader(ResourceId id, ShaderStage stage, const QString &e
MarkModification();
});
// if we know the shader was originally compiled with a specific tool, pick the first matching
// tool we have configured.
if(knownTool != KnownShaderTool::Unknown)
{
for(const ShaderProcessingTool &tool : m_Ctx.Config().ShaderProcessors)
{
// skip tools that can't accept our inputs, or doesn't produce a supported output
if(tool.tool == knownTool)
{
for(int i = 0; i < ui->compileTool->count(); i++)
{
if(ui->compileTool->itemText(i) == tool.name)
{
ui->compileTool->setCurrentIndex(i);
break;
}
}
break;
}
}
}
// if it's a custom shader, hide the group entirely (don't allow customisation of compile
// parameters). We can still use it to store the parameters passed in. When visible we collapse it
// by default.
@@ -1248,8 +1270,9 @@ ShaderViewer *ShaderViewer::LoadEditor(ICaptureContext &ctx, QVariantMap data,
encoding = ShaderEncoding::HLSL;
}
ShaderViewer *view = EditShader(ctx, id, stage, entryPoint, files, encoding, flags, saveCallback,
revertCallback, modifyCallback, parent);
ShaderViewer *view =
EditShader(ctx, id, stage, entryPoint, files, KnownShaderTool::Unknown, encoding, flags,
saveCallback, revertCallback, modifyCallback, parent);
int toolIndex = -1;
@@ -5775,7 +5798,8 @@ void ShaderViewer::PopulateCompileToolParameters()
ShaderCompileFlag &flag = m_Flags.flags[i];
if(flag.name == "@cmdline")
{
// append command line from saved flags
// append command line from saved flags, so any specified options override the defaults if
// they're specified twice
ui->toolCommandLine->setPlainText(ui->toolCommandLine->toPlainText() +
lit(" %1").arg(flag.value));
break;
+5 -4
View File
@@ -116,8 +116,8 @@ public:
static ShaderViewer *EditShader(ICaptureContext &ctx, ResourceId id, ShaderStage stage,
const QString &entryPoint, const rdcstrpairs &files,
ShaderEncoding shaderEncoding, ShaderCompileFlags flags,
IShaderViewer::SaveCallback saveCallback,
KnownShaderTool knownTool, ShaderEncoding shaderEncoding,
ShaderCompileFlags flags, IShaderViewer::SaveCallback saveCallback,
IShaderViewer::RevertCallback revertCallback,
ModifyCallback modifyCallback, QWidget *parent)
{
@@ -125,7 +125,7 @@ public:
ret->m_SaveCallback = saveCallback;
ret->m_RevertCallback = revertCallback;
ret->m_ModifyCallback = modifyCallback;
ret->editShader(id, stage, entryPoint, files, shaderEncoding, flags);
ret->editShader(id, stage, entryPoint, files, knownTool, shaderEncoding, flags);
return ret;
}
@@ -208,7 +208,8 @@ private slots:
private:
explicit ShaderViewer(ICaptureContext &ctx, QWidget *parent = 0);
void editShader(ResourceId id, ShaderStage stage, const QString &entryPoint,
const rdcstrpairs &files, ShaderEncoding shaderEncoding, ShaderCompileFlags flags);
const rdcstrpairs &files, KnownShaderTool knownTool,
ShaderEncoding shaderEncoding, ShaderCompileFlags flags);
void debugShader(const ShaderBindpointMapping *bind, const ShaderReflection *shader,
ResourceId pipeline, ShaderDebugTrace *trace, const QString &debugContext);
+1 -1
View File
@@ -4574,7 +4574,7 @@ void TextureViewer::on_customEdit_clicked()
QPointer<TextureViewer> thisPointer(this);
IShaderViewer *s = m_Ctx.EditShader(
ResourceId(), ShaderStage::Fragment, lit("main"), files,
ResourceId(), ShaderStage::Fragment, lit("main"), files, KnownShaderTool::Unknown,
encodingExtensions[QFileInfo(filename).completeSuffix()], ShaderCompileFlags(),
// Save Callback
[thisPointer, key, filename, path](ICaptureContext *ctx, IShaderViewer *viewer, ResourceId,