Skip to content

Commit

Permalink
igl | vulkan | Don't do unnecessary heap allocations
Browse files Browse the repository at this point in the history
Summary:
Don't do unnecessary heap allocations for trivial operations.

Removed `#include <vector>` making things a tad faster to compile and link.

Reviewed By: syeh1

Differential Revision: D48477642

fbshipit-source-id: 5c24a8cf823bde0459d65d8206b9db482b98e1e8
  • Loading branch information
corporateshark authored and facebook-github-bot committed Aug 19, 2023
1 parent 8059803 commit 47e5570
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/igl/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,27 +816,29 @@ igl::Result VulkanContext::initContext(const HWDeviceDesc& desc,
limits.maxPushConstantsSize);
}

std::vector<VkDescriptorSetLayout> DSLs = {
// @lint-ignore CLANGTIDY
const VkDescriptorSetLayout DSLs[] = {
dslCombinedImageSamplers_->getVkDescriptorSetLayout(),
dslBuffersUniform_->getVkDescriptorSetLayout(),
dslBuffersStorage_->getVkDescriptorSetLayout(),
config_.enableDescriptorIndexing ? dslBindless_->getVkDescriptorSetLayout() : VK_NULL_HANDLE,
};

if (config_.enableDescriptorIndexing) {
DSLs.push_back(dslBindless_->getVkDescriptorSetLayout());
}

// create pipeline layout
pipelineLayoutGraphics_ = std::make_unique<VulkanPipelineLayout>(
device,
DSLs,
static_cast<uint32_t>(config_.enableDescriptorIndexing ? IGL_ARRAY_NUM_ELEMENTS(DSLs)
: IGL_ARRAY_NUM_ELEMENTS(DSLs) - 1),
ivkGetPushConstantRange(
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, kPushConstantsSize),
"Pipeline Layout: VulkanContext::pipelineLayoutGraphics_");

pipelineLayoutCompute_ = std::make_unique<VulkanPipelineLayout>(
device,
DSLs,
static_cast<uint32_t>(config_.enableDescriptorIndexing ? IGL_ARRAY_NUM_ELEMENTS(DSLs)
: IGL_ARRAY_NUM_ELEMENTS(DSLs) - 1),
ivkGetPushConstantRange(VK_SHADER_STAGE_COMPUTE_BIT, 0, kPushConstantsSize),
"Pipeline Layout: VulkanContext::pipelineLayoutCompute_");

Expand Down
6 changes: 3 additions & 3 deletions src/igl/vulkan/VulkanPipelineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace igl {
namespace vulkan {

VulkanPipelineLayout::VulkanPipelineLayout(VkDevice device,
const std::vector<VkDescriptorSetLayout>& layouts,
const VkDescriptorSetLayout* layouts,
uint32_t numLayouts,
const VkPushConstantRange& range,
const char* debugName) :
device_(device) {
IGL_PROFILER_FUNCTION_COLOR(IGL_PROFILER_COLOR_CREATE);

const VkPipelineLayoutCreateInfo ci =
ivkGetPipelineLayoutCreateInfo((uint32_t)layouts.size(), layouts.data(), &range);
const VkPipelineLayoutCreateInfo ci = ivkGetPipelineLayoutCreateInfo(numLayouts, layouts, &range);

VK_ASSERT(vkCreatePipelineLayout(device, &ci, nullptr, &vkPipelineLayout_));
VK_ASSERT(ivkSetDebugObjectName(
Expand Down
4 changes: 2 additions & 2 deletions src/igl/vulkan/VulkanPipelineLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#pragma once

#include <igl/vulkan/VulkanHelpers.h>
#include <vector>

namespace igl {
namespace vulkan {

class VulkanPipelineLayout final {
public:
explicit VulkanPipelineLayout(VkDevice device,
const std::vector<VkDescriptorSetLayout>& layouts,
const VkDescriptorSetLayout* layouts,
uint32_t numLayouts,
const VkPushConstantRange& range,
const char* debugName = nullptr);
~VulkanPipelineLayout();
Expand Down

0 comments on commit 47e5570

Please sign in to comment.