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:30:54 +01:00
parent e29d48a2a8
commit e061ea3b2e
22 changed files with 333 additions and 203 deletions
+7 -6
View File
@@ -2450,8 +2450,8 @@ void CaptureContext::ShowResourceInspector()
m_MainWindow->showResourceInspector();
}
IShaderViewer *CaptureContext::EditShader(ResourceId id, ShaderStage stage,
const rdcstr &entryPoint, const rdcstrpairs &files,
IShaderViewer *CaptureContext::EditShader(ResourceId id, ShaderStage stage, const rdcstr &entryPoint,
const rdcstrpairs &files, KnownShaderTool knownTool,
ShaderEncoding shaderEncoding, ShaderCompileFlags flags,
IShaderViewer::SaveCallback saveCallback,
IShaderViewer::RevertCallback revertCallback)
@@ -2479,8 +2479,8 @@ IShaderViewer *CaptureContext::EditShader(ResourceId id, ShaderStage stage,
revertCallback(ctx, view, id);
};
viewer = ShaderViewer::EditShader(*this, id, stage, entryPoint, files, shaderEncoding, flags,
replaceSaveCallback, replaceRevertCallback,
viewer = ShaderViewer::EditShader(*this, id, stage, entryPoint, files, knownTool, shaderEncoding,
flags, replaceSaveCallback, replaceRevertCallback,
[this](ShaderViewer *view, bool closed) {
SetModification(CaptureModifications::EditedShaders);
if(closed)
@@ -2493,8 +2493,9 @@ IShaderViewer *CaptureContext::EditShader(ResourceId id, ShaderStage stage,
}
else
{
viewer = ShaderViewer::EditShader(*this, id, stage, entryPoint, files, shaderEncoding, flags,
saveCallback, revertCallback, NULL, m_MainWindow->Widget());
viewer =
ShaderViewer::EditShader(*this, id, stage, entryPoint, files, knownTool, shaderEncoding,
flags, saveCallback, revertCallback, NULL, m_MainWindow->Widget());
}
return viewer;
+3 -2
View File
@@ -245,8 +245,9 @@ public:
void ShowResourceInspector() override;
IShaderViewer *EditShader(ResourceId id, ShaderStage stage, const rdcstr &entryPoint,
const rdcstrpairs &files, ShaderEncoding shaderEncoding,
ShaderCompileFlags flags, IShaderViewer::SaveCallback saveCallback,
const rdcstrpairs &files, KnownShaderTool knownTool,
ShaderEncoding shaderEncoding, ShaderCompileFlags flags,
IShaderViewer::SaveCallback saveCallback,
IShaderViewer::RevertCallback revertCallback) override;
void ApplyShaderEdit(IShaderViewer *viewer, ResourceId id, ShaderStage stage,
+35 -15
View File
@@ -511,12 +511,6 @@ bool PersistantConfig::Load(const rdcstr &filename)
// if it's declared
if(dis.tool != KnownShaderTool::Unknown)
tools[(size_t)dis.tool] = true;
for(KnownShaderTool tool : values<KnownShaderTool>())
{
if(QString(dis.executable).contains(ToolExecutable(tool)))
tools[(size_t)tool] = true;
}
}
for(KnownShaderTool tool : values<KnownShaderTool>())
@@ -524,7 +518,7 @@ bool PersistantConfig::Load(const rdcstr &filename)
if(tool == KnownShaderTool::Unknown || tools[(size_t)tool])
continue;
QString exe = ToolExecutable(tool);
rdcstr exe = ToolExecutable(tool);
if(exe.isEmpty())
continue;
@@ -588,6 +582,7 @@ bool PersistantConfig::Load(const rdcstr &filename)
{
if(dis.tool != KnownShaderTool::Unknown)
{
dis.name = ToQStr(dis.tool);
dis.input = ToolInput(dis.tool);
dis.output = ToolOutput(dis.tool);
}
@@ -698,22 +693,47 @@ ShaderProcessingTool::ShaderProcessingTool(const QVariant &var)
rdcstr ShaderProcessingTool::DefaultArguments() const
{
if(tool == KnownShaderTool::SPIRV_Cross)
return "--output {output_file} {input_file} --vulkan-semantics --entry {entry_point} --stage "
"{glsl_stage4}";
return "--vulkan-semantics --entry {entry_point} --stage {glsl_stage4}";
else if(tool == KnownShaderTool::spirv_dis)
return "--no-color -o {output_file} {input_file}";
return "--no-color";
else if(tool == KnownShaderTool::glslangValidatorGLSL)
return "-g -V -o {output_file} {input_file} -S {glsl_stage4}";
return "-g -V -S {glsl_stage4}";
else if(tool == KnownShaderTool::glslangValidatorHLSL)
return "-D -g -V -o {output_file} {input_file} -S {glsl_stage4} -e {entry_point}";
return "-D -g -V -S {glsl_stage4} -e {entry_point}";
else if(tool == KnownShaderTool::spirv_as)
return "-o {output_file} {input_file}";
else if(tool == KnownShaderTool::dxc)
return "-T {hlsl_stage2}_6_0 -E {entry_point} -Fo {output_file} {input_file} -spirv";
return "";
else if(tool == KnownShaderTool::dxcSPIRV)
return "-T {hlsl_stage2}_6_0 -E {entry_point} -spirv";
else if(tool == KnownShaderTool::dxcDXIL)
return "-T {hlsl_stage2}_6_0 -E {entry_point}";
else if(tool == KnownShaderTool::fxc)
return "/T {hlsl_stage2}_5_0 /E {entry_point}";
return args;
}
rdcstr ShaderProcessingTool::IOArguments() const
{
if(tool == KnownShaderTool::SPIRV_Cross)
return "--output {output_file} {input_file}";
else if(tool == KnownShaderTool::spirv_dis)
return "-o {output_file} {input_file}";
else if(tool == KnownShaderTool::glslangValidatorGLSL)
return "-o {output_file} {input_file}";
else if(tool == KnownShaderTool::glslangValidatorHLSL)
return "-o {output_file} {input_file}";
else if(tool == KnownShaderTool::spirv_as)
return "-o {output_file} {input_file}";
else if(tool == KnownShaderTool::dxcSPIRV)
return "-Fo {output_file} {input_file}";
else if(tool == KnownShaderTool::dxcDXIL)
return "-Fo {output_file} {input_file}";
else if(tool == KnownShaderTool::fxc)
return "/Fo {output_file} {input_file}";
return rdcstr();
}
ShaderProcessingTool::operator QVariant() const
{
QVariantMap map;
+4 -120
View File
@@ -30,126 +30,6 @@
class QMutex;
DOCUMENT(R"(Identifies a particular known tool used for shader processing.
.. data:: Unknown
Corresponds to no known tool.
.. data:: SPIRV_Cross
`SPIRV-Cross <https://github.com/KhronosGroup/SPIRV-Cross>`_.
.. data:: spirv_dis
`spirv-dis from SPIRV-Tools <https://github.com/KhronosGroup/SPIRV-Tools>`_.
.. data:: glslangValidatorGLSL
`glslang compiler (GLSL) <https://github.com/KhronosGroup/glslang>`_.
.. data:: glslangValidatorHLSL
`glslang compiler (HLSL) <https://github.com/KhronosGroup/glslang>`_.
.. data:: spirv_as
`spirv-as from SPIRV-Tools <https://github.com/KhronosGroup/SPIRV-Tools>`_.
.. data:: dxc
`DirectX Shader Compiler <https://github.com/microsoft/DirectXShaderCompiler>`_.
)");
enum class KnownShaderTool : uint32_t
{
Unknown,
First = Unknown,
SPIRV_Cross,
spirv_dis,
glslangValidatorGLSL,
glslangValidatorHLSL,
spirv_as,
dxc,
Count,
};
ITERABLE_OPERATORS(KnownShaderTool);
DOCUMENT(R"(Returns the default executable name with no suffix for a given :class:`KnownShaderTool`.
.. note::
The executable name is returned with no suffix, e.g. ``foobar`` which may need a platform specific
suffix like ``.exe`` appended.
:param KnownShaderTool tool: The tool to get the executable name for.
:return: The default executable name for this tool, or an empty string if the tool is unrecognised.
:rtype: str
)");
inline rdcstr ToolExecutable(KnownShaderTool tool)
{
if(tool == KnownShaderTool::SPIRV_Cross)
return "spirv-cross";
else if(tool == KnownShaderTool::spirv_dis)
return "spirv-dis";
else if(tool == KnownShaderTool::glslangValidatorGLSL)
return "glslangValidator";
else if(tool == KnownShaderTool::glslangValidatorHLSL)
return "glslangValidator";
else if(tool == KnownShaderTool::spirv_as)
return "spirv-as";
else if(tool == KnownShaderTool::dxc)
return "dxc";
return "";
}
DOCUMENT(R"(Returns the expected default input :class:`~renderdoc.ShaderEncoding` that a
:class:`KnownShaderTool` expects. This may not be accurate and may be configurable depending on the
tool.
:param KnownShaderTool tool: The tool to get the input encoding for.
:return: The encoding that this tool expects as an input by default.
:rtype: renderdoc.ShaderEncoding
)");
inline ShaderEncoding ToolInput(KnownShaderTool tool)
{
if(tool == KnownShaderTool::SPIRV_Cross || tool == KnownShaderTool::spirv_dis)
return ShaderEncoding::SPIRV;
else if(tool == KnownShaderTool::glslangValidatorGLSL)
return ShaderEncoding::GLSL;
else if(tool == KnownShaderTool::glslangValidatorHLSL)
return ShaderEncoding::HLSL;
else if(tool == KnownShaderTool::spirv_as)
return ShaderEncoding::SPIRVAsm;
else if(tool == KnownShaderTool::dxc)
return ShaderEncoding::HLSL;
return ShaderEncoding::Unknown;
}
DOCUMENT(R"(Returns the expected default output :class:`~renderdoc.ShaderEncoding` that a
:class:`KnownShaderTool` produces. This may not be accurate and may be configurable depending on the
tool.
:param KnownShaderTool tool: The tool to get the output encoding for.
:return: The encoding that this tool produces as an output by default.
:rtype: renderdoc.ShaderEncoding
)");
inline ShaderEncoding ToolOutput(KnownShaderTool tool)
{
if(tool == KnownShaderTool::SPIRV_Cross)
return ShaderEncoding::GLSL;
else if(tool == KnownShaderTool::spirv_dis)
return ShaderEncoding::SPIRVAsm;
else if(tool == KnownShaderTool::glslangValidatorGLSL ||
tool == KnownShaderTool::glslangValidatorHLSL || tool == KnownShaderTool::spirv_as ||
tool == KnownShaderTool::dxc)
return ShaderEncoding::SPIRV;
return ShaderEncoding::Unknown;
}
DOCUMENT(R"(Contains the output from invoking a :class:`ShaderProcessingTool`, including both the
actual output data desired as well as any stdout/stderr messages.
)");
@@ -241,6 +121,10 @@ struct ShaderProcessingTool
)");
ShaderToolOutput CompileShader(QWidget *window, rdcstr source, rdcstr entryPoint,
ShaderStage stage, rdcstr args) const;
private:
DOCUMENT("Internal function");
rdcstr IOArguments() const;
};
DECLARE_REFLECTION_STRUCT(ShaderProcessingTool);
+3 -2
View File
@@ -2515,6 +2515,7 @@ place if needed.
:param str entryPoint: The entry point to be used when compiling the edited shader.
:param List[Tuple[str,str]] files: The source files, with each tuple being a pair of the filename
and the file contents.
:param renderdoc.KnownShaderTool knownTool: The preferred tool to use to compile, if known.
:param renderdoc.ShaderEncoding shaderEncoding: The encoding of the input files.
:param renderdoc.ShaderCompileFlags flags: The flags originally used to compile the shader.
:param ShaderViewer.SaveCallback saveCallback: The callback function to call when a save/update is
@@ -2525,8 +2526,8 @@ place if needed.
:rtype: ShaderViewer
)");
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) = 0;
@@ -36,22 +36,6 @@ static const QString hlsl_stage2[arraydim<ShaderStage>()] = {
lit("vs"), lit("hs"), lit("ds"), lit("gs"), lit("ps"), lit("cs"),
};
template <>
rdcstr DoStringise(const KnownShaderTool &el)
{
BEGIN_ENUM_STRINGISE(KnownShaderTool);
{
STRINGISE_ENUM_CLASS_NAMED(Unknown, "Custom Tool");
STRINGISE_ENUM_CLASS_NAMED(SPIRV_Cross, "SPIRV-Cross");
STRINGISE_ENUM_CLASS_NAMED(spirv_dis, "spirv-dis");
STRINGISE_ENUM_CLASS_NAMED(glslangValidatorGLSL, "glslang (GLSL)");
STRINGISE_ENUM_CLASS_NAMED(glslangValidatorHLSL, "glslang (HLSL)");
STRINGISE_ENUM_CLASS_NAMED(spirv_as, "spirv-as");
STRINGISE_ENUM_CLASS_NAMED(dxc, "dxc");
}
END_ENUM_STRINGISE();
}
static QString tmpPath(const QString &filename)
{
return QDir(QDir::tempPath()).absoluteFilePath(filename);
@@ -201,6 +185,9 @@ ShaderToolOutput ShaderProcessingTool::DisassembleShader(QWidget *window,
rdcstr arguments) const
{
QStringList argList = ParseArgsList(arguments.isEmpty() ? DefaultArguments() : arguments);
// always append IO arguments for known tools, so we read/write to our own files and override any
// dangling output specified file in the embedded command line
argList.append(ParseArgsList(IOArguments()));
QString input_file, output_file;
@@ -253,6 +240,9 @@ ShaderToolOutput ShaderProcessingTool::CompileShader(QWidget *window, rdcstr sou
rdcstr arguments) const
{
QStringList argList = ParseArgsList(arguments.isEmpty() ? DefaultArguments() : arguments);
// always append IO arguments for known tools, so we read/write to our own files and override any
// dangling output specified file in the embedded command line
argList.append(ParseArgsList(IOArguments()));
QString input_file, output_file;
@@ -74,6 +74,11 @@ rdcstr ShaderProcessingTool::DefaultArguments() const
return "";
}
rdcstr ShaderProcessingTool::IOArguments() const
{
return "";
}
ShaderToolOutput ShaderProcessingTool::DisassembleShader(QWidget *window,
const ShaderReflection *shaderDetails,
rdcstr arguments) const