D3D12: Move transform/FirstIndexOffset outside of TranslateToHLSL
This is a minor refactor that runs transform/FirstIndexOffset in a separate pass, outside of TranslateToHLSL. It should be functionally the same as what currently exists. This is to prepare for creating pipeline cache keys based on the WGSL. Bug: dawn:1103 Change-Id: Ifc516079bafe2449d422f8bd8485b2459cd3d181 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/63224 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Michael Tang <tangm@microsoft.com>
This commit is contained in:
parent
fa9ca4482a
commit
0a4cb8d859
|
@ -181,11 +181,11 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::string> ShaderModule::TranslateToHLSL(
|
ResultOrError<std::string> ShaderModule::TranslateToHLSL(
|
||||||
|
const tint::Program* program,
|
||||||
const char* entryPointName,
|
const char* entryPointName,
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
PipelineLayout* layout,
|
PipelineLayout* layout,
|
||||||
std::string* remappedEntryPointName,
|
std::string* remappedEntryPointName) const {
|
||||||
FirstOffsetInfo* firstOffsetInfo) const {
|
|
||||||
ASSERT(!IsError());
|
ASSERT(!IsError());
|
||||||
|
|
||||||
ScopedTintICEHandler scopedICEHandler(GetDevice());
|
ScopedTintICEHandler scopedICEHandler(GetDevice());
|
||||||
|
@ -244,17 +244,6 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
transformManager.Add<tint::transform::BindingRemapper>();
|
transformManager.Add<tint::transform::BindingRemapper>();
|
||||||
|
|
||||||
// The FirstIndexOffset transform must be done after the BindingRemapper because it assumes
|
|
||||||
// that the register space has already flattened (and uses the next register). Otherwise
|
|
||||||
// intermediate ASTs can be produced where the extra registers conflict with one of the
|
|
||||||
// user-declared bind points.
|
|
||||||
if (stage == SingleShaderStage::Vertex) {
|
|
||||||
transformManager.Add<tint::transform::FirstIndexOffset>();
|
|
||||||
transformInputs.Add<tint::transform::FirstIndexOffset::BindingPoint>(
|
|
||||||
layout->GetFirstIndexOffsetShaderRegister(),
|
|
||||||
layout->GetFirstIndexOffsetRegisterSpace());
|
|
||||||
}
|
|
||||||
|
|
||||||
transformManager.Add<tint::transform::Renamer>();
|
transformManager.Add<tint::transform::Renamer>();
|
||||||
|
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming)) {
|
if (GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming)) {
|
||||||
|
@ -269,21 +258,11 @@ namespace dawn_native { namespace d3d12 {
|
||||||
transformInputs.Add<BindingRemapper::Remappings>(std::move(bindingPoints),
|
transformInputs.Add<BindingRemapper::Remappings>(std::move(bindingPoints),
|
||||||
std::move(accessControls), mayCollide);
|
std::move(accessControls), mayCollide);
|
||||||
|
|
||||||
tint::Program program;
|
tint::Program transformedProgram;
|
||||||
tint::transform::DataMap transformOutputs;
|
tint::transform::DataMap transformOutputs;
|
||||||
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
DAWN_TRY_ASSIGN(
|
||||||
&transformOutputs, nullptr));
|
transformedProgram,
|
||||||
|
RunTransforms(&transformManager, program, transformInputs, &transformOutputs, nullptr));
|
||||||
if (auto* data = transformOutputs.Get<tint::transform::FirstIndexOffset::Data>()) {
|
|
||||||
firstOffsetInfo->usesVertexIndex = data->has_vertex_index;
|
|
||||||
if (firstOffsetInfo->usesVertexIndex) {
|
|
||||||
firstOffsetInfo->vertexIndexOffset = data->first_vertex_offset;
|
|
||||||
}
|
|
||||||
firstOffsetInfo->usesInstanceIndex = data->has_instance_index;
|
|
||||||
if (firstOffsetInfo->usesInstanceIndex) {
|
|
||||||
firstOffsetInfo->instanceIndexOffset = data->first_instance_offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto* data = transformOutputs.Get<tint::transform::Renamer::Data>()) {
|
if (auto* data = transformOutputs.Get<tint::transform::Renamer::Data>()) {
|
||||||
auto it = data->remappings.find(entryPointName);
|
auto it = data->remappings.find(entryPointName);
|
||||||
|
@ -302,7 +281,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
tint::writer::hlsl::Options options;
|
tint::writer::hlsl::Options options;
|
||||||
options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
|
options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
|
||||||
auto result = tint::writer::hlsl::Generate(&program, options);
|
auto result = tint::writer::hlsl::Generate(&transformedProgram, options);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
errorStream << "Generator: " << result.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());
|
||||||
|
@ -317,13 +296,48 @@ namespace dawn_native { namespace d3d12 {
|
||||||
uint32_t compileFlags) {
|
uint32_t compileFlags) {
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
|
||||||
|
CompiledShader compiledShader = {};
|
||||||
|
|
||||||
|
tint::transform::Manager transformManager;
|
||||||
|
tint::transform::DataMap transformInputs;
|
||||||
|
|
||||||
|
const tint::Program* program;
|
||||||
|
tint::Program programAsValue;
|
||||||
|
if (stage == SingleShaderStage::Vertex) {
|
||||||
|
transformManager.Add<tint::transform::FirstIndexOffset>();
|
||||||
|
transformInputs.Add<tint::transform::FirstIndexOffset::BindingPoint>(
|
||||||
|
layout->GetFirstIndexOffsetShaderRegister(),
|
||||||
|
layout->GetFirstIndexOffsetRegisterSpace());
|
||||||
|
|
||||||
|
tint::transform::DataMap transformOutputs;
|
||||||
|
DAWN_TRY_ASSIGN(programAsValue,
|
||||||
|
RunTransforms(&transformManager, GetTintProgram(), transformInputs,
|
||||||
|
&transformOutputs, nullptr));
|
||||||
|
|
||||||
|
if (auto* data = transformOutputs.Get<tint::transform::FirstIndexOffset::Data>()) {
|
||||||
|
// TODO(dawn:549): Consider adding this information to the pipeline cache once we
|
||||||
|
// can store more than the shader blob in it.
|
||||||
|
compiledShader.firstOffsetInfo.usesVertexIndex = data->has_vertex_index;
|
||||||
|
if (compiledShader.firstOffsetInfo.usesVertexIndex) {
|
||||||
|
compiledShader.firstOffsetInfo.vertexIndexOffset = data->first_vertex_offset;
|
||||||
|
}
|
||||||
|
compiledShader.firstOffsetInfo.usesInstanceIndex = data->has_instance_index;
|
||||||
|
if (compiledShader.firstOffsetInfo.usesInstanceIndex) {
|
||||||
|
compiledShader.firstOffsetInfo.instanceIndexOffset =
|
||||||
|
data->first_instance_offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
program = &programAsValue;
|
||||||
|
} else {
|
||||||
|
program = GetTintProgram();
|
||||||
|
}
|
||||||
|
|
||||||
// Compile the source shader to HLSL.
|
// Compile the source shader to HLSL.
|
||||||
std::string hlslSource;
|
std::string hlslSource;
|
||||||
std::string remappedEntryPoint;
|
std::string remappedEntryPoint;
|
||||||
CompiledShader compiledShader = {};
|
DAWN_TRY_ASSIGN(hlslSource, TranslateToHLSL(program, entryPointName, stage, layout,
|
||||||
DAWN_TRY_ASSIGN(hlslSource,
|
&remappedEntryPoint));
|
||||||
TranslateToHLSL(entryPointName, stage, layout, &remappedEntryPoint,
|
|
||||||
&compiledShader.firstOffsetInfo));
|
|
||||||
entryPointName = remappedEntryPoint.c_str();
|
entryPointName = remappedEntryPoint.c_str();
|
||||||
|
|
||||||
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
|
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
|
||||||
|
|
|
@ -59,11 +59,11 @@ namespace dawn_native { namespace d3d12 {
|
||||||
~ShaderModule() override = default;
|
~ShaderModule() override = default;
|
||||||
MaybeError Initialize(ShaderModuleParseResult* parseResult);
|
MaybeError Initialize(ShaderModuleParseResult* parseResult);
|
||||||
|
|
||||||
ResultOrError<std::string> TranslateToHLSL(const char* entryPointName,
|
ResultOrError<std::string> TranslateToHLSL(const tint::Program* program,
|
||||||
|
const char* entryPointName,
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
PipelineLayout* layout,
|
PipelineLayout* layout,
|
||||||
std::string* remappedEntryPointName,
|
std::string* remappedEntryPointName) const;
|
||||||
FirstOffsetInfo* firstOffsetInfo) const;
|
|
||||||
|
|
||||||
ResultOrError<PersistentCacheKey> CreateHLSLKey(const char* entryPointName,
|
ResultOrError<PersistentCacheKey> CreateHLSLKey(const char* entryPointName,
|
||||||
SingleShaderStage stage,
|
SingleShaderStage stage,
|
||||||
|
|
Loading…
Reference in New Issue