Hash :
1ceddbf6
Author :
Date :
2024-01-11T16:15:08
OpenCL/Vulkan: Add createProgram routines Introduce createProgramWithSource and createProgramWithBinary. Additionally introduce KernelArgument types, SPIR-V Reflection info types, and DeviceProgram types. Bug: angleproject:8549 Change-Id: I611627d747a5ba6718778fd27fd28477b77fbbe1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5303563 Commit-Queue: Austin Annestrand <a.annestrand@samsung.com> Reviewed-by: Geoff Lang <geofflang@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
//
// 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/CLProgramVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
#include "libANGLE/cl_utils.h"
namespace rx
{
CLContextVk::CLContextVk(const cl::Context &context,
const egl::Display *display,
const cl::DevicePtrs devicePtrs)
: CLContextImpl(context),
vk::Context(GetImplAs<DisplayVk>(display)->getRenderer()),
mAssociatedDevices(devicePtrs)
{}
CLContextVk::~CLContextVk() = default;
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)
<< ". " << "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)
{
*commandQueueOut = CLCommandQueueVk::Ptr(new (std::nothrow) CLCommandQueueVk(commandQueue));
if (*commandQueueOut == nullptr)
{
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_HOST_MEMORY);
}
return angle::Result::Continue;
}
angle::Result CLContextVk::createBuffer(const cl::Buffer &buffer,
size_t size,
void *hostPtr,
CLMemoryImpl::Ptr *bufferOut)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::createImage(const cl::Image &image,
cl::MemFlags flags,
const cl_image_format &format,
const cl::ImageDescriptor &desc,
void *hostPtr,
CLMemoryImpl::Ptr *imageOut)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::getSupportedImageFormats(cl::MemFlags flags,
cl::MemObjectType imageType,
cl_uint numEntries,
cl_image_format *imageFormats,
cl_uint *numImageFormats)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::createSampler(const cl::Sampler &sampler, CLSamplerImpl::Ptr *samplerOut)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
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)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::createUserEvent(const cl::Event &event, CLEventImpl::Ptr *eventOut)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
angle::Result CLContextVk::waitForEvents(const cl::EventPtrs &events)
{
UNIMPLEMENTED();
ANGLE_CL_RETURN_ERROR(CL_OUT_OF_RESOURCES);
}
} // namespace rx