mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Consistent formatting for Dawn/Tint.
This CL updates the clang format files to have a single shared format between Dawn and Tint. The major changes are tabs are 4 spaces, lines are 100 columns and namespaces are not indented. Bug: dawn:1339 Change-Id: I4208742c95643998d9fd14e77a9cc558071ded39 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87603 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
73b1d1dafa
commit
41e4d9a34c
@@ -31,145 +31,143 @@ namespace tint::val {
|
||||
Result HlslUsingDXC(const std::string& dxc_path,
|
||||
const std::string& source,
|
||||
const EntryPointList& entry_points) {
|
||||
Result result;
|
||||
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;
|
||||
}
|
||||
|
||||
utils::TmpFile file;
|
||||
file << source;
|
||||
|
||||
for (auto ep : entry_points) {
|
||||
const char* profile = "";
|
||||
|
||||
switch (ep.second) {
|
||||
case ast::PipelineStage::kNone:
|
||||
result.output = "Invalid PipelineStage";
|
||||
auto dxc = utils::Command(dxc_path);
|
||||
if (!dxc.Found()) {
|
||||
result.output = "DXC not found at '" + std::string(dxc_path) + "'";
|
||||
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;
|
||||
}
|
||||
|
||||
// Match Dawn's compile flags
|
||||
// See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp
|
||||
// and dawn_native\d3d12\ShaderModuleD3D12.cpp (GetDXCArguments)
|
||||
const char* compileFlags =
|
||||
"/Zpr " // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
|
||||
"/Gis"; // D3DCOMPILE_IEEE_STRICTNESS
|
||||
utils::TmpFile file;
|
||||
file << source;
|
||||
|
||||
auto res = dxc(profile, "-E " + ep.first, compileFlags, 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);
|
||||
}
|
||||
for (auto ep : entry_points) {
|
||||
const char* profile = "";
|
||||
|
||||
switch (ep.second) {
|
||||
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;
|
||||
}
|
||||
|
||||
// Match Dawn's compile flags
|
||||
// See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp
|
||||
// and dawn_native\d3d12\ShaderModuleD3D12.cpp (GetDXCArguments)
|
||||
const char* compileFlags =
|
||||
"/Zpr " // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
|
||||
"/Gis"; // D3DCOMPILE_IEEE_STRICTNESS
|
||||
|
||||
auto res = dxc(profile, "-E " + ep.first, compileFlags, 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 (entry_points.empty()) {
|
||||
result.output = "No entrypoint found";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (entry_points.empty()) {
|
||||
result.output = "No entrypoint found";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
Result HlslUsingFXC(const std::string& source,
|
||||
const EntryPointList& entry_points) {
|
||||
Result result;
|
||||
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
|
||||
// because it is loaded at most once, and the executables using HlslUsingFXC
|
||||
// are short-lived.
|
||||
HMODULE fxcLib = LoadLibraryA("d3dcompiler_47.dll");
|
||||
if (fxcLib == nullptr) {
|
||||
result.output = "Couldn't load FXC";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
pD3DCompile d3dCompile = reinterpret_cast<pD3DCompile>(
|
||||
reinterpret_cast<void*>(GetProcAddress(fxcLib, "D3DCompile")));
|
||||
if (d3dCompile == nullptr) {
|
||||
result.output = "Couldn't load D3DCompile from FXC";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
for (auto ep : entry_points) {
|
||||
const char* profile = "";
|
||||
switch (ep.second) {
|
||||
case ast::PipelineStage::kNone:
|
||||
result.output = "Invalid PipelineStage";
|
||||
// This library leaks if an error happens in this function, but it is ok
|
||||
// because it is loaded at most once, and the executables using HlslUsingFXC
|
||||
// are short-lived.
|
||||
HMODULE fxcLib = LoadLibraryA("d3dcompiler_47.dll");
|
||||
if (fxcLib == nullptr) {
|
||||
result.output = "Couldn't load FXC";
|
||||
result.failed = true;
|
||||
return result;
|
||||
case ast::PipelineStage::kVertex:
|
||||
profile = "vs_5_1";
|
||||
break;
|
||||
case ast::PipelineStage::kFragment:
|
||||
profile = "ps_5_1";
|
||||
break;
|
||||
case ast::PipelineStage::kCompute:
|
||||
profile = "cs_5_1";
|
||||
break;
|
||||
}
|
||||
|
||||
// Match Dawn's compile flags
|
||||
// See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp
|
||||
UINT compileFlags = D3DCOMPILE_OPTIMIZATION_LEVEL0 |
|
||||
D3DCOMPILE_PACK_MATRIX_ROW_MAJOR |
|
||||
D3DCOMPILE_IEEE_STRICTNESS;
|
||||
|
||||
ComPtr<ID3DBlob> compiledShader;
|
||||
ComPtr<ID3DBlob> errors;
|
||||
HRESULT cr = d3dCompile(source.c_str(), // pSrcData
|
||||
source.length(), // SrcDataSize
|
||||
nullptr, // pSourceName
|
||||
nullptr, // pDefines
|
||||
nullptr, // pInclude
|
||||
ep.first.c_str(), // pEntrypoint
|
||||
profile, // pTarget
|
||||
compileFlags, // Flags1
|
||||
0, // Flags2
|
||||
&compiledShader, // ppCode
|
||||
&errors); // ppErrorMsgs
|
||||
if (FAILED(cr)) {
|
||||
result.output = static_cast<char*>(errors->GetBufferPointer());
|
||||
result.failed = true;
|
||||
return result;
|
||||
pD3DCompile d3dCompile = reinterpret_cast<pD3DCompile>(
|
||||
reinterpret_cast<void*>(GetProcAddress(fxcLib, "D3DCompile")));
|
||||
if (d3dCompile == nullptr) {
|
||||
result.output = "Couldn't load D3DCompile from FXC";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
FreeLibrary(fxcLib);
|
||||
for (auto ep : entry_points) {
|
||||
const char* profile = "";
|
||||
switch (ep.second) {
|
||||
case ast::PipelineStage::kNone:
|
||||
result.output = "Invalid PipelineStage";
|
||||
result.failed = true;
|
||||
return result;
|
||||
case ast::PipelineStage::kVertex:
|
||||
profile = "vs_5_1";
|
||||
break;
|
||||
case ast::PipelineStage::kFragment:
|
||||
profile = "ps_5_1";
|
||||
break;
|
||||
case ast::PipelineStage::kCompute:
|
||||
profile = "cs_5_1";
|
||||
break;
|
||||
}
|
||||
|
||||
// Match Dawn's compile flags
|
||||
// See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp
|
||||
UINT compileFlags = D3DCOMPILE_OPTIMIZATION_LEVEL0 | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR |
|
||||
D3DCOMPILE_IEEE_STRICTNESS;
|
||||
|
||||
ComPtr<ID3DBlob> compiledShader;
|
||||
ComPtr<ID3DBlob> errors;
|
||||
HRESULT cr = d3dCompile(source.c_str(), // pSrcData
|
||||
source.length(), // SrcDataSize
|
||||
nullptr, // pSourceName
|
||||
nullptr, // pDefines
|
||||
nullptr, // pInclude
|
||||
ep.first.c_str(), // pEntrypoint
|
||||
profile, // pTarget
|
||||
compileFlags, // Flags1
|
||||
0, // Flags2
|
||||
&compiledShader, // ppCode
|
||||
&errors); // ppErrorMsgs
|
||||
if (FAILED(cr)) {
|
||||
result.output = static_cast<char*>(errors->GetBufferPointer());
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
FreeLibrary(fxcLib);
|
||||
|
||||
if (entry_points.empty()) {
|
||||
result.output = "No entrypoint found";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (entry_points.empty()) {
|
||||
result.output = "No entrypoint found";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
@@ -22,46 +22,46 @@
|
||||
namespace tint::val {
|
||||
|
||||
Result Msl(const std::string& xcrun_path, const std::string& source) {
|
||||
Result result;
|
||||
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;
|
||||
}
|
||||
auto xcrun = utils::Command(xcrun_path);
|
||||
if (!xcrun.Found()) {
|
||||
result.output = "xcrun not found at '" + std::string(xcrun_path) + "'";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
utils::TmpFile file(".metal");
|
||||
file << source;
|
||||
utils::TmpFile file(".metal");
|
||||
file << source;
|
||||
|
||||
#ifdef _WIN32
|
||||
// On Windows, we should actually be running metal.exe from the Metal
|
||||
// Developer Tools for Windows
|
||||
auto res = xcrun("-x", "metal", //
|
||||
"-o", "NUL", //
|
||||
"-std=osx-metal1.2", //
|
||||
"-c", file.Path());
|
||||
// On Windows, we should actually be running metal.exe from the Metal
|
||||
// Developer Tools for Windows
|
||||
auto res = xcrun("-x", "metal", //
|
||||
"-o", "NUL", //
|
||||
"-std=osx-metal1.2", //
|
||||
"-c", file.Path());
|
||||
#else
|
||||
auto res = xcrun("-sdk", "macosx", "metal", //
|
||||
"-o", "/dev/null", //
|
||||
"-std=osx-metal1.2", //
|
||||
"-c", file.Path());
|
||||
auto res = xcrun("-sdk", "macosx", "metal", //
|
||||
"-o", "/dev/null", //
|
||||
"-std=osx-metal1.2", //
|
||||
"-c", file.Path());
|
||||
#endif
|
||||
if (!res.out.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
if (!res.out.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
}
|
||||
result.output += res.out;
|
||||
}
|
||||
result.output += res.out;
|
||||
}
|
||||
if (!res.err.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
if (!res.err.empty()) {
|
||||
if (!result.output.empty()) {
|
||||
result.output += "\n";
|
||||
}
|
||||
result.output += res.err;
|
||||
}
|
||||
result.output += res.err;
|
||||
}
|
||||
result.failed = (res.error_code != 0);
|
||||
result.failed = (res.error_code != 0);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace tint::val
|
||||
|
||||
@@ -25,33 +25,32 @@
|
||||
namespace tint::val {
|
||||
|
||||
Result MslUsingMetalAPI(const std::string& src) {
|
||||
tint::val::Result result;
|
||||
tint::val::Result result;
|
||||
|
||||
NSError* error = nil;
|
||||
NSError* error = nil;
|
||||
|
||||
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
|
||||
if (!device) {
|
||||
result.output = "MTLCreateSystemDefaultDevice returned null";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
NSString* source = [NSString stringWithCString:src.c_str() encoding:NSUTF8StringEncoding];
|
||||
|
||||
MTLCompileOptions* compileOptions = [MTLCompileOptions new];
|
||||
compileOptions.languageVersion = MTLLanguageVersion1_2;
|
||||
|
||||
id<MTLLibrary> library = [device newLibraryWithSource:source
|
||||
options:compileOptions
|
||||
error:&error];
|
||||
if (!library) {
|
||||
NSString* output = [error localizedDescription];
|
||||
result.output = [output UTF8String];
|
||||
result.failed = true;
|
||||
}
|
||||
|
||||
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
|
||||
if (!device) {
|
||||
result.output = "MTLCreateSystemDefaultDevice returned null";
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
NSString* source = [NSString stringWithCString:src.c_str()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
|
||||
MTLCompileOptions* compileOptions = [MTLCompileOptions new];
|
||||
compileOptions.languageVersion = MTLLanguageVersion1_2;
|
||||
|
||||
id<MTLLibrary> library = [device newLibraryWithSource:source
|
||||
options:compileOptions
|
||||
error:&error];
|
||||
if (!library) {
|
||||
NSString* output = [error localizedDescription];
|
||||
result.output = [output UTF8String];
|
||||
result.failed = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace tint::val
|
||||
|
||||
@@ -32,10 +32,10 @@ using EntryPointList = std::vector<std::pair<std::string, ast::PipelineStage>>;
|
||||
|
||||
/// The return structure of Validate()
|
||||
struct Result {
|
||||
/// True if validation passed
|
||||
bool failed = false;
|
||||
/// Output of DXC.
|
||||
std::string output;
|
||||
/// True if validation passed
|
||||
bool failed = false;
|
||||
/// Output of DXC.
|
||||
std::string output;
|
||||
};
|
||||
|
||||
/// Hlsl attempts to compile the shader with DXC, verifying that the shader
|
||||
@@ -54,8 +54,7 @@ Result HlslUsingDXC(const std::string& dxc_path,
|
||||
/// @param source the generated HLSL source
|
||||
/// @param entry_points the list of entry points to validate
|
||||
/// @return the result of the compile
|
||||
Result HlslUsingFXC(const std::string& source,
|
||||
const EntryPointList& entry_points);
|
||||
Result HlslUsingFXC(const std::string& source, const EntryPointList& entry_points);
|
||||
#endif // _WIN32
|
||||
|
||||
/// Msl attempts to compile the shader with the Metal Shader Compiler,
|
||||
|
||||
Reference in New Issue
Block a user