Change EliminateDeadInputComponentsPass to EliminateDeadIOComponentsPass (#4997)

To reflect processing of both Input and Output variables.

Also renamed files as needed.
This commit is contained in:
Greg Fischer 2022-11-25 16:48:13 -07:00 коммит произвёл GitHub
Родитель 9a6f4121f4
Коммит 00018e58af
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 95 добавлений и 90 удалений

Просмотреть файл

@ -111,7 +111,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/eliminate_dead_constant_pass.cpp \
source/opt/eliminate_dead_functions_pass.cpp \
source/opt/eliminate_dead_functions_util.cpp \
source/opt/eliminate_dead_input_components_pass.cpp \
source/opt/eliminate_dead_io_components_pass.cpp \
source/opt/eliminate_dead_members_pass.cpp \
source/opt/eliminate_dead_output_stores_pass.cpp \
source/opt/feature_manager.cpp \

Просмотреть файл

@ -632,8 +632,8 @@ static_library("spvtools_opt") {
"source/opt/eliminate_dead_functions_pass.h",
"source/opt/eliminate_dead_functions_util.cpp",
"source/opt/eliminate_dead_functions_util.h",
"source/opt/eliminate_dead_input_components_pass.cpp",
"source/opt/eliminate_dead_input_components_pass.h",
"source/opt/eliminate_dead_io_components_pass.cpp",
"source/opt/eliminate_dead_io_components_pass.h",
"source/opt/eliminate_dead_members_pass.cpp",
"source/opt/eliminate_dead_members_pass.h",
"source/opt/eliminate_dead_output_stores_pass.cpp",

Просмотреть файл

@ -47,7 +47,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
eliminate_dead_constant_pass.h
eliminate_dead_functions_pass.h
eliminate_dead_functions_util.h
eliminate_dead_input_components_pass.h
eliminate_dead_io_components_pass.h
eliminate_dead_members_pass.h
eliminate_dead_output_stores_pass.h
empty_pass.h
@ -166,7 +166,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
eliminate_dead_constant_pass.cpp
eliminate_dead_functions_pass.cpp
eliminate_dead_functions_util.cpp
eliminate_dead_input_components_pass.cpp
eliminate_dead_io_components_pass.cpp
eliminate_dead_members_pass.cpp
eliminate_dead_output_stores_pass.cpp
feature_manager.cpp

Просмотреть файл

@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "source/opt/eliminate_dead_input_components_pass.h"
#include "source/opt/eliminate_dead_io_components_pass.h"
#include <set>
#include <vector>
@ -32,10 +32,22 @@ constexpr uint32_t kAccessChainIndex1InIdx = 2;
constexpr uint32_t kConstantValueInIdx = 0;
} // namespace
Pass::Status EliminateDeadInputComponentsPass::Process() {
// Process non-vertex only if explicitly allowed.
Pass::Status EliminateDeadIOComponentsPass::Process() {
// Only process input and output variables
if (elim_sclass_ != spv::StorageClass::Input &&
elim_sclass_ != spv::StorageClass::Output) {
if (consumer()) {
std::string message =
"EliminateDeadIOComponentsPass only valid for input and output "
"variables.";
consumer()(SPV_MSG_ERROR, 0, {0, 0, 0}, message.c_str());
}
return Status::Failure;
}
// If safe mode, only process Input variables in vertex shader
const auto stage = context()->GetStage();
if (stage != spv::ExecutionModel::Vertex && vertex_shader_only_)
if (safe_mode_ && !(stage == spv::ExecutionModel::Vertex &&
elim_sclass_ == spv::StorageClass::Input))
return Status::SuccessWithoutChange;
// Current functionality assumes shader capability.
if (!context()->get_feature_mgr()->HasCapability(spv::Capability::Shader))
@ -62,14 +74,8 @@ Pass::Status EliminateDeadInputComponentsPass::Process() {
continue;
}
const auto sclass = ptr_type->storage_class();
if (output_instead_) {
if (sclass != spv::StorageClass::Output) {
continue;
}
} else {
if (sclass != spv::StorageClass::Input) {
continue;
}
if (sclass != elim_sclass_) {
continue;
}
// For tesc, or input variables in tese or geom shaders,
// there is a outer per-vertex-array that must be ignored
@ -137,7 +143,7 @@ Pass::Status EliminateDeadInputComponentsPass::Process() {
return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
}
unsigned EliminateDeadInputComponentsPass::FindMaxIndex(
unsigned EliminateDeadIOComponentsPass::FindMaxIndex(
const Instruction& var, const unsigned original_max,
const bool skip_first_index) {
unsigned max = 0;
@ -182,8 +188,8 @@ unsigned EliminateDeadInputComponentsPass::FindMaxIndex(
return seen_non_const_ac ? original_max : max;
}
void EliminateDeadInputComponentsPass::ChangeArrayLength(Instruction& arr_var,
unsigned length) {
void EliminateDeadIOComponentsPass::ChangeArrayLength(Instruction& arr_var,
unsigned length) {
analysis::TypeManager* type_mgr = context()->get_type_mgr();
analysis::ConstantManager* const_mgr = context()->get_constant_mgr();
analysis::DefUseManager* def_use_mgr = context()->get_def_use_mgr();
@ -202,8 +208,8 @@ void EliminateDeadInputComponentsPass::ChangeArrayLength(Instruction& arr_var,
def_use_mgr->AnalyzeInstUse(&arr_var);
}
void EliminateDeadInputComponentsPass::ChangeIOVarStructLength(
Instruction& io_var, unsigned length) {
void EliminateDeadIOComponentsPass::ChangeIOVarStructLength(Instruction& io_var,
unsigned length) {
analysis::TypeManager* type_mgr = context()->get_type_mgr();
analysis::Pointer* ptr_type =
type_mgr->GetType(io_var.type_id())->AsPointer();
@ -235,9 +241,7 @@ void EliminateDeadInputComponentsPass::ChangeIOVarStructLength(
analysis::Array new_arr_ty(reg_new_var_ty, arr_type->length_info());
reg_new_var_ty = type_mgr->GetRegisteredType(&new_arr_ty);
}
auto sclass =
output_instead_ ? spv::StorageClass::Output : spv::StorageClass::Input;
analysis::Pointer new_ptr_ty(reg_new_var_ty, sclass);
analysis::Pointer new_ptr_ty(reg_new_var_ty, elim_sclass_);
analysis::Type* reg_new_ptr_ty = type_mgr->GetRegisteredType(&new_ptr_ty);
uint32_t new_ptr_ty_id = type_mgr->GetTypeInstruction(reg_new_ptr_ty);
io_var.SetResultType(new_ptr_ty_id);

Просмотреть файл

@ -26,12 +26,11 @@ namespace spvtools {
namespace opt {
// See optimizer.hpp for documentation.
class EliminateDeadInputComponentsPass : public Pass {
class EliminateDeadIOComponentsPass : public Pass {
public:
explicit EliminateDeadInputComponentsPass(bool output_instead = false,
bool vertex_shader_only = true)
: output_instead_(output_instead),
vertex_shader_only_(vertex_shader_only) {}
explicit EliminateDeadIOComponentsPass(spv::StorageClass elim_sclass,
bool safe_mode = true)
: elim_sclass_(elim_sclass), safe_mode_(safe_mode) {}
const char* name() const override {
return "eliminate-dead-input-components";
@ -62,11 +61,12 @@ class EliminateDeadInputComponentsPass : public Pass {
// is either the struct or a per-vertex-array of the struct.
void ChangeIOVarStructLength(Instruction& io_var, unsigned length);
// Process output variables instead
bool output_instead_;
// Storage class to be optimized. Must be Input or Output.
spv::StorageClass elim_sclass_;
// Only process vertex shaders
bool vertex_shader_only_;
// Only make changes that will not cause interface incompatibility if done
// standalone. Currently this is only Input variables in vertex shaders.
bool safe_mode_;
};
} // namespace opt

Просмотреть файл

@ -1013,19 +1013,20 @@ Optimizer::PassToken CreateInterpolateFixupPass() {
Optimizer::PassToken CreateEliminateDeadInputComponentsPass() {
return MakeUnique<Optimizer::PassToken::Impl>(
MakeUnique<opt::EliminateDeadInputComponentsPass>(
/* output_instead */ false, /* vertex_shader_only */ false));
MakeUnique<opt::EliminateDeadIOComponentsPass>(spv::StorageClass::Input,
/* safe_mode */ false));
}
Optimizer::PassToken CreateEliminateDeadOutputComponentsPass() {
return MakeUnique<Optimizer::PassToken::Impl>(
MakeUnique<opt::EliminateDeadInputComponentsPass>(
/* output_instead */ true, /* vertex_shader_only */ false));
MakeUnique<opt::EliminateDeadIOComponentsPass>(spv::StorageClass::Output,
/* safe_mode */ false));
}
Optimizer::PassToken CreateEliminateDeadInputComponentsSafePass() {
return MakeUnique<Optimizer::PassToken::Impl>(
MakeUnique<opt::EliminateDeadInputComponentsPass>());
MakeUnique<opt::EliminateDeadIOComponentsPass>(spv::StorageClass::Input,
/* safe_mode */ true));
}
Optimizer::PassToken CreateAnalyzeLiveInputPass(

Просмотреть файл

@ -35,7 +35,7 @@
#include "source/opt/desc_sroa.h"
#include "source/opt/eliminate_dead_constant_pass.h"
#include "source/opt/eliminate_dead_functions_pass.h"
#include "source/opt/eliminate_dead_input_components_pass.h"
#include "source/opt/eliminate_dead_io_components_pass.h"
#include "source/opt/eliminate_dead_members_pass.h"
#include "source/opt/eliminate_dead_output_stores_pass.h"
#include "source/opt/empty_pass.h"

Просмотреть файл

@ -43,7 +43,7 @@ add_spvtools_unittest(TARGET opt
desc_sroa_test.cpp
eliminate_dead_const_test.cpp
eliminate_dead_functions_test.cpp
eliminate_dead_input_components_test.cpp
eliminate_dead_io_components_test.cpp
eliminate_dead_member_test.cpp
eliminate_dead_output_stores_test.cpp
feature_manager_test.cpp

Просмотреть файл

@ -23,9 +23,9 @@ namespace spvtools {
namespace opt {
namespace {
using ElimDeadInputComponentsTest = PassTest<::testing::Test>;
using ElimDeadIOComponentsTest = PassTest<::testing::Test>;
TEST_F(ElimDeadInputComponentsTest, ElimOneConstantIndex) {
TEST_F(ElimDeadIOComponentsTest, ElimOneConstantIndex) {
// Should reduce to uv[2]
//
// #version 450
@ -85,11 +85,11 @@ TEST_F(ElimDeadInputComponentsTest, ElimOneConstantIndex) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, ElimOneConstantIndexInBounds) {
TEST_F(ElimDeadIOComponentsTest, ElimOneConstantIndexInBounds) {
// Same as ElimOneConstantIndex but with OpInBoundsAccessChain
const std::string text = R"(
OpCapability Shader
@ -136,11 +136,11 @@ TEST_F(ElimDeadInputComponentsTest, ElimOneConstantIndexInBounds) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, ElimTwoConstantIndices) {
TEST_F(ElimDeadIOComponentsTest, ElimTwoConstantIndices) {
// Should reduce to uv[4]
//
// #version 450
@ -204,11 +204,11 @@ TEST_F(ElimDeadInputComponentsTest, ElimTwoConstantIndices) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, NoElimMaxConstantIndex) {
TEST_F(ElimDeadIOComponentsTest, NoElimMaxConstantIndex) {
// Should not reduce uv[8] because of max index of 7
//
// #version 450
@ -271,11 +271,11 @@ TEST_F(ElimDeadInputComponentsTest, NoElimMaxConstantIndex) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, NoElimNonConstantIndex) {
TEST_F(ElimDeadIOComponentsTest, NoElimNonConstantIndex) {
// Should not reduce uv[8] because of non-constant index of ui
//
// #version 450
@ -354,11 +354,11 @@ TEST_F(ElimDeadInputComponentsTest, NoElimNonConstantIndex) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, NoElimNonIndexedAccessChain) {
TEST_F(ElimDeadIOComponentsTest, NoElimNonIndexedAccessChain) {
// Should not change due to non-indexed access chain
const std::string text = R"(
OpCapability Shader
@ -401,11 +401,11 @@ TEST_F(ElimDeadInputComponentsTest, NoElimNonIndexedAccessChain) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, ElimStructMember) {
TEST_F(ElimDeadIOComponentsTest, ElimStructMember) {
// Should eliminate uv
//
// #version 450
@ -466,11 +466,11 @@ TEST_F(ElimDeadInputComponentsTest, ElimStructMember) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, ElimOutputStructMember) {
TEST_F(ElimDeadIOComponentsTest, ElimOutputStructMember) {
// Should eliminate uv from Vertex and all but gl_Position from gl_PerVertex
//
// #version 450
@ -565,11 +565,11 @@ TEST_F(ElimDeadInputComponentsTest, ElimOutputStructMember) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, true,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Output, false);
}
TEST_F(ElimDeadInputComponentsTest, ElimOutputArrayMembers) {
TEST_F(ElimDeadIOComponentsTest, ElimOutputArrayMembers) {
// Should reduce to uv[2]
//
// #version 450
@ -618,11 +618,11 @@ TEST_F(ElimDeadInputComponentsTest, ElimOutputArrayMembers) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, true,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Output, false);
}
TEST_F(ElimDeadInputComponentsTest, VertexOnly) {
TEST_F(ElimDeadIOComponentsTest, VertexOnly) {
// Should NOT eliminate uv
//
// #version 450
@ -682,11 +682,11 @@ TEST_F(ElimDeadInputComponentsTest, VertexOnly) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
true);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, true);
}
TEST_F(ElimDeadInputComponentsTest, TescInput) {
TEST_F(ElimDeadIOComponentsTest, TescInput) {
// Eliminate PointSize, ClipDistance, CullDistance from gl_in[]
//
// #version 450
@ -771,11 +771,11 @@ TEST_F(ElimDeadInputComponentsTest, TescInput) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, TescOutput) {
TEST_F(ElimDeadIOComponentsTest, TescOutput) {
// Eliminate PointSize, ClipDistance, CullDistance from gl_out[]
//
// #version 450
@ -859,11 +859,11 @@ TEST_F(ElimDeadInputComponentsTest, TescOutput) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, true,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Output, false);
}
TEST_F(ElimDeadInputComponentsTest, TeseInput) {
TEST_F(ElimDeadIOComponentsTest, TeseInput) {
// Eliminate PointSize, ClipDistance, CullDistance from gl_in[]
//
// #version 450
@ -946,11 +946,11 @@ TEST_F(ElimDeadInputComponentsTest, TeseInput) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, TeseOutput) {
TEST_F(ElimDeadIOComponentsTest, TeseOutput) {
// Eliminate PointSize, ClipDistance, CullDistance from gl_out
//
// #version 450
@ -1030,11 +1030,11 @@ TEST_F(ElimDeadInputComponentsTest, TeseOutput) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, true,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Output, false);
}
TEST_F(ElimDeadInputComponentsTest, GeomInput) {
TEST_F(ElimDeadIOComponentsTest, GeomInput) {
// Eliminate PointSize, ClipDistance, CullDistance from gl_in[]
//
// #version 450
@ -1138,11 +1138,11 @@ TEST_F(ElimDeadInputComponentsTest, GeomInput) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, false,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Input, false);
}
TEST_F(ElimDeadInputComponentsTest, GeomOutput) {
TEST_F(ElimDeadIOComponentsTest, GeomOutput) {
// Eliminate PointSize, ClipDistance, CullDistance from gl_out
//
// #version 450
@ -1245,8 +1245,8 @@ TEST_F(ElimDeadInputComponentsTest, GeomOutput) {
SetTargetEnv(SPV_ENV_VULKAN_1_3);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<EliminateDeadInputComponentsPass>(text, true, true,
false);
SinglePassRunAndMatch<EliminateDeadIOComponentsPass>(
text, true, spv::StorageClass::Output, false);
}
} // namespace