Add transform to substitute overrides with const expressions.

This CL adds a SubstituteOverride transform which will convert
an `override` into a `const`. The transform is provided a map of
(string, double) which matches what the WebGPU API accepts as
data for overrides.

Bug: tint:1582
Change-Id: I6e6bf51b98ce4d4746f8de55128666c36735e585
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96760
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2022-07-22 16:05:06 +00:00
committed by Dawn LUCI CQ
parent 9ec7893ad4
commit 256f1116b8
156 changed files with 1235 additions and 659 deletions

View File

@@ -30,8 +30,7 @@ namespace tint::val {
Result HlslUsingDXC(const std::string& dxc_path,
const std::string& source,
const EntryPointList& entry_points,
const std::vector<std::string>& overrides) {
const EntryPointList& entry_points) {
Result result;
auto dxc = utils::Command(dxc_path);
@@ -70,13 +69,7 @@ Result HlslUsingDXC(const std::string& dxc_path,
"/Zpr " // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
"/Gis"; // D3DCOMPILE_IEEE_STRICTNESS
std::string defs;
defs.reserve(overrides.size() * 20);
for (auto& o : overrides) {
defs += "/D" + o + " ";
}
auto res = dxc(profile, "-E " + ep.first, compileFlags, file.Path(), defs);
auto res = dxc(profile, "-E " + ep.first, compileFlags, file.Path());
if (!res.out.empty()) {
if (!result.output.empty()) {
result.output += "\n";
@@ -102,9 +95,7 @@ Result HlslUsingDXC(const std::string& dxc_path,
}
#ifdef _WIN32
Result HlslUsingFXC(const std::string& source,
const EntryPointList& entry_points,
const std::vector<std::string>& overrides) {
Result HlslUsingFXC(const std::string& source, const EntryPointList& entry_points) {
Result result;
// This library leaks if an error happens in this function, but it is ok
@@ -148,26 +139,12 @@ Result HlslUsingFXC(const std::string& source,
UINT compileFlags = D3DCOMPILE_OPTIMIZATION_LEVEL0 | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR |
D3DCOMPILE_IEEE_STRICTNESS;
auto overrides_copy = overrides; // Copy so that we can replace '=' with '\0'
std::vector<D3D_SHADER_MACRO> macros;
macros.reserve(overrides_copy.size() * 2);
for (auto& o : overrides_copy) {
if (auto sep = o.find_first_of('='); sep != std::string::npos) {
// Replace '=' with '\0' so we can point directly into the allocated string buffer
o[sep] = '\0';
macros.push_back(D3D_SHADER_MACRO{&o[0], &o[sep + 1]});
} else {
macros.emplace_back(D3D_SHADER_MACRO{o.c_str(), NULL});
}
}
macros.emplace_back(D3D_SHADER_MACRO{NULL, NULL});
ComPtr<ID3DBlob> compiledShader;
ComPtr<ID3DBlob> errors;
HRESULT cr = d3dCompile(source.c_str(), // pSrcData
source.length(), // SrcDataSize
nullptr, // pSourceName
macros.data(), // pDefines
nullptr, // pDefines
nullptr, // pInclude
ep.first.c_str(), // pEntrypoint
profile, // pTarget

View File

@@ -43,23 +43,18 @@ struct Result {
/// @param dxc_path path to DXC
/// @param source the generated HLSL source
/// @param entry_points the list of entry points to validate
/// @param overrides optional list of pipeline overrides
/// @return the result of the compile
Result HlslUsingDXC(const std::string& dxc_path,
const std::string& source,
const EntryPointList& entry_points,
const std::vector<std::string>& overrides);
const EntryPointList& entry_points);
#ifdef _WIN32
/// Hlsl attempts to compile the shader with FXC, verifying that the shader
/// compiles successfully.
/// @param source the generated HLSL source
/// @param entry_points the list of entry points to validate
/// @param overrides optional list of pipeline overrides
/// @return the result of the compile
Result HlslUsingFXC(const std::string& source,
const EntryPointList& entry_points,
const std::vector<std::string>& overrides);
Result HlslUsingFXC(const std::string& source, const EntryPointList& entry_points);
#endif // _WIN32
/// Msl attempts to compile the shader with the Metal Shader Compiler,