Skip to content

Commit 887fda5

Browse files
committed
[SPIR-V] Remove temp reserve for 4 or less elements
1 parent 75d8052 commit 887fda5

6 files changed

+0
-212
lines changed

src/xenia/gpu/spirv_shader_translator.cc

-27
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,19 @@ void SpirvShaderTranslator::StartTranslation() {
197197

198198
const_int_0_ = builder_->makeIntConstant(0);
199199
id_vector_temp_.clear();
200-
id_vector_temp_.reserve(4);
201200
for (uint32_t i = 0; i < 4; ++i) {
202201
id_vector_temp_.push_back(const_int_0_);
203202
}
204203
const_int4_0_ = builder_->makeCompositeConstant(type_int4_, id_vector_temp_);
205204
const_uint_0_ = builder_->makeUintConstant(0);
206205
id_vector_temp_.clear();
207-
id_vector_temp_.reserve(4);
208206
for (uint32_t i = 0; i < 4; ++i) {
209207
id_vector_temp_.push_back(const_uint_0_);
210208
}
211209
const_uint4_0_ =
212210
builder_->makeCompositeConstant(type_uint4_, id_vector_temp_);
213211
const_float_0_ = builder_->makeFloatConstant(0.0f);
214212
id_vector_temp_.clear();
215-
id_vector_temp_.reserve(4);
216213
id_vector_temp_.push_back(const_float_0_);
217214
for (uint32_t i = 1; i < 4; ++i) {
218215
id_vector_temp_.push_back(const_float_0_);
@@ -221,15 +218,13 @@ void SpirvShaderTranslator::StartTranslation() {
221218
}
222219
const_float_1_ = builder_->makeFloatConstant(1.0f);
223220
id_vector_temp_.clear();
224-
id_vector_temp_.reserve(4);
225221
id_vector_temp_.push_back(const_float_1_);
226222
for (uint32_t i = 1; i < 4; ++i) {
227223
id_vector_temp_.push_back(const_float_1_);
228224
const_float_vectors_1_[i] = builder_->makeCompositeConstant(
229225
type_float_vectors_[i], id_vector_temp_);
230226
}
231227
id_vector_temp_.clear();
232-
id_vector_temp_.reserve(2);
233228
id_vector_temp_.push_back(const_float_0_);
234229
id_vector_temp_.push_back(const_float_1_);
235230
const_float2_0_1_ =
@@ -378,7 +373,6 @@ void SpirvShaderTranslator::StartTranslation() {
378373
// vectors instead of scalar arrays because the latter would have padding to
379374
// 16 bytes in each element.
380375
id_vector_temp_.clear();
381-
id_vector_temp_.reserve(2);
382376
// 256 bool constants.
383377
id_vector_temp_.push_back(builder_->makeArrayType(
384378
type_uint4_, builder_->makeUintConstant(2), sizeof(uint32_t) * 4));
@@ -576,7 +570,6 @@ void SpirvShaderTranslator::StartTranslation() {
576570
if (has_main_switch) {
577571
// OpPhi must be the first in the block.
578572
id_vector_temp_.clear();
579-
id_vector_temp_.reserve(4);
580573
id_vector_temp_.push_back(const_int_0_);
581574
id_vector_temp_.push_back(main_loop_pre_header.getId());
582575
main_loop_pc_next_ = builder_->getUniqueId();
@@ -855,7 +848,6 @@ void SpirvShaderTranslator::ProcessLoopStartInstruction(
855848
EnsureBuildPointAvailable();
856849

857850
id_vector_temp_.clear();
858-
id_vector_temp_.reserve(3);
859851
// Loop constants (member 1).
860852
id_vector_temp_.push_back(builder_->makeIntConstant(1));
861853
// 4-component vector.
@@ -882,7 +874,6 @@ void SpirvShaderTranslator::ProcessLoopStartInstruction(
882874
builder_->createTriOp(spv::OpBitFieldUExtract, type_uint_, loop_constant,
883875
const_int_0_, const_int_8);
884876
id_vector_temp_.clear();
885-
id_vector_temp_.reserve(4);
886877
id_vector_temp_.push_back(loop_count_new);
887878
for (unsigned int i = 0; i < 3; ++i) {
888879
id_vector_temp_.push_back(
@@ -897,7 +888,6 @@ void SpirvShaderTranslator::ProcessLoopStartInstruction(
897888
spv::Id address_relative_stack_old =
898889
builder_->createLoad(var_main_loop_address_, spv::NoPrecision);
899890
id_vector_temp_.clear();
900-
id_vector_temp_.reserve(4);
901891
if (instr.is_repeat) {
902892
id_vector_temp_.emplace_back();
903893
} else {
@@ -1017,7 +1007,6 @@ void SpirvShaderTranslator::ProcessLoopEndInstruction(
10171007
// Extract the value to add to aL (signed, in bits 16:23 of the loop
10181008
// constant).
10191009
id_vector_temp_.clear();
1020-
id_vector_temp_.reserve(3);
10211010
// Loop constants (member 1).
10221011
id_vector_temp_.push_back(builder_->makeIntConstant(1));
10231012
// 4-component vector.
@@ -1056,7 +1045,6 @@ void SpirvShaderTranslator::ProcessLoopEndInstruction(
10561045
// Pop the current loop off the loop counter and the relative address stacks -
10571046
// move YZW to XYZ and set W to 0.
10581047
id_vector_temp_.clear();
1059-
id_vector_temp_.reserve(4);
10601048
for (unsigned int i = 1; i < 4; ++i) {
10611049
id_vector_temp_.push_back(
10621050
builder_->createCompositeExtract(loop_count_stack_old, type_uint_, i));
@@ -1066,7 +1054,6 @@ void SpirvShaderTranslator::ProcessLoopEndInstruction(
10661054
builder_->createCompositeConstruct(type_uint4_, id_vector_temp_),
10671055
var_main_loop_count_);
10681056
id_vector_temp_.clear();
1069-
id_vector_temp_.reserve(4);
10701057
for (unsigned int i = 1; i < 4; ++i) {
10711058
id_vector_temp_.push_back(builder_->createCompositeExtract(
10721059
address_relative_stack_old, type_int_, i));
@@ -1240,7 +1227,6 @@ void SpirvShaderTranslator::StartVertexOrTessEvalShaderInMain() {
12401227
// The edge flag isn't used for any purpose by the translator.
12411228
if (current_shader().writes_point_size_edge_flag_kill_vertex() & 0b101) {
12421229
id_vector_temp_.clear();
1243-
id_vector_temp_.reserve(3);
12441230
// Set the point size to a negative value to tell the point sprite expansion
12451231
// that it should use the default point size if the vertex shader does not
12461232
// override it.
@@ -1475,7 +1461,6 @@ void SpirvShaderTranslator::StartVertexOrTessEvalShaderInMain() {
14751461
spv::NoPrecision));
14761462
// Write the index to r0.x as float.
14771463
id_vector_temp_.clear();
1478-
id_vector_temp_.reserve(2);
14791464
id_vector_temp_.push_back(const_int_0_);
14801465
id_vector_temp_.push_back(const_int_0_);
14811466
builder_->createStore(
@@ -1521,7 +1506,6 @@ void SpirvShaderTranslator::CompleteVertexOrTessEvalShaderInMain() {
15211506
// Check if the shader returns XY/W rather than XY, and if it does, revert
15221507
// that.
15231508
uint_vector_temp_.clear();
1524-
uint_vector_temp_.reserve(2);
15251509
uint_vector_temp_.push_back(0);
15261510
uint_vector_temp_.push_back(1);
15271511
spv::Id position_xy = builder_->createRvalueSwizzle(
@@ -1629,7 +1613,6 @@ void SpirvShaderTranslator::CompleteVertexOrTessEvalShaderInMain() {
16291613
// frontFace = VkFrontFace(0), but faceness is ignored for non-polygon
16301614
// primitive types).
16311615
id_vector_temp_.clear();
1632-
id_vector_temp_.reserve(2);
16331616
id_vector_temp_.push_back(builder_->makeUintConstant(0b10));
16341617
id_vector_temp_.push_back(builder_->makeUintConstant(0b01));
16351618
spv::Id point_vertex_positive = builder_->createBinOp(
@@ -1704,7 +1687,6 @@ void SpirvShaderTranslator::CompleteVertexOrTessEvalShaderInMain() {
17041687
spv::DecorationNoContraction);
17051688
// Expand the point sprite.
17061689
uint_vector_temp_.clear();
1707-
uint_vector_temp_.reserve(2);
17081690
uint_vector_temp_.push_back(0);
17091691
uint_vector_temp_.push_back(1);
17101692
spv::Id point_position_xy = builder_->createBinOp(
@@ -2139,7 +2121,6 @@ void SpirvShaderTranslator::StartFragmentShaderInMain() {
21392121
// Saturate to avoid negative point coordinates if the center of the pixel
21402122
// is not covered, and extrapolation is done.
21412123
id_vector_temp_.clear();
2142-
id_vector_temp_.reserve(3);
21432124
id_vector_temp_.push_back(
21442125
builder_->createLoad(input_point_coordinates_, spv::NoPrecision));
21452126
id_vector_temp_.push_back(const_float2_0_);
@@ -2168,7 +2149,6 @@ void SpirvShaderTranslator::StartFragmentShaderInMain() {
21682149
}
21692150
// Store the pixel parameters.
21702151
id_vector_temp_.clear();
2171-
id_vector_temp_.reserve(4);
21722152
id_vector_temp_.push_back(param_gen_x);
21732153
id_vector_temp_.push_back(param_gen_y);
21742154
id_vector_temp_.push_back(param_gen_z);
@@ -2234,7 +2214,6 @@ void SpirvShaderTranslator::UpdateExecConditionals(
22342214
spv::Id condition_id;
22352215
if (type == ParsedExecInstruction::Type::kConditional) {
22362216
id_vector_temp_.clear();
2237-
id_vector_temp_.reserve(3);
22382217
// Bool constants (member 0).
22392218
id_vector_temp_.push_back(const_int_0_);
22402219
// 128-bit vector.
@@ -2865,7 +2844,6 @@ spv::Id SpirvShaderTranslator::EndianSwap32Uint(spv::Id value, spv::Id endian) {
28652844
spv::Id const_uint_8_typed, const_uint_00ff00ff_typed, const_uint_16_typed;
28662845
int num_components = builder_->getNumTypeComponents(type);
28672846
if (num_components > 1) {
2868-
id_vector_temp_.reserve(num_components);
28692847
id_vector_temp_.clear();
28702848
id_vector_temp_.insert(id_vector_temp_.cend(), num_components,
28712849
const_uint_8_scalar);
@@ -2946,7 +2924,6 @@ spv::Id SpirvShaderTranslator::EndianSwap32Uint(spv::Id value, spv::Id endian) {
29462924
&block_16in32_merge);
29472925
builder_->setBuildPoint(&block_16in32);
29482926
id_vector_temp_.clear();
2949-
id_vector_temp_.reserve(4);
29502927
id_vector_temp_.push_back(builder_->createBinOp(
29512928
spv::OpShiftRightLogical, type, value, const_uint_16_typed));
29522929
id_vector_temp_.push_back(value);
@@ -2983,7 +2960,6 @@ spv::Id SpirvShaderTranslator::LoadUint32FromSharedMemory(
29832960
if (!buffer_count_log2) {
29842961
// Single binding - load directly.
29852962
id_vector_temp_.clear();
2986-
id_vector_temp_.reserve(2);
29872963
// The only SSBO struct member.
29882964
id_vector_temp_.push_back(const_int_0_);
29892965
id_vector_temp_.push_back(address_dwords_int);
@@ -3034,7 +3010,6 @@ spv::Id SpirvShaderTranslator::LoadUint32FromSharedMemory(
30343010
for (uint32_t i = 0; i < buffer_count; ++i) {
30353011
builder_->setBuildPoint(switch_case_blocks[i]);
30363012
id_vector_temp_.clear();
3037-
id_vector_temp_.reserve(3);
30383013
id_vector_temp_.push_back(builder_->makeIntConstant(int(i)));
30393014
// The only SSBO struct member.
30403015
id_vector_temp_.push_back(const_int_0_);
@@ -3068,7 +3043,6 @@ spv::Id SpirvShaderTranslator::PWLGammaToLinear(spv::Id gamma,
30683043
if (!gamma_pre_saturated) {
30693044
// Saturate, flushing NaN to 0.
30703045
id_vector_temp_.clear();
3071-
id_vector_temp_.reserve(3);
30723046
id_vector_temp_.push_back(gamma);
30733047
id_vector_temp_.push_back(const_vector_0);
30743048
id_vector_temp_.push_back(const_vector_1);
@@ -3166,7 +3140,6 @@ spv::Id SpirvShaderTranslator::LinearToPWLGamma(spv::Id linear,
31663140
if (!linear_pre_saturated) {
31673141
// Saturate, flushing NaN to 0.
31683142
id_vector_temp_.clear();
3169-
id_vector_temp_.reserve(3);
31703143
id_vector_temp_.push_back(linear);
31713144
id_vector_temp_.push_back(const_vector_0);
31723145
id_vector_temp_.push_back(const_vector_1);

src/xenia/gpu/spirv_shader_translator_alu.cc

-9
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
195195
// Extract the different components, if not all are different.
196196
if (multiplicands_different != used_result_components) {
197197
uint_vector_temp_.clear();
198-
uint_vector_temp_.reserve(different_count);
199198
uint32_t components_remaining = used_result_components;
200199
for (uint32_t i = 0; i < used_result_component_count; ++i) {
201200
uint32_t component;
@@ -231,7 +230,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
231230
instr.vector_operands[i]);
232231
}
233232
id_vector_temp_.clear();
234-
id_vector_temp_.reserve(2);
235233
id_vector_temp_.push_back(different_operands[0]);
236234
id_vector_temp_.push_back(different_operands[1]);
237235
spv::Id different_abs_min =
@@ -315,7 +313,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
315313
builder_->createBuiltinCall(type_float_, ext_inst_glsl_std_450_,
316314
GLSLstd450Floor, id_vector_temp_);
317315
id_vector_temp_.clear();
318-
id_vector_temp_.reserve(3);
319316
id_vector_temp_.push_back(maxa_address);
320317
id_vector_temp_.push_back(builder_->makeFloatConstant(-256.0f));
321318
id_vector_temp_.push_back(builder_->makeFloatConstant(255.0f));
@@ -346,7 +343,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
346343
if (used_result_component_count > 1) {
347344
// Need all but the last (W) element of operand_0 as a vector.
348345
uint_vector_temp_.clear();
349-
uint_vector_temp_.reserve(used_result_component_count);
350346
for (unsigned int i = 0; i < used_result_component_count; ++i) {
351347
uint_vector_temp_.push_back(i);
352348
}
@@ -390,7 +386,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
390386
// Mixed identical and different components.
391387
assert_true(used_result_component_count > 1);
392388
id_vector_temp_.clear();
393-
id_vector_temp_.reserve(used_result_component_count);
394389
uint32_t components_remaining = used_result_components;
395390
for (uint32_t i = 0; i < used_result_component_count; ++i) {
396391
// Composite extraction of operand_0[i] works fine even it's maxa with
@@ -695,7 +690,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
695690
builder_->setBuildPoint(ma_merge_block);
696691
// Choose the result options from Z and YX cases.
697692
id_vector_temp_.clear();
698-
id_vector_temp_.reserve(used_result_component_count);
699693
for (uint32_t i = 0; i < 4; ++i) {
700694
if (!(used_result_components & (1 << i))) {
701695
continue;
@@ -753,7 +747,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
753747
while (xe::bit_scan_forward(components_remaining, &component)) {
754748
components_remaining &= ~(uint32_t(1) << component);
755749
id_vector_temp_.clear();
756-
id_vector_temp_.reserve(2);
757750
id_vector_temp_.push_back(result);
758751
id_vector_temp_.push_back(builder_->createCompositeExtract(
759752
operand, type_float_, static_cast<unsigned int>(component)));
@@ -895,7 +888,6 @@ spv::Id SpirvShaderTranslator::ProcessVectorAluOperation(
895888
}
896889
}
897890
id_vector_temp_.clear();
898-
id_vector_temp_.reserve(used_result_component_count);
899891
if (used_result_components & 0b0001) {
900892
// x = 1.0
901893
id_vector_temp_.push_back(const_float_1_);
@@ -1171,7 +1163,6 @@ spv::Id SpirvShaderTranslator::ProcessScalarAluOperation(
11711163
builder_->createBuiltinCall(type_float_, ext_inst_glsl_std_450_,
11721164
GLSLstd450Floor, id_vector_temp_);
11731165
id_vector_temp_.clear();
1174-
id_vector_temp_.reserve(3);
11751166
id_vector_temp_.push_back(maxa_address);
11761167
id_vector_temp_.push_back(builder_->makeFloatConstant(-256.0f));
11771168
id_vector_temp_.push_back(builder_->makeFloatConstant(255.0f));

0 commit comments

Comments
 (0)