tint->dawn: Shuffle source tree in preperation of merging repos

docs/    -> docs/tint/
fuzzers/ -> src/tint/fuzzers/
samples/ -> src/tint/cmd/
src/     -> src/tint/
test/    -> test/tint/

BUG=tint:1418,tint:1433

Change-Id: Id2aa79f989aef3245b80ef4aa37a27ff16cd700b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80482
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Ryan Harrison
2022-02-21 15:19:07 +00:00
committed by Tint LUCI CQ
parent 38f1e9c75c
commit dbc13af287
12231 changed files with 4897 additions and 4871 deletions

178
src/tint/val/hlsl.cc Normal file
View File

@@ -0,0 +1,178 @@
// 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/tint/val/val.h"
#include "src/tint/utils/io/command.h"
#include "src/tint/utils/io/tmpfile.h"
#ifdef _WIN32
#include <Windows.h>
#include <d3dcommon.h>
#include <d3dcompiler.h>
#include <wrl.h>
using Microsoft::WRL::ComPtr;
#endif // _WIN32
namespace tint {
namespace val {
Result HlslUsingDXC(const std::string& dxc_path,
const std::string& source,
const EntryPointList& entry_points) {
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";
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;
}
return result;
}
#ifdef _WIN32
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>(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";
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;
}
return result;
}
#endif // _WIN32
} // namespace val
} // namespace tint

69
src/tint/val/msl.cc Normal file
View File

@@ -0,0 +1,69 @@
// 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/tint/val/val.h"
#include "src/tint/ast/module.h"
#include "src/tint/program.h"
#include "src/tint/utils/io/command.h"
#include "src/tint/utils/io/tmpfile.h"
namespace tint {
namespace val {
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;
}
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());
#else
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";
}
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

61
src/tint/val/msl_metal.mm Normal file
View File

@@ -0,0 +1,61 @@
// 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.
#ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
@import Metal;
// Disable: error: treating #include as an import of module 'std.string'
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wauto-import"
#include "src/tint/val/val.h"
#pragma clang diagnostic pop
namespace tint {
namespace val {
Result MslUsingMetalAPI(const std::string& src) {
tint::val::Result result;
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;
}
return result;
}
} // namespace val
} // namespace tint
#endif // TINT_ENABLE_MSL_VALIDATION_USING_METAL_API

80
src/tint/val/val.h Normal file
View File

@@ -0,0 +1,80 @@
// 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_TINT_VAL_VAL_H_
#define SRC_TINT_VAL_VAL_H_
#include <string>
#include <utility>
#include <vector>
#include "src/tint/ast/pipeline_stage.h"
// Forward declarations
namespace tint {
class Program;
} // namespace tint
namespace tint {
namespace val {
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;
};
/// 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 entry_points the list of entry points to validate
/// @return the result of the compile
Result HlslUsingDXC(const std::string& dxc_path,
const std::string& source,
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
/// @return the result of the compile
Result HlslUsingFXC(const std::string& source,
const EntryPointList& entry_points);
#endif // _WIN32
/// 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);
#ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
/// Msl attempts to compile the shader with the runtime Metal Shader Compiler
/// API, verifying that the shader compiles successfully.
/// @param source the generated MSL source
/// @return the result of the compile
Result MslUsingMetalAPI(const std::string& source);
#endif // TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
} // namespace val
} // namespace tint
#endif // SRC_TINT_VAL_VAL_H_