Add TRACEs to backend shader module creation

Specifically ensuring that Tint's generator is individually traced so
that we can better see how much time is going into Tint's transforms
vs the backend's compiler.

Change-Id: I9903cdca137d652ee400e94f0570eeeb17779207
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/76260
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
This commit is contained in:
Brandon Jones 2022-01-13 21:43:26 +00:00 committed by Dawn LUCI CQ
parent bd767283c8
commit 4abe2a0b53
4 changed files with 102 additions and 45 deletions

View File

@ -26,6 +26,8 @@
#include "dawn_native/d3d12/PipelineLayoutD3D12.h"
#include "dawn_native/d3d12/PlatformFunctions.h"
#include "dawn_native/d3d12/UtilsD3D12.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h"
#include <d3dcompiler.h>
@ -596,7 +598,8 @@ namespace dawn::native::d3d12 {
return std::move(compiledShader);
}
ResultOrError<std::string> TranslateToHLSL(const ShaderCompilationRequest& request,
ResultOrError<std::string> TranslateToHLSL(dawn::platform::Platform* platform,
const ShaderCompilationRequest& request,
std::string* remappedEntryPointName) {
std::ostringstream errorStream;
errorStream << "Tint HLSL failure:" << std::endl;
@ -631,9 +634,12 @@ namespace dawn::native::d3d12 {
tint::Program transformedProgram;
tint::transform::DataMap transformOutputs;
DAWN_TRY_ASSIGN(transformedProgram,
RunTransforms(&transformManager, request.program, transformInputs,
&transformOutputs, nullptr));
{
TRACE_EVENT0(platform, General, "RunTransforms");
DAWN_TRY_ASSIGN(transformedProgram,
RunTransforms(&transformManager, request.program, transformInputs,
&transformOutputs, nullptr));
}
if (auto* data = transformOutputs.Get<tint::transform::Renamer::Data>()) {
auto it = data->remappings.find(request.entryPointName);
@ -661,6 +667,7 @@ namespace dawn::native::d3d12 {
// them as well. This would allow us to only upload root constants that are actually
// read by the shader.
options.array_length_from_uniform = request.arrayLengthFromUniform;
TRACE_EVENT0(platform, General, "tint::writer::hlsl::Generate");
auto result = tint::writer::hlsl::Generate(&transformedProgram, options);
DAWN_INVALID_IF(!result.success, "An error occured while generating HLSL: %s",
result.error);
@ -669,7 +676,8 @@ namespace dawn::native::d3d12 {
}
template <typename F>
MaybeError CompileShader(const PlatformFunctions* functions,
MaybeError CompileShader(dawn::platform::Platform* platform,
const PlatformFunctions* functions,
IDxcLibrary* dxcLibrary,
IDxcCompiler* dxcCompiler,
ShaderCompilationRequest&& request,
@ -679,7 +687,7 @@ namespace dawn::native::d3d12 {
// Compile the source shader to HLSL.
std::string hlslSource;
std::string remappedEntryPoint;
DAWN_TRY_ASSIGN(hlslSource, TranslateToHLSL(request, &remappedEntryPoint));
DAWN_TRY_ASSIGN(hlslSource, TranslateToHLSL(platform, request, &remappedEntryPoint));
if (dumpShaders) {
std::ostringstream dumpedMsg;
dumpedMsg << "/* Dumped generated HLSL */" << std::endl << hlslSource;
@ -687,14 +695,18 @@ namespace dawn::native::d3d12 {
}
request.entryPointName = remappedEntryPoint.c_str();
switch (request.compiler) {
case ShaderCompilationRequest::Compiler::DXC:
case ShaderCompilationRequest::Compiler::DXC: {
TRACE_EVENT0(platform, General, "CompileShaderDXC");
DAWN_TRY_ASSIGN(compiledShader->compiledDXCShader,
CompileShaderDXC(dxcLibrary, dxcCompiler, request, hlslSource));
break;
case ShaderCompilationRequest::Compiler::FXC:
}
case ShaderCompilationRequest::Compiler::FXC: {
TRACE_EVENT0(platform, General, "CompileShaderFXC");
DAWN_TRY_ASSIGN(compiledShader->compiledFXCShader,
CompileShaderFXC(functions, request, hlslSource));
break;
}
}
if (dumpShaders && request.compiler == ShaderCompilationRequest::Compiler::FXC) {
@ -743,7 +755,9 @@ namespace dawn::native::d3d12 {
SingleShaderStage stage,
PipelineLayout* layout,
uint32_t compileFlags) {
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "ShaderModuleD3D12::Compile");
ASSERT(!IsError());
ScopedTintICEHandler scopedICEHandler(GetDevice());
Device* device = ToBackend(GetDevice());
@ -799,7 +813,7 @@ namespace dawn::native::d3d12 {
device->GetPersistentCache()->GetOrCreate(
shaderCacheKey, [&](auto doCache) -> MaybeError {
DAWN_TRY(CompileShader(
device->GetFunctions(),
device->GetPlatform(), device->GetFunctions(),
device->IsToggleEnabled(Toggle::UseDXC) ? device->GetDxcLibrary().Get()
: nullptr,
device->IsToggleEnabled(Toggle::UseDXC) ? device->GetDxcCompiler().Get()

View File

@ -19,6 +19,8 @@
#include "dawn_native/metal/DeviceMTL.h"
#include "dawn_native/metal/PipelineLayoutMTL.h"
#include "dawn_native/metal/RenderPipelineMTL.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h"
#include <tint/tint.h>
@ -132,8 +134,11 @@ namespace dawn::native::metal {
tint::Program program;
tint::transform::DataMap transformOutputs;
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
&transformOutputs, nullptr));
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "RunTransforms");
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(),
transformInputs, &transformOutputs, nullptr));
}
if (auto* data = transformOutputs.Get<tint::transform::Renamer::Data>()) {
auto it = data->remappings.find(entryPointName);
@ -156,6 +161,7 @@ namespace dawn::native::metal {
options.emit_vertex_point_size =
stage == SingleShaderStage::Vertex &&
renderPipeline->GetPrimitiveTopology() == wgpu::PrimitiveTopology::PointList;
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "tint::writer::msl::Generate");
auto result = tint::writer::msl::Generate(&program, options);
DAWN_INVALID_IF(!result.success, "An error occured while generating MSL: %s.",
result.error);
@ -174,6 +180,8 @@ namespace dawn::native::metal {
id constantValuesPointer,
uint32_t sampleMask,
const RenderPipeline* renderPipeline) {
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "ShaderModuleMTL::CreateFunction");
ASSERT(!IsError());
ASSERT(out);
@ -216,10 +224,15 @@ namespace dawn::native::metal {
}
auto mtlDevice = ToBackend(GetDevice())->GetMTLDevice();
NSError* error = nullptr;
NSPRef<id<MTLLibrary>> library =
AcquireNSPRef([mtlDevice newLibraryWithSource:mslSource.Get()
options:compileOptions.Get()
error:&error]);
NSPRef<id<MTLLibrary>> library;
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "MTLDevice::newLibraryWithSource");
library = AcquireNSPRef([mtlDevice newLibraryWithSource:mslSource.Get()
options:compileOptions.Get()
error:&error]);
}
if (error != nullptr) {
DAWN_INVALID_IF(error.code != MTLLibraryErrorCompileWarning,
"Unable to create library object: %s.",
@ -230,24 +243,27 @@ namespace dawn::native::metal {
NSRef<NSString> name =
AcquireNSRef([[NSString alloc] initWithUTF8String:remappedEntryPointName.c_str()]);
if (constantValuesPointer != nil) {
if (@available(macOS 10.12, *)) {
MTLFunctionConstantValues* constantValues = constantValuesPointer;
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()
constantValues:constantValues
error:&error]);
if (error != nullptr) {
if (error.code != MTLLibraryErrorCompileWarning) {
return DAWN_VALIDATION_ERROR(std::string("Function compile error: ") +
[error.localizedDescription UTF8String]);
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "MTLLibrary::newFunctionWithName");
if (constantValuesPointer != nil) {
if (@available(macOS 10.12, *)) {
MTLFunctionConstantValues* constantValues = constantValuesPointer;
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()
constantValues:constantValues
error:&error]);
if (error != nullptr) {
if (error.code != MTLLibraryErrorCompileWarning) {
return DAWN_VALIDATION_ERROR(std::string("Function compile error: ") +
[error.localizedDescription UTF8String]);
}
}
ASSERT(out->function != nil);
} else {
UNREACHABLE();
}
ASSERT(out->function != nil);
} else {
UNREACHABLE();
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()]);
}
} else {
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()]);
}
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&

View File

@ -22,6 +22,8 @@
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/opengl/PipelineLayoutGL.h"
#include "dawn_native/opengl/SpirvUtils.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h"
#include <spirv_glsl.hpp>
@ -265,23 +267,32 @@ namespace dawn::native::opengl {
CombinedSamplerInfo* combinedSamplers,
const PipelineLayout* layout,
bool* needsDummySampler) const {
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "TranslateToGLSL");
tint::transform::SingleEntryPoint singleEntryPointTransform;
tint::transform::DataMap transformInputs;
transformInputs.Add<tint::transform::SingleEntryPoint::Config>(entryPointName);
tint::Program program;
DAWN_TRY_ASSIGN(program, RunTransforms(&singleEntryPointTransform, GetTintProgram(),
transformInputs, nullptr, nullptr));
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "RunTransforms");
DAWN_TRY_ASSIGN(program, RunTransforms(&singleEntryPointTransform, GetTintProgram(),
transformInputs, nullptr, nullptr));
}
tint::writer::spirv::Options tintOptions;
tintOptions.disable_workgroup_init =
GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
auto result = tint::writer::spirv::Generate(&program, tintOptions);
DAWN_INVALID_IF(!result.success, "An error occured while generating SPIR-V: %s.",
result.error);
std::vector<uint32_t> spirv;
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "tint::writer::spirv::Generate");
auto result = tint::writer::spirv::Generate(&program, tintOptions);
DAWN_INVALID_IF(!result.success, "An error occured while generating SPIR-V: %s.",
result.error);
spirv = std::move(result.spirv);
}
std::vector<uint32_t> spirv = std::move(result.spirv);
DAWN_TRY(
ValidateSpirv(GetDevice(), spirv, GetDevice()->IsToggleEnabled(Toggle::DumpShaders)));

View File

@ -22,6 +22,8 @@
#include "dawn_native/vulkan/PipelineLayoutVk.h"
#include "dawn_native/vulkan/UtilsVulkan.h"
#include "dawn_native/vulkan/VulkanError.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h"
#include <tint/tint.h>
#include <spirv-tools/libspirv.hpp>
@ -110,6 +112,9 @@ namespace dawn::native::vulkan {
ResultOrError<VkShaderModule> ShaderModule::GetTransformedModuleHandle(
const char* entryPointName,
PipelineLayout* layout) {
TRACE_EVENT0(GetDevice()->GetPlatform(), General,
"ShaderModuleVk::GetTransformedModuleHandle");
// If the shader was destroyed, we should never call this function.
ASSERT(IsAlive());
@ -161,17 +166,26 @@ namespace dawn::native::vulkan {
transformInputs.Add<tint::transform::SingleEntryPoint::Config>(entryPointName);
tint::Program program;
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
nullptr, nullptr));
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "RunTransforms");
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(),
transformInputs, nullptr, nullptr));
}
tint::writer::spirv::Options options;
options.emit_vertex_point_size = true;
options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
auto result = tint::writer::spirv::Generate(&program, options);
DAWN_INVALID_IF(!result.success, "An error occured while generating SPIR-V: %s.",
result.error);
std::vector<uint32_t> spirv = std::move(result.spirv);
std::vector<uint32_t> spirv;
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "tint::writer::spirv::Generate()");
auto result = tint::writer::spirv::Generate(&program, options);
DAWN_INVALID_IF(!result.success, "An error occured while generating SPIR-V: %s.",
result.error);
spirv = std::move(result.spirv);
}
DAWN_TRY(
ValidateSpirv(GetDevice(), spirv, GetDevice()->IsToggleEnabled(Toggle::DumpShaders)));
@ -185,10 +199,12 @@ namespace dawn::native::vulkan {
Device* device = ToBackend(GetDevice());
VkShaderModule newHandle = VK_NULL_HANDLE;
DAWN_TRY(CheckVkSuccess(
device->fn.CreateShaderModule(device->GetVkDevice(), &createInfo, nullptr, &*newHandle),
"CreateShaderModule"));
{
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "vkCreateShaderModule");
DAWN_TRY(CheckVkSuccess(device->fn.CreateShaderModule(
device->GetVkDevice(), &createInfo, nullptr, &*newHandle),
"CreateShaderModule"));
}
if (newHandle != VK_NULL_HANDLE) {
newHandle =
mTransformedShaderModuleCache->AddOrGetCachedShaderModule(cacheKey, newHandle);