[GPU/Common/D3D11/Directx9/GLES/Vulkan] Using reserve if possible

This commit is contained in:
Herman Semenov
2023-12-15 14:08:22 +03:00
parent b8748ae9e5
commit 0748ce610f
11 changed files with 17 additions and 0 deletions
+1
View File
@@ -75,6 +75,7 @@ VertexDecoder *DrawEngineCommon::GetVertexDecoder(u32 vtype) {
std::vector<std::string> DrawEngineCommon::DebugGetVertexLoaderIDs() {
std::vector<std::string> ids;
ids.reserve(decoderMap_.size());
decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) {
std::string id;
id.resize(sizeof(vtype));
+1
View File
@@ -72,6 +72,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
std::vector<const char*> extensions;
if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) {
extensions.reserve(4);
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE && gl_extensions.EXT_blend_func_extended) {
extensions.push_back("#extension GL_EXT_blend_func_extended : require");
}
+2
View File
@@ -67,6 +67,8 @@ bool GenerateGeometryShader(const GShaderID &id, char *buffer, const ShaderLangu
}
std::vector<VaryingDef> varyings, outVaryings;
varyings.reserve(4);
outVaryings.reserve(4);
if (id.Bit(GS_BIT_DO_TEXTURE)) {
varyings.push_back(VaryingDef{ "vec3", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" });
+1
View File
@@ -136,6 +136,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
bool highpTexcoord = false;
std::vector<const char*> extensions;
extensions.reserve(6);
if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) {
if (gl_extensions.EXT_gpu_shader4) {
extensions.push_back("#extension GL_EXT_gpu_shader4 : enable");
+2
View File
@@ -251,6 +251,7 @@ std::vector<std::string> ShaderManagerD3D11::DebugGetShaderIDs(DebugShaderType t
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
for (auto iter : vsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
@@ -259,6 +260,7 @@ std::vector<std::string> ShaderManagerD3D11::DebugGetShaderIDs(DebugShaderType t
}
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
for (auto iter : fsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
+2
View File
@@ -667,6 +667,7 @@ std::vector<std::string> ShaderManagerDX9::DebugGetShaderIDs(DebugShaderType typ
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
for (auto iter : vsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
@@ -675,6 +676,7 @@ std::vector<std::string> ShaderManagerDX9::DebugGetShaderIDs(DebugShaderType typ
break;
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
for (auto iter : fsCache_) {
iter.first.ToString(&id);
ids.push_back(id);
+1
View File
@@ -103,6 +103,7 @@ void DrawEngineGLES::InitDeviceObjects() {
int stride = sizeof(TransformedVertex);
std::vector<GLRInputLayout::Entry> entries;
entries.reserve(5);
entries.push_back({ ATTR_POSITION, 4, GL_FLOAT, GL_FALSE, offsetof(TransformedVertex, x) });
entries.push_back({ ATTR_TEXCOORD, 3, GL_FLOAT, GL_FALSE, offsetof(TransformedVertex, u) });
entries.push_back({ ATTR_COLOR0, 4, GL_UNSIGNED_BYTE, GL_TRUE, offsetof(TransformedVertex, color0) });
+2
View File
@@ -915,6 +915,7 @@ std::vector<std::string> ShaderManagerGLES::DebugGetShaderIDs(DebugShaderType ty
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
vsCache_.Iterate([&](const VShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
@@ -924,6 +925,7 @@ std::vector<std::string> ShaderManagerGLES::DebugGetShaderIDs(DebugShaderType ty
break;
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
fsCache_.Iterate([&](const FShaderID &id, Shader *shader) {
std::string idstr;
id.ToString(&idstr);
+1
View File
@@ -402,6 +402,7 @@ std::vector<std::string> PipelineManagerVulkan::DebugGetObjectIDs(DebugShaderTyp
switch (type) {
case SHADER_TYPE_PIPELINE:
{
ids.reserve(pipelines_.size());
pipelines_.Iterate([&](const VulkanPipelineKey &key, VulkanPipeline *value) {
std::string id;
key.ToString(&id);
+3
View File
@@ -394,6 +394,7 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
switch (type) {
case SHADER_TYPE_VERTEX:
{
ids.reserve(vsCache_.size());
vsCache_.Iterate([&](const VShaderID &id, VulkanVertexShader *shader) {
std::string idstr;
id.ToString(&idstr);
@@ -403,6 +404,7 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
}
case SHADER_TYPE_FRAGMENT:
{
ids.reserve(fsCache_.size());
fsCache_.Iterate([&](const FShaderID &id, VulkanFragmentShader *shader) {
std::string idstr;
id.ToString(&idstr);
@@ -412,6 +414,7 @@ std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType
}
case SHADER_TYPE_GEOMETRY:
{
ids.reserve(gsCache_.size());
gsCache_.Iterate([&](const GShaderID &id, VulkanGeometryShader *shader) {
std::string idstr;
id.ToString(&idstr);
+1
View File
@@ -187,6 +187,7 @@ void SamplerCache::DeviceRestore(VulkanContext *vulkan) {
std::vector<std::string> SamplerCache::DebugGetSamplerIDs() const {
std::vector<std::string> ids;
ids.reserve(cache_.size());
cache_.Iterate([&](const SamplerCacheKey &id, VkSampler sampler) {
std::string idstr;
id.ToString(&idstr);