Hash :
f51170b3
Author :
Date :
2024-11-21T16:30:40
Enable GL_KHR_texture_compression_astc_hdr Vulkan supports GL_KHR_texture_compression_astc_hdr, so this extension can be enabled in Angle. Bug: angleproject:379186304 Change-Id: I438a120c3f884a7eefcd883ad71abf68f81cb473 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6038457 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
//
// 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.
//
// CLContextVk.cpp: Implements the class methods for CLContextVk.
#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/renderer/vulkan/CLCommandQueueVk.h"
#include "libANGLE/renderer/vulkan/CLEventVk.h"
#include "libANGLE/renderer/vulkan/CLMemoryVk.h"
#include "libANGLE/renderer/vulkan/CLProgramVk.h"
#include "libANGLE/renderer/vulkan/CLSamplerVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/vk_renderer.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
#include "libANGLE/CLBuffer.h"
#include "libANGLE/CLContext.h"
#include "libANGLE/CLEvent.h"
#include "libANGLE/CLImage.h"
#include "libANGLE/CLProgram.h"
#include "libANGLE/cl_utils.h"
namespace rx
{
CLContextVk::CLContextVk(const cl::Context &context, const cl::DevicePtrs devicePtrs)
: CLContextImpl(context),
vk::Context(getPlatform()->getRenderer()),
mAssociatedDevices(devicePtrs)
{
mDeviceQueueIndex = mRenderer->getDefaultDeviceQueueIndex();
}
CLContextVk::~CLContextVk()
{
mDescriptorSetLayoutCache.destroy(getRenderer());
mPipelineLayoutCache.destroy(getRenderer());
}
void CLContextVk::handleError(VkResult errorCode,
const char *file,
const char *function,
unsigned int line)
{
ASSERT(errorCode != VK_SUCCESS);
CLenum clErrorCode = CL_SUCCESS;
switch (errorCode)
{
case VK_ERROR_TOO_MANY_OBJECTS:
case VK_ERROR_OUT_OF_HOST_MEMORY:
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
clErrorCode = CL_OUT_OF_HOST_MEMORY;
break;
default:
clErrorCode = CL_INVALID_OPERATION;
}
ERR() << "Internal Vulkan error (" << errorCode << "): " << VulkanResultString(errorCode);
ERR() << " CL error (" << clErrorCode << ")";
if (errorCode == VK_ERROR_DEVICE_LOST)
{
handleDeviceLost();
}
ANGLE_CL_SET_ERROR(clErrorCode);
}
void CLContextVk::handleDeviceLost() const
{
// For now just notify the renderer
getRenderer()->notifyDeviceLost();
}
angle::Result CLContextVk::getDevices(cl::DevicePtrs *devicePtrsOut) const
{
ASSERT(!mAssociatedDevices.empty());
*devicePtrsOut = mAssociatedDevices;
return angle::Result::Continue;
}
angle::Result CLContextVk::createCommandQueue(const cl::CommandQueue &commandQueue,
CLCommandQueueImpl::Ptr *commandQueueOut)
{
CLCommandQueueVk *queueImpl = new CLCommandQueueVk(commandQueue);
if (queueImpl == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(queueImpl->init());
*commandQueueOut = CLCommandQueueVk::Ptr(std::move(queueImpl));
return angle::Result::Continue;
}
angle::Result CLContextVk::createBuffer(const cl::Buffer &buffer,
void *hostPtr,
CLMemoryImpl::Ptr *bufferOut)
{
CLBufferVk *memory = new (std::nothrow) CLBufferVk(buffer);
if (memory == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(memory->create(hostPtr));
*bufferOut = CLMemoryImpl::Ptr(memory);
mAssociatedObjects->mMemories.emplace(buffer.getNative());
return angle::Result::Continue;
}
angle::Result CLContextVk::createImage(const cl::Image &image,
void *hostPtr,
CLMemoryImpl::Ptr *imageOut)
{
CLImageVk *memory = new (std::nothrow) CLImageVk(image);
if (memory == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(memory->create(hostPtr));
*imageOut = CLMemoryImpl::Ptr(memory);
mAssociatedObjects->mMemories.emplace(image.getNative());
return angle::Result::Continue;
}
VkFormat CLContextVk::getVkFormatFromCL(cl_image_format format)
{
angle::FormatID formatID;
switch (format.image_channel_order)
{
case CL_R:
formatID = angle::Format::CLRFormatToID(format.image_channel_data_type);
break;
case CL_RG:
formatID = angle::Format::CLRGFormatToID(format.image_channel_data_type);
break;
case CL_RGB:
formatID = angle::Format::CLRGBFormatToID(format.image_channel_data_type);
break;
case CL_RGBA:
formatID = angle::Format::CLRGBAFormatToID(format.image_channel_data_type);
break;
case CL_BGRA:
formatID = angle::Format::CLBGRAFormatToID(format.image_channel_data_type);
break;
case CL_sRGBA:
formatID = angle::Format::CLsRGBAFormatToID(format.image_channel_data_type);
break;
default:
return VK_FORMAT_UNDEFINED;
}
return getPlatform()->getRenderer()->getFormat(formatID).getActualRenderableImageVkFormat(
getPlatform()->getRenderer());
}
angle::Result CLContextVk::getSupportedImageFormats(cl::MemFlags flags,
cl::MemObjectType imageType,
cl_uint numEntries,
cl_image_format *imageFormats,
cl_uint *numImageFormats)
{
VkPhysicalDevice physicalDevice = getPlatform()->getRenderer()->getPhysicalDevice();
std::vector<cl_image_format> supportedFormats;
std::vector<cl_image_format> minSupportedFormats;
if (flags.intersects((CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY)))
{
minSupportedFormats.insert(minSupportedFormats.end(),
std::begin(kMinSupportedFormatsReadOrWrite),
std::end(kMinSupportedFormatsReadOrWrite));
}
else
{
minSupportedFormats.insert(minSupportedFormats.end(),
std::begin(kMinSupportedFormatsReadAndWrite),
std::end(kMinSupportedFormatsReadAndWrite));
}
for (cl_image_format format : minSupportedFormats)
{
VkFormatProperties formatProperties;
VkFormat vkFormat = getVkFormatFromCL(format);
ASSERT(vkFormat != VK_FORMAT_UNDEFINED);
vkGetPhysicalDeviceFormatProperties(physicalDevice, vkFormat, &formatProperties);
if (formatProperties.optimalTilingFeatures != 0)
{
supportedFormats.push_back(format);
}
}
if (numImageFormats != nullptr)
{
*numImageFormats = static_cast<cl_uint>(supportedFormats.size());
}
if (imageFormats != nullptr)
{
memcpy(imageFormats, supportedFormats.data(),
sizeof(cl_image_format) *
std::min(static_cast<cl_uint>(supportedFormats.size()), numEntries));
}
return angle::Result::Continue;
}
angle::Result CLContextVk::createSampler(const cl::Sampler &sampler, CLSamplerImpl::Ptr *samplerOut)
{
CLSamplerVk *samplerVk = new (std::nothrow) CLSamplerVk(sampler);
if (samplerVk == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(samplerVk->create());
*samplerOut = CLSamplerImpl::Ptr(samplerVk);
return angle::Result::Continue;
}
angle::Result CLContextVk::createProgramWithSource(const cl::Program &program,
const std::string &source,
CLProgramImpl::Ptr *programOut)
{
CLProgramVk *programVk = new (std::nothrow) CLProgramVk(program);
if (programVk == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(programVk->init());
*programOut = CLProgramImpl::Ptr(std::move(programVk));
return angle::Result::Continue;
}
angle::Result CLContextVk::createProgramWithIL(const cl::Program &program,
const void *il,
size_t length,
CLProgramImpl::Ptr *programOut)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::createProgramWithBinary(const cl::Program &program,
const size_t *lengths,
const unsigned char **binaries,
cl_int *binaryStatus,
CLProgramImpl::Ptr *programOut)
{
CLProgramVk *programVk = new (std::nothrow) CLProgramVk(program);
if (programVk == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(programVk->init(lengths, binaries, binaryStatus));
*programOut = CLProgramImpl::Ptr(std::move(programVk));
return angle::Result::Continue;
}
angle::Result CLContextVk::createProgramWithBuiltInKernels(const cl::Program &program,
const char *kernel_names,
CLProgramImpl::Ptr *programOut)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::linkProgram(const cl::Program &program,
const cl::DevicePtrs &devices,
const char *options,
const cl::ProgramPtrs &inputPrograms,
cl::Program *notify,
CLProgramImpl::Ptr *programOut)
{
const cl::DevicePtrs &devicePtrs = !devices.empty() ? devices : mContext.getDevices();
CLProgramVk::Ptr programImpl = CLProgramVk::Ptr(new (std::nothrow) CLProgramVk(program));
if (programImpl == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
ANGLE_TRY(programImpl->init());
cl::DevicePtrs linkDeviceList;
CLProgramVk::LinkProgramsList linkProgramsList;
cl::BitField libraryOrObject(CL_PROGRAM_BINARY_TYPE_LIBRARY |
CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT);
for (const cl::DevicePtr &devicePtr : devicePtrs)
{
CLProgramVk::LinkPrograms linkPrograms;
for (const cl::ProgramPtr &inputProgram : inputPrograms)
{
const CLProgramVk::DeviceProgramData *deviceProgramData =
inputProgram->getImpl<CLProgramVk>().getDeviceProgramData(devicePtr->getNative());
// Should be valid at this point
ASSERT(deviceProgramData != nullptr);
if (libraryOrObject.intersects(deviceProgramData->binaryType))
{
linkPrograms.push_back(deviceProgramData);
}
}
if (!linkPrograms.empty())
{
linkDeviceList.push_back(devicePtr);
linkProgramsList.push_back(linkPrograms);
}
}
programImpl->setBuildStatus(linkDeviceList, CL_BUILD_IN_PROGRESS);
// Perform link
if (notify)
{
std::shared_ptr<angle::WaitableEvent> asyncEvent =
mContext.getPlatform().getMultiThreadPool()->postWorkerTask(
std::make_shared<CLAsyncBuildTask>(
programImpl.get(), linkDeviceList, std::string(options ? options : ""), "",
CLProgramVk::BuildType::LINK, linkProgramsList, notify));
ASSERT(asyncEvent != nullptr);
}
else
{
if (!programImpl->buildInternal(linkDeviceList, std::string(options ? options : ""), "",
CLProgramVk::BuildType::LINK, linkProgramsList))
{
ANGLE_CL_RETURN_ERROR(CL_LINK_PROGRAM_FAILURE);
}
}
*programOut = std::move(programImpl);
return angle::Result::Continue;
}
angle::Result CLContextVk::createUserEvent(const cl::Event &event, CLEventImpl::Ptr *eventOut)
{
*eventOut = CLEventImpl::Ptr(new (std::nothrow) CLEventVk(event));
if (*eventOut == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
return angle::Result::Continue;
}
angle::Result CLContextVk::waitForEvents(const cl::EventPtrs &events)
{
for (auto &event : events)
{
CLEventVk *eventVk = &event.get()->getImpl<CLEventVk>();
if (eventVk->isUserEvent())
{
ANGLE_TRY(eventVk->waitForUserEventStatus());
}
else
{
// TODO rework this to instead (flush w/ ResourceUse serial wait) once we move away from
// spawning a submit-thread/Task for flush routine
// https://anglebug.com/42267107
ANGLE_TRY(event->getCommandQueue()->finish());
}
}
return angle::Result::Continue;
}
} // namespace rx