mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 07:06:11 +00:00
main: Replace --dawn-validation with --validate
Performs output validation with spirv-val for SPIR-V (as before), HLSL validation with DXC, and MSL validation with the Metal Shader Compiler. Disable HLSL tests that fail to validate Bug: tint:812 Change-Id: If78c351b4e23c7fb50d333eacf9ee7cc81d18564 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51280 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
a7a23eaa9e
commit
a70c14dbce
133
src/val/val.cc
Normal file
133
src/val/val.cc
Normal file
@@ -0,0 +1,133 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/val/val.h"
|
||||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/program.h"
|
||||
#include "src/utils/io/command.h"
|
||||
#include "src/utils/io/tmpfile.h"
|
||||
|
||||
namespace tint {
|
||||
namespace val {
|
||||
|
||||
Result Hlsl(const std::string& dxc_path,
|
||||
const std::string& source,
|
||||
Program* program) {
|
||||
Result result;
|
||||
|
||||
auto dxc = utils::Command(dxc_path);
|
||||
if (!dxc.Found()) {
|
||||
result.output = "DXC not found at '" + std::string(dxc_path) + "'";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
result.source = source;
|
||||
|
||||
utils::TmpFile file;
|
||||
file << source;
|
||||
|
||||
bool found_an_entrypoint = false;
|
||||
for (auto* func : program->AST().Functions()) {
|
||||
if (func->IsEntryPoint()) {
|
||||
found_an_entrypoint = true;
|
||||
|
||||
const char* profile = "";
|
||||
|
||||
switch (func->pipeline_stage()) {
|
||||
case ast::PipelineStage::kNone:
|
||||
result.output = "Invalid PipelineStage";
|
||||
result.failed = true;
|
||||
return result;
|
||||
case ast::PipelineStage::kVertex:
|
||||
profile = "-T vs_6_0";
|
||||
break;
|
||||
case ast::PipelineStage::kFragment:
|
||||
profile = "-T ps_6_0";
|
||||
break;
|
||||
case ast::PipelineStage::kCompute:
|
||||
profile = "-T cs_6_0";
|
||||
break;
|
||||
}
|
||||
|
||||
auto name = program->Symbols().NameFor(func->symbol());
|
||||
auto res = dxc(profile, "-E " + name, file.Path());
|
||||
if (!res.out.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
}
|
||||
result.output += res.out;
|
||||
}
|
||||
if (!res.err.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
}
|
||||
result.output += res.err;
|
||||
}
|
||||
result.failed = (res.error_code != 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_an_entrypoint) {
|
||||
result.output = "No entrypoint found";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Result Msl(const std::string& xcrun_path, const std::string& source) {
|
||||
Result result;
|
||||
|
||||
auto xcrun = utils::Command(xcrun_path);
|
||||
if (!xcrun.Found()) {
|
||||
result.output = "xcrun not found at '" + std::string(xcrun_path) + "'";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
result.source = source;
|
||||
|
||||
utils::TmpFile file(".metal");
|
||||
file << result.source;
|
||||
|
||||
#ifdef _WIN32
|
||||
// On Windows, we should actually be running metal.exe from the Metal
|
||||
// Developer Tools for Windows
|
||||
auto res = xcrun("-x", "metal", "-c", "-o", "NUL", file.Path());
|
||||
#else
|
||||
auto res =
|
||||
xcrun("-sdk", "macosx", "metal", "-o", "/dev/null", "-c", file.Path());
|
||||
#endif
|
||||
if (!res.out.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
}
|
||||
result.output += res.out;
|
||||
}
|
||||
if (!res.err.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
}
|
||||
result.output += res.err;
|
||||
}
|
||||
result.failed = (res.error_code != 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace val
|
||||
} // namespace tint
|
||||
58
src/val/val.h
Normal file
58
src/val/val.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_VAL_VAL_H_
|
||||
#define SRC_VAL_VAL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
// Forward declarations
|
||||
namespace tint {
|
||||
class Program;
|
||||
} // namespace tint
|
||||
|
||||
namespace tint {
|
||||
namespace val {
|
||||
|
||||
/// The return structure of Validate()
|
||||
struct Result {
|
||||
/// True if validation passed
|
||||
bool failed = false;
|
||||
/// Output of DXC.
|
||||
std::string output;
|
||||
/// The generated source that was compiled
|
||||
std::string source;
|
||||
};
|
||||
|
||||
/// Hlsl attempts to compile the shader with DXC, verifying that the shader
|
||||
/// compiles successfully.
|
||||
/// @param dxc_path path to DXC
|
||||
/// @param source the generated HLSL source
|
||||
/// @param program the HLSL program
|
||||
/// @return the result of the compile
|
||||
Result Hlsl(const std::string& dxc_path,
|
||||
const std::string& source,
|
||||
Program* program);
|
||||
|
||||
/// Msl attempts to compile the shader with the Metal Shader Compiler,
|
||||
/// verifying that the shader compiles successfully.
|
||||
/// @param xcrun_path path to xcrun
|
||||
/// @param source the generated MSL source
|
||||
/// @return the result of the compile
|
||||
Result Msl(const std::string& xcrun_path, const std::string& source);
|
||||
|
||||
} // namespace val
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_VAL_VAL_H_
|
||||
Reference in New Issue
Block a user