Switch to new Tint generator API
Tint now has a single-function API for code generation that automatically runs the backend-specific sanitizer transforms. This API allows for backend-specific configuration options such as the fixed sample mask for MSL (and, in the future, information about which compiler/version is being targeted), and returns any backend-specific metadata such as whether a UBO of buffer sizes is required by the shader. This change prevents the post-sanitizer program from being exposed to Dawn, which is a potential foot-gun (e.g. the Inspector is not expected to be run after the sanitizer transforms, and Dawn is currently doing this). The old Generator class API will be removed from Tint shortly after landing this change. Bug: tint:697 Change-Id: I9b988d55514f810d3091ec6471731e6eb41dc27f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/57103 Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
31930e7287
commit
15838b98af
|
@ -406,14 +406,15 @@ namespace dawn_native {
|
||||||
std::ostringstream errorStream;
|
std::ostringstream errorStream;
|
||||||
errorStream << "Tint SPIR-V writer failure:" << std::endl;
|
errorStream << "Tint SPIR-V writer failure:" << std::endl;
|
||||||
|
|
||||||
tint::writer::spirv::Generator generator(program);
|
tint::writer::spirv::Options options;
|
||||||
if (!generator.Generate()) {
|
options.emit_vertex_point_size = true;
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
auto result = tint::writer::spirv::Generate(program, options);
|
||||||
|
if (!result.success) {
|
||||||
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint32_t> spirv = generator.result();
|
return std::move(result.spirv);
|
||||||
return std::move(spirv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint64_t> GetBindGroupMinBufferSizes(
|
std::vector<uint64_t> GetBindGroupMinBufferSizes(
|
||||||
|
@ -1113,15 +1114,16 @@ namespace dawn_native {
|
||||||
tint::Program program;
|
tint::Program program;
|
||||||
DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages));
|
DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages));
|
||||||
|
|
||||||
tint::writer::wgsl::Generator generator(&program);
|
tint::writer::wgsl::Options options;
|
||||||
if (!generator.Generate()) {
|
auto result = tint::writer::wgsl::Generate(&program, options);
|
||||||
|
if (!result.success) {
|
||||||
std::ostringstream errorStream;
|
std::ostringstream errorStream;
|
||||||
errorStream << "Tint WGSL failure:" << std::endl;
|
errorStream << "Tint WGSL failure:" << std::endl;
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
newWgslCode = generator.result();
|
newWgslCode = std::move(result.wgsl);
|
||||||
newWgslDesc.source = newWgslCode.c_str();
|
newWgslDesc.source = newWgslCode.c_str();
|
||||||
|
|
||||||
if (device->IsToggleEnabled(Toggle::DumpTranslatedShaders)) {
|
if (device->IsToggleEnabled(Toggle::DumpTranslatedShaders)) {
|
||||||
|
@ -1160,18 +1162,6 @@ namespace dawn_native {
|
||||||
parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
|
parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
|
||||||
parseResult->tintSource = std::move(tintSource);
|
parseResult->tintSource = std::move(tintSource);
|
||||||
} else {
|
} else {
|
||||||
tint::transform::Manager transformManager;
|
|
||||||
transformManager.Add<tint::transform::Spirv>();
|
|
||||||
|
|
||||||
tint::transform::DataMap transformInputs;
|
|
||||||
|
|
||||||
tint::transform::Spirv::Config spirv_cfg;
|
|
||||||
spirv_cfg.emit_vertex_point_size = true;
|
|
||||||
transformInputs.Add<tint::transform::Spirv::Config>(spirv_cfg);
|
|
||||||
|
|
||||||
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, &program, transformInputs,
|
|
||||||
nullptr, outMessages));
|
|
||||||
|
|
||||||
std::vector<uint32_t> spirv;
|
std::vector<uint32_t> spirv;
|
||||||
DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(&program));
|
DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(&program));
|
||||||
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
|
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
|
||||||
|
@ -1433,17 +1423,12 @@ namespace dawn_native {
|
||||||
|
|
||||||
tint::transform::Manager transformManager;
|
tint::transform::Manager transformManager;
|
||||||
transformManager.Add<tint::transform::VertexPulling>();
|
transformManager.Add<tint::transform::VertexPulling>();
|
||||||
transformManager.Add<tint::transform::Spirv>();
|
|
||||||
if (GetDevice()->IsRobustnessEnabled()) {
|
if (GetDevice()->IsRobustnessEnabled()) {
|
||||||
transformManager.Add<tint::transform::BoundArrayAccessors>();
|
transformManager.Add<tint::transform::BoundArrayAccessors>();
|
||||||
}
|
}
|
||||||
|
|
||||||
tint::transform::DataMap transformInputs;
|
tint::transform::DataMap transformInputs;
|
||||||
|
|
||||||
tint::transform::Spirv::Config spirv_cfg;
|
|
||||||
spirv_cfg.emit_vertex_point_size = true;
|
|
||||||
transformInputs.Add<tint::transform::Spirv::Config>(spirv_cfg);
|
|
||||||
|
|
||||||
AddVertexPullingTransformConfig(vertexState, entryPoint, pullingBufferBindingSet,
|
AddVertexPullingTransformConfig(vertexState, entryPoint, pullingBufferBindingSet,
|
||||||
&transformInputs);
|
&transformInputs);
|
||||||
|
|
||||||
|
@ -1454,13 +1439,15 @@ namespace dawn_native {
|
||||||
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, programIn, transformInputs,
|
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, programIn, transformInputs,
|
||||||
nullptr, nullptr));
|
nullptr, nullptr));
|
||||||
|
|
||||||
tint::writer::spirv::Generator generator(&program);
|
tint::writer::spirv::Options options;
|
||||||
if (!generator.Generate()) {
|
options.emit_vertex_point_size = true;
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
auto result = tint::writer::spirv::Generate(&program, options);
|
||||||
|
if (!result.success) {
|
||||||
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint32_t> spirv = generator.result();
|
std::vector<uint32_t> spirv = std::move(result.spirv);
|
||||||
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
|
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
|
||||||
return std::move(spirv);
|
return std::move(spirv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,6 @@ namespace dawn_native { namespace d3d12 {
|
||||||
layout->GetFirstIndexOffsetRegisterSpace());
|
layout->GetFirstIndexOffsetRegisterSpace());
|
||||||
}
|
}
|
||||||
transformManager.Add<tint::transform::BindingRemapper>();
|
transformManager.Add<tint::transform::BindingRemapper>();
|
||||||
transformManager.Add<tint::transform::Hlsl>();
|
|
||||||
|
|
||||||
if (!GetDevice()->IsToggleEnabled(Toggle::DumpTranslatedShaders)) {
|
if (!GetDevice()->IsToggleEnabled(Toggle::DumpTranslatedShaders)) {
|
||||||
transformManager.Add<tint::transform::Renamer>();
|
transformManager.Add<tint::transform::Renamer>();
|
||||||
|
@ -300,14 +299,14 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tint::writer::hlsl::Generator generator(&program);
|
tint::writer::hlsl::Options options;
|
||||||
// TODO: Switch to GenerateEntryPoint once HLSL writer supports it.
|
auto result = tint::writer::hlsl::Generate(&program, options);
|
||||||
if (!generator.Generate()) {
|
if (!result.success) {
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return generator.result();
|
return std::move(result.hlsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::string> ShaderModule::TranslateToHLSLWithSPIRVCross(
|
ResultOrError<std::string> ShaderModule::TranslateToHLSLWithSPIRVCross(
|
||||||
|
|
|
@ -122,7 +122,6 @@ namespace dawn_native { namespace metal {
|
||||||
transformManager.Add<tint::transform::BoundArrayAccessors>();
|
transformManager.Add<tint::transform::BoundArrayAccessors>();
|
||||||
}
|
}
|
||||||
transformManager.Add<tint::transform::BindingRemapper>();
|
transformManager.Add<tint::transform::BindingRemapper>();
|
||||||
transformManager.Add<tint::transform::Msl>();
|
|
||||||
|
|
||||||
if (!GetDevice()->IsToggleEnabled(Toggle::DumpTranslatedShaders)) {
|
if (!GetDevice()->IsToggleEnabled(Toggle::DumpTranslatedShaders)) {
|
||||||
transformManager.Add<tint::transform::Renamer>();
|
transformManager.Add<tint::transform::Renamer>();
|
||||||
|
@ -132,8 +131,6 @@ namespace dawn_native { namespace metal {
|
||||||
std::move(accessControls),
|
std::move(accessControls),
|
||||||
/* mayCollide */ true);
|
/* mayCollide */ true);
|
||||||
|
|
||||||
transformInputs.Add<tint::transform::Msl::Config>(kBufferLengthBufferSlot, sampleMask);
|
|
||||||
|
|
||||||
tint::Program program;
|
tint::Program program;
|
||||||
tint::transform::DataMap transformOutputs;
|
tint::transform::DataMap transformOutputs;
|
||||||
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
||||||
|
@ -153,20 +150,18 @@ namespace dawn_native { namespace metal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto* data = transformOutputs.Get<tint::transform::Msl::Result>()) {
|
tint::writer::msl::Options options;
|
||||||
*needsStorageBufferLength = data->needs_storage_buffer_sizes;
|
options.buffer_size_ubo_index = kBufferLengthBufferSlot;
|
||||||
} else {
|
options.fixed_sample_mask = sampleMask;
|
||||||
return DAWN_VALIDATION_ERROR("Transform output missing MSL data.");
|
auto result = tint::writer::msl::Generate(&program, options);
|
||||||
}
|
if (!result.success) {
|
||||||
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
tint::writer::msl::Generator generator(&program);
|
|
||||||
if (!generator.Generate()) {
|
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string msl = generator.result();
|
*needsStorageBufferLength = result.needs_storage_buffer_sizes;
|
||||||
return std::move(msl);
|
|
||||||
|
return std::move(result.msl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::string> ShaderModule::TranslateToMSLWithSPIRVCross(
|
ResultOrError<std::string> ShaderModule::TranslateToMSLWithSPIRVCross(
|
||||||
|
|
|
@ -84,24 +84,15 @@ namespace dawn_native { namespace opengl {
|
||||||
// Tint currently does not support emitting GLSL, so when provided a Tint program need to
|
// Tint currently does not support emitting GLSL, so when provided a Tint program need to
|
||||||
// generate SPIRV and SPIRV-Cross reflection data to be used in this backend.
|
// generate SPIRV and SPIRV-Cross reflection data to be used in this backend.
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
||||||
tint::transform::Manager transformManager;
|
tint::writer::spirv::Options options;
|
||||||
transformManager.append(std::make_unique<tint::transform::Spirv>());
|
auto result = tint::writer::spirv::Generate(GetTintProgram(), options);
|
||||||
|
if (!result.success) {
|
||||||
tint::transform::DataMap transformInputs;
|
|
||||||
|
|
||||||
tint::Program program;
|
|
||||||
DAWN_TRY_ASSIGN(program,
|
|
||||||
RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
|
||||||
nullptr, GetCompilationMessages()));
|
|
||||||
|
|
||||||
tint::writer::spirv::Generator generator(&program);
|
|
||||||
if (!generator.Generate()) {
|
|
||||||
std::ostringstream errorStream;
|
std::ostringstream errorStream;
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
mGLSpirv = generator.result();
|
mGLSpirv = std::move(result.spirv);
|
||||||
DAWN_TRY_ASSIGN(mGLEntryPoints, ReflectShaderUsingSPIRVCross(GetDevice(), mGLSpirv));
|
DAWN_TRY_ASSIGN(mGLEntryPoints, ReflectShaderUsingSPIRVCross(GetDevice(), mGLSpirv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,27 +97,24 @@ namespace dawn_native { namespace vulkan {
|
||||||
if (GetDevice()->IsRobustnessEnabled()) {
|
if (GetDevice()->IsRobustnessEnabled()) {
|
||||||
transformManager.Add<tint::transform::BoundArrayAccessors>();
|
transformManager.Add<tint::transform::BoundArrayAccessors>();
|
||||||
}
|
}
|
||||||
transformManager.Add<tint::transform::Spirv>();
|
|
||||||
|
|
||||||
tint::transform::DataMap transformInputs;
|
tint::transform::DataMap transformInputs;
|
||||||
|
|
||||||
tint::transform::Spirv::Config spirv_cfg;
|
|
||||||
spirv_cfg.emit_vertex_point_size = true;
|
|
||||||
transformInputs.Add<tint::transform::Spirv::Config>(spirv_cfg);
|
|
||||||
|
|
||||||
tint::Program program;
|
tint::Program program;
|
||||||
DAWN_TRY_ASSIGN(program,
|
DAWN_TRY_ASSIGN(program,
|
||||||
RunTransforms(&transformManager, parseResult->tintProgram.get(),
|
RunTransforms(&transformManager, parseResult->tintProgram.get(),
|
||||||
transformInputs, nullptr, nullptr));
|
transformInputs, nullptr, nullptr));
|
||||||
// We will miss the messages generated in this RunTransforms.
|
// We will miss the messages generated in this RunTransforms.
|
||||||
|
|
||||||
tint::writer::spirv::Generator generator(&program);
|
tint::writer::spirv::Options options;
|
||||||
if (!generator.Generate()) {
|
options.emit_vertex_point_size = true;
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
auto result = tint::writer::spirv::Generate(&program, options);
|
||||||
|
if (!result.success) {
|
||||||
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
spirv = generator.result();
|
spirv = std::move(result.spirv);
|
||||||
spirvPtr = &spirv;
|
spirvPtr = &spirv;
|
||||||
|
|
||||||
// Rather than use a new ParseResult object, we just reuse the original parseResult
|
// Rather than use a new ParseResult object, we just reuse the original parseResult
|
||||||
|
@ -214,13 +211,15 @@ namespace dawn_native { namespace vulkan {
|
||||||
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
||||||
nullptr, nullptr));
|
nullptr, nullptr));
|
||||||
|
|
||||||
tint::writer::spirv::Generator generator(&program);
|
tint::writer::spirv::Options options;
|
||||||
if (!generator.Generate()) {
|
options.emit_vertex_point_size = true;
|
||||||
errorStream << "Generator: " << generator.error() << std::endl;
|
auto result = tint::writer::spirv::Generate(&program, options);
|
||||||
|
if (!result.success) {
|
||||||
|
errorStream << "Generator: " << result.error << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint32_t> spirv = generator.result();
|
std::vector<uint32_t> spirv = result.spirv;
|
||||||
|
|
||||||
// Don't save the transformedParseResult but just create a VkShaderModule
|
// Don't save the transformedParseResult but just create a VkShaderModule
|
||||||
VkShaderModuleCreateInfo createInfo;
|
VkShaderModuleCreateInfo createInfo;
|
||||||
|
|
Loading…
Reference in New Issue