Skip to content

[ET-VK][ez] Fix using a temporary variable when creating ComputePipeline #9405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions backends/vulkan/runtime/api/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,17 @@ vkapi::DescriptorSet Context::get_descriptor_set(
VkPipelineLayout pipeline_layout =
pipeline_layout_cache().retrieve(shader_layout, push_constants_size);

vkapi::SpecVarList spec_constants = {
SV(local_workgroup_size[0u]),
SV(local_workgroup_size[1u]),
SV(local_workgroup_size[2u])};

spec_constants.append(additional_constants);

VkPipeline pipeline = pipeline_cache().retrieve(
{pipeline_layout_cache().retrieve(shader_layout, push_constants_size),
shader_cache().retrieve(shader_descriptor),
additional_constants,
local_workgroup_size});
spec_constants});

cmd_.bind_pipeline(pipeline, pipeline_layout, local_workgroup_size);

Expand Down
24 changes: 8 additions & 16 deletions backends/vulkan/runtime/vk_api/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,13 @@ ComputePipeline::ComputePipeline(
const ComputePipeline::Descriptor& descriptor,
VkPipelineCache pipeline_cache)
: device_(device), handle_{VK_NULL_HANDLE} {
SpecVarList specialization_constants;

specialization_constants.reserve(
3 + descriptor.specialization_constants.size());
specialization_constants.append(descriptor.local_wg_size[0]);
specialization_constants.append(descriptor.local_wg_size[1]);
specialization_constants.append(descriptor.local_wg_size[2]);

specialization_constants.append(descriptor.specialization_constants);
const std::vector<VkSpecializationMapEntry> map_entries =
specialization_constants.generate_map_entries();
map_entries_ = descriptor.specialization_constants.generate_map_entries();

const VkSpecializationInfo specialization_info{
specialization_constants.size(), // mapEntryCount
map_entries.data(), // pMapEntries
specialization_constants.data_nbytes(), // dataSize
specialization_constants.data(), // pData
descriptor.specialization_constants.size(), // mapEntryCount
map_entries_.data(), // pMapEntries
descriptor.specialization_constants.data_nbytes(), // dataSize
descriptor.specialization_constants.data(), // pData
};

const VkPipelineShaderStageCreateInfo shader_stage_create_info{
Expand Down Expand Up @@ -330,7 +320,9 @@ ComputePipeline::ComputePipeline(
}

ComputePipeline::ComputePipeline(ComputePipeline&& other) noexcept
: device_(other.device_), handle_(other.handle_) {
: device_(other.device_),
handle_(other.handle_),
map_entries_(std::move(other.map_entries_)) {
other.handle_ = VK_NULL_HANDLE;
}

Expand Down
5 changes: 1 addition & 4 deletions backends/vulkan/runtime/vk_api/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class ComputePipeline final {
VkPipelineLayout pipeline_layout;
VkShaderModule shader_module;
SpecVarList specialization_constants;
utils::WorkgroupSize local_wg_size;
};

explicit ComputePipeline(
Expand All @@ -175,6 +174,7 @@ class ComputePipeline final {
private:
VkDevice device_;
VkPipeline handle_;
std::vector<VkSpecializationMapEntry> map_entries_;

public:
inline VkPipeline handle() const {
Expand Down Expand Up @@ -274,9 +274,6 @@ class ComputePipelineCache final {
seed = utils::hash_combine(seed, new_seed);
}

seed = utils::hash_combine(
seed, std::hash<uint32_t>()((uint32_t)descriptor.local_wg_size));

return seed;
}
};
Expand Down
Loading