mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-07-08 08:40:55 +00:00
Add auto-detection for dxc as a shader processing tool
This commit is contained in:
@@ -557,6 +557,8 @@ rdcstr ShaderProcessingTool::DefaultArguments() const
|
||||
return "-D -g -V -o {output_file} {input_file} -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 args;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@ DOCUMENT(R"(Identifies a particular known tool used for shader processing.
|
||||
|
||||
`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
|
||||
{
|
||||
@@ -64,6 +68,7 @@ enum class KnownShaderTool : uint32_t
|
||||
glslangValidatorGLSL,
|
||||
glslangValidatorHLSL,
|
||||
spirv_as,
|
||||
dxc,
|
||||
Count,
|
||||
};
|
||||
|
||||
@@ -81,6 +86,8 @@ inline rdcstr ToolExecutable(KnownShaderTool tool)
|
||||
return "glslangValidator";
|
||||
else if(tool == KnownShaderTool::spirv_as)
|
||||
return "spirv-as";
|
||||
else if(tool == KnownShaderTool::dxc)
|
||||
return "dxc";
|
||||
|
||||
return "";
|
||||
}
|
||||
@@ -95,6 +102,8 @@ inline ShaderEncoding ToolInput(KnownShaderTool tool)
|
||||
return ShaderEncoding::HLSL;
|
||||
else if(tool == KnownShaderTool::spirv_as)
|
||||
return ShaderEncoding::SPIRVAsm;
|
||||
else if(tool == KnownShaderTool::dxc)
|
||||
return ShaderEncoding::HLSL;
|
||||
|
||||
return ShaderEncoding::Unknown;
|
||||
}
|
||||
@@ -106,7 +115,8 @@ inline ShaderEncoding ToolOutput(KnownShaderTool tool)
|
||||
else if(tool == KnownShaderTool::spirv_dis)
|
||||
return ShaderEncoding::SPIRVAsm;
|
||||
else if(tool == KnownShaderTool::glslangValidatorGLSL ||
|
||||
tool == KnownShaderTool::glslangValidatorHLSL || tool == KnownShaderTool::spirv_as)
|
||||
tool == KnownShaderTool::glslangValidatorHLSL || tool == KnownShaderTool::spirv_as ||
|
||||
tool == KnownShaderTool::dxc)
|
||||
return ShaderEncoding::SPIRV;
|
||||
|
||||
return ShaderEncoding::Unknown;
|
||||
|
||||
@@ -47,6 +47,7 @@ rdcstr DoStringise(const KnownShaderTool &el)
|
||||
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();
|
||||
}
|
||||
@@ -211,10 +212,12 @@ ShaderToolOutput ShaderProcessingTool::DisassembleShader(QWidget *window,
|
||||
arg = input_file;
|
||||
if(arg == lit("{output_file}"))
|
||||
arg = output_file = tmpPath(lit("shader_output"));
|
||||
if(arg == lit("{glsl_stage4}"))
|
||||
arg = glsl_stage4[int(shaderDetails->stage)];
|
||||
if(arg == lit("{hlsl_stage2}"))
|
||||
arg = hlsl_stage2[int(shaderDetails->stage)];
|
||||
|
||||
// allow substring matches from the left, to enable e.g. {hlsl_stage2}_6_0
|
||||
if(arg.left(13) == lit("{glsl_stage4}"))
|
||||
arg.replace(0, 13, glsl_stage4[int(shaderDetails->stage)]);
|
||||
if(arg.left(13) == lit("{hlsl_stage2}"))
|
||||
arg.replace(0, 13, hlsl_stage2[int(shaderDetails->stage)]);
|
||||
}
|
||||
|
||||
QFile binHandle(input_file);
|
||||
@@ -257,10 +260,12 @@ ShaderToolOutput ShaderProcessingTool::CompileShader(QWidget *window, rdcstr sou
|
||||
arg = output_file = tmpPath(lit("shader_output"));
|
||||
if(arg == lit("{entry_point}"))
|
||||
arg = entryPoint;
|
||||
if(arg == lit("{glsl_stage4}"))
|
||||
arg = glsl_stage4[int(stage)];
|
||||
if(arg == lit("{hlsl_stage2}"))
|
||||
arg = hlsl_stage2[int(stage)];
|
||||
|
||||
// allow substring matches from the left, to enable e.g. {hlsl_stage2}_6_0
|
||||
if(arg.left(13) == lit("{glsl_stage4}"))
|
||||
arg.replace(0, 13, glsl_stage4[int(stage)]);
|
||||
if(arg.left(13) == lit("{hlsl_stage2}"))
|
||||
arg.replace(0, 13, hlsl_stage2[int(stage)]);
|
||||
}
|
||||
|
||||
QFile binHandle(input_file);
|
||||
|
||||
@@ -4939,13 +4939,18 @@ void ParseSPIRV(uint32_t *spirv, size_t spirvLength, SPVModule &module)
|
||||
|
||||
module.generator = spirv[2];
|
||||
|
||||
bool isglslang = false;
|
||||
bool hasParamsInModuleProcessed = false;
|
||||
|
||||
{
|
||||
uint32_t toolid = (module.generator & 0xffff0000) >> 16;
|
||||
|
||||
if(toolid == 8 || toolid == 13)
|
||||
isglslang = true;
|
||||
// see table above:
|
||||
// - 8 is glslang
|
||||
// - 13 is shaderc
|
||||
// - 14 is dxc
|
||||
|
||||
if(toolid == 8 || toolid == 13 || toolid == 14)
|
||||
hasParamsInModuleProcessed = true;
|
||||
}
|
||||
|
||||
uint32_t idbound = spirv[3];
|
||||
@@ -4990,7 +4995,7 @@ void ParseSPIRV(uint32_t *spirv, size_t spirvLength, SPVModule &module)
|
||||
|
||||
// glslang outputs command-line arguments as OpModuleProcessed - before SPIR-V 1.1 where
|
||||
// it was an actual op, it was output as comments in the source.
|
||||
if(isglslang)
|
||||
if(hasParamsInModuleProcessed)
|
||||
{
|
||||
const char compileFlagPrefix[] = "// OpModuleProcessed ";
|
||||
const char endMarker[] = "#line 1\n";
|
||||
@@ -5062,7 +5067,7 @@ void ParseSPIRV(uint32_t *spirv, size_t spirvLength, SPVModule &module)
|
||||
case spv::OpModuleProcessed:
|
||||
{
|
||||
// glslang outputs command-line arguments as OpModuleProcessed
|
||||
if(isglslang)
|
||||
if(hasParamsInModuleProcessed)
|
||||
{
|
||||
module.cmdline += " --";
|
||||
module.cmdline += (const char *)&spirv[it + 1];
|
||||
|
||||
Reference in New Issue
Block a user