summaryrefslogtreecommitdiff
path: root/spirv_parser.cpp
diff options
context:
space:
mode:
authorHans-Kristian Arntzen <post@arntzen-software.no>2019-04-02 11:19:03 +0200
committerHans-Kristian Arntzen <post@arntzen-software.no>2019-04-09 15:09:44 +0200
commita489ba7fd172966a8960faad4ada01b086c1bf69 (patch)
treebe0123f1108dbfc54d8895f50b3589df973710c4 /spirv_parser.cpp
parentc60b9a1e963c7f399fca070eb414b9323620c99f (diff)
downloadSPIRV-Cross-a489ba7fd172966a8960faad4ada01b086c1bf69.tar.gz
SPIRV-Cross-a489ba7fd172966a8960faad4ada01b086c1bf69.tar.bz2
SPIRV-Cross-a489ba7fd172966a8960faad4ada01b086c1bf69.zip
Reduce pressure on global allocation.
- Replace ostringstream with custom implementation. ~30% performance uplift on vector-shuffle-oom test. Allocations are measurably reduced in Valgrind. - Replace std::vector with SmallVector. Classic malloc optimization, small vectors are backed by inline data. ~ 7-8% gain on vector-shuffle-oom on GCC 8 on Linux. - Use an object pool for IVariant type. We generally allocate a lot of SPIR* objects. We can amortize these allocations neatly by pooling them. - ~15% overall uplift on ./test_shaders.py --iterations 10000 shaders/.
Diffstat (limited to 'spirv_parser.cpp')
-rw-r--r--spirv_parser.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/spirv_parser.cpp b/spirv_parser.cpp
index 96481d5e..c5159102 100644
--- a/spirv_parser.cpp
+++ b/spirv_parser.cpp
@@ -22,14 +22,14 @@ using namespace spv;
namespace SPIRV_CROSS_NAMESPACE
{
-Parser::Parser(std::vector<uint32_t> spirv)
+Parser::Parser(SmallVector<uint32_t> spirv)
{
ir.spirv = move(spirv);
}
Parser::Parser(const uint32_t *spirv_data, size_t word_count)
{
- ir.spirv = vector<uint32_t>(spirv_data, spirv_data + word_count);
+ ir.spirv = SmallVector<uint32_t>(spirv_data, spirv_data + word_count);
}
static bool decoration_is_string(Decoration decoration)
@@ -88,7 +88,7 @@ void Parser::parse()
uint32_t offset = 5;
- vector<Instruction> instructions;
+ SmallVector<Instruction> instructions;
while (offset < len)
{
Instruction instr = {};
@@ -131,7 +131,7 @@ const uint32_t *Parser::stream(const Instruction &instr) const
return &ir.spirv[instr.offset];
}
-static string extract_string(const vector<uint32_t> &spirv, uint32_t offset)
+static string extract_string(const SmallVector<uint32_t> &spirv, uint32_t offset)
{
string ret;
for (uint32_t i = offset; i < spirv.size(); i++)
@@ -1097,7 +1097,7 @@ void Parser::make_constant_null(uint32_t id, uint32_t type)
if (!constant_type.array_size_literal.back())
SPIRV_CROSS_THROW("Array size of OpConstantNull must be a literal.");
- vector<uint32_t> elements(constant_type.array.back());
+ SmallVector<uint32_t> elements(constant_type.array.back());
for (uint32_t i = 0; i < constant_type.array.back(); i++)
elements[i] = parent_id;
set<SPIRConstant>(id, type, elements.data(), uint32_t(elements.size()), false);
@@ -1105,7 +1105,7 @@ void Parser::make_constant_null(uint32_t id, uint32_t type)
else if (!constant_type.member_types.empty())
{
uint32_t member_ids = ir.increase_bound_by(uint32_t(constant_type.member_types.size()));
- vector<uint32_t> elements(constant_type.member_types.size());
+ SmallVector<uint32_t> elements(constant_type.member_types.size());
for (uint32_t i = 0; i < constant_type.member_types.size(); i++)
{
make_constant_null(member_ids + i, constant_type.member_types[i]);
@@ -1120,4 +1120,4 @@ void Parser::make_constant_null(uint32_t id, uint32_t type)
}
}
-} // namespace spirv_cross
+} // namespace SPIRV_CROSS_NAMESPACE