Branch
Hash :
7c7fcb92
Author :
Date :
2025-07-14T07:56:22
CL/Vulkan: Allocate descriptor sets under lock Multiple threads in the application are accessing the OpenCL runtime simultaneously, resulting in multiple SharedPtr of mDynamicDescriptorPools[] being created for a single context. This can lead to incorrect reference counting and potentially cause `DynamicDescriptorPool::destroy` to be called unexpectedly. This fixes the concurrent access issue through acquiring the descriptor set mutex just before initializing mDynamicDescriptorPools to ensure that only one mDynamicDescriptorPools[] is created per context. Bug: angleproject:383999367 Tests-Passing: test_integer_ops int_logic Change-Id: Iba0fad6813a08e1631b73d5efae4f4639892b36f Signed-off-by: hoonee.cho <hoonee.cho@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6981091 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Austin Annestrand <a.annestrand@samsung.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CLKernelVk.h: Defines the class interface for CLKernelVk, implementing CLKernelImpl.
#ifndef LIBANGLE_RENDERER_VULKAN_CLKERNELVK_H_
#define LIBANGLE_RENDERER_VULKAN_CLKERNELVK_H_
#include "libANGLE/renderer/vulkan/CLMemoryVk.h"
#include "libANGLE/renderer/vulkan/cl_types.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
#include "libANGLE/renderer/CLKernelImpl.h"
#include "vulkan/vulkan_core.h"
namespace rx
{
struct CLKernelArgument
{
CLKernelImpl::ArgInfo info{};
uint32_t type = 0;
uint32_t ordinal = 0;
size_t handleSize = 0;
void *handle = nullptr;
bool used = false;
// Shared operand words/regions for "OpExtInst" type spv instructions
// (starts from spv word index/offset 7 and onward)
// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpExtInst
// https://github.com/google/clspv/blob/main/docs/OpenCLCOnVulkan.md#kernels
union
{
uint32_t op3;
uint32_t descriptorSet;
uint32_t pushConstOffset;
uint32_t workgroupBufferSpecId;
};
union
{
uint32_t op4;
uint32_t descriptorBinding;
uint32_t pushConstantSize;
uint32_t workgroupBufferElemSize;
};
union
{
uint32_t op5;
uint32_t podStorageBufferOffset;
uint32_t podUniformOffset;
uint32_t pointerUniformOffset;
};
union
{
uint32_t op6;
uint32_t podStorageBufferSize;
uint32_t podUniformSize;
uint32_t pointerUniformSize;
};
};
using CLKernelArguments = std::vector<CLKernelArgument>;
using CLKernelArgsMap = angle::HashMap<std::string, CLKernelArguments>;
bool IsCLKernelArgumentReadonly(const CLKernelArgument &kernelArgument);
cl::Memory *GetCLKernelArgumentMemoryHandle(const CLKernelArgument &kernelArgument);
class CLKernelVk : public CLKernelImpl
{
public:
using Ptr = std::unique_ptr<CLKernelVk>;
struct KernelSpecConstant
{
uint32_t ID;
uint32_t data;
};
// Setting a reasonable initial value
// https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_DEVICE_MAX_PARAMETER_SIZE
using KernelSpecConstants = angle::FastVector<KernelSpecConstant, 128>;
CLKernelVk(const cl::Kernel &kernel,
std::string &name,
std::string &attributes,
CLKernelArguments &args);
~CLKernelVk() override;
angle::Result init();
angle::Result setArg(cl_uint argIndex, size_t argSize, const void *argValue) override;
angle::Result createInfo(CLKernelImpl::Info *infoOut) const override;
angle::Result initPipelineLayout();
CLProgramVk *getProgram() { return mProgram; }
const std::string &getKernelName() { return mName; }
const CLKernelArguments &getArgs() { return mArgs; }
const vk::PipelineLayout &getPipelineLayout() const { return *mPipelineLayout; }
vk::DescriptorSetLayoutPointerArray &getDescriptorSetLayouts() { return mDescriptorSetLayouts; }
cl::Kernel &getFrontendObject() { return const_cast<cl::Kernel &>(mKernel); }
angle::Result getOrCreateComputePipeline(vk::PipelineCacheAccess *pipelineCache,
const cl::NDRange &ndrange,
const cl::Device &device,
vk::PipelineHelper **pipelineOut);
const vk::DescriptorSetLayoutDesc &getDescriptorSetLayoutDesc(DescriptorSetIndex index) const
{
return mDescriptorSetLayoutDescs[index];
}
const vk::DescriptorSetLayoutDesc &getKernelArgDescriptorSetDesc() const
{
return getDescriptorSetLayoutDesc(DescriptorSetIndex::KernelArguments);
}
const vk::DescriptorSetLayoutDesc &getLiteralSamplerDescriptorSetDesc() const
{
return getDescriptorSetLayoutDesc(DescriptorSetIndex::LiteralSampler);
}
const vk::DescriptorSetLayoutDesc &getPrintfDescriptorSetDesc() const
{
return getDescriptorSetLayoutDesc(DescriptorSetIndex::Printf);
}
const vk::PipelineLayoutDesc &getPipelineLayoutDesc() { return mPipelineLayoutDesc; }
VkDescriptorSet getDescriptorSet(DescriptorSetIndex index)
{
return mDescriptorSets[index]->getDescriptorSet();
}
std::vector<uint8_t> &getPodArgumentPushConstantsData() { return mPodArgumentPushConstants; }
cl::MemoryPtr getPodBuffer() { return mPodBuffer; }
bool usesPrintf() const;
bool usesPrintfBufferPointerPushConstant() const;
angle::Result allocateDescriptorSet(
DescriptorSetIndex index,
angle::EnumIterator<DescriptorSetIndex> layoutIndex,
vk::OutsideRenderPassCommandBufferHelper *computePassCommands);
// Initialize the descriptor pools for this kernel resources
angle::Result initializeDescriptorPools();
private:
CLProgramVk *mProgram;
CLContextVk *mContext;
std::string mName;
std::string mAttributes;
CLKernelArguments mArgs;
std::vector<uint8_t> mPodArgumentPushConstants;
cl::MemoryPtr mPodBuffer;
vk::ShaderProgramHelper mShaderProgramHelper;
ComputePipelineCache mComputePipelineCache;
// Pipeline and DescriptorSetLayout Shared pointers
vk::PipelineLayoutPtr mPipelineLayout;
vk::DescriptorSetLayoutPointerArray mDescriptorSetLayouts{};
// DescriptorSet and DescriptorPool shared pointers for this kernel resources
vk::DescriptorSetArray<vk::DescriptorSetPointer> mDescriptorSets;
vk::DescriptorSetArray<vk::DynamicDescriptorPoolPointer> mDynamicDescriptorPools;
vk::DescriptorSetArray<vk::DescriptorSetLayoutDesc> mDescriptorSetLayoutDescs;
vk::PipelineLayoutDesc mPipelineLayoutDesc;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_CLKERNELVK_H_