Skip to content

Commit

Permalink
CL/VK: Setup GlobalOps for the platform
Browse files Browse the repository at this point in the history
Setup CLPlatformVk as a provider of vk::GlobalOps, and use the
vk::GlobalOps associated thread pool for async tasks.

Bug: angleproject:8515
Change-Id: I3e1ae069afabeadfdfa02f4a2f99419882f91c6a
Signed-off-by: Gowtham Tammana <[email protected]>
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5403225
Reviewed-by: Shahbaz Youssefi <[email protected]>
Commit-Queue: Shahbaz Youssefi <[email protected]>
  • Loading branch information
gowtham-sarc authored and Angle LUCI CQ committed Apr 2, 2024
1 parent 85b3e96 commit a8e9aa2
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/libANGLE/renderer/vulkan/CLCommandQueueVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <vector>

#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/cl_types.h"
#include "libANGLE/renderer/vulkan/vk_command_buffer_utils.h"
Expand Down Expand Up @@ -221,6 +222,8 @@ class CLCommandQueueVk : public CLCommandQueueImpl

angle::Result finish() override;

CLPlatformVk *getPlatform() { return mContext->getPlatform(); }

private:
vk::ProtectionType getProtectionType() const { return vk::ProtectionType::Unprotected; }

Expand Down
4 changes: 4 additions & 0 deletions src/libANGLE/renderer/vulkan/CLContextVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
#ifndef LIBANGLE_RENDERER_VULKAN_CLCONTEXTVK_H_
#define LIBANGLE_RENDERER_VULKAN_CLCONTEXTVK_H_

#include "libANGLE/renderer/vulkan/CLPlatformVk.h"
#include "libANGLE/renderer/vulkan/cl_types.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"

#include "libANGLE/renderer/CLContextImpl.h"

#include <libANGLE/CLContext.h>
#include "libANGLE/CLDevice.h"
#include "libANGLE/Display.h"

Expand Down Expand Up @@ -90,6 +92,8 @@ class CLContextVk : public CLContextImpl, public vk::Context

angle::Result waitForEvents(const cl::EventPtrs &events) override;

CLPlatformVk *getPlatform() { return &mContext.getPlatform().getImpl<CLPlatformVk>(); }

private:
void handleDeviceLost() const;

Expand Down
36 changes: 35 additions & 1 deletion src/libANGLE/renderer/vulkan/CLPlatformVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// CLPlatformVk.cpp: Implements the class methods for CLPlatformVk.

#include "libANGLE/renderer/vulkan/CLPlatformVk.h"
#include "common/MemoryBuffer.h"
#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/renderer/vulkan/CLDeviceVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
Expand All @@ -16,6 +17,7 @@

#include "anglebase/no_destructor.h"
#include "common/angle_version_info.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"

namespace rx
{
Expand Down Expand Up @@ -194,7 +196,8 @@ const std::string &CLPlatformVk::GetVersionString()
return *sVersion;
}

CLPlatformVk::CLPlatformVk(const cl::Platform &platform) : CLPlatformImpl(platform)
CLPlatformVk::CLPlatformVk(const cl::Platform &platform)
: CLPlatformImpl(platform), mBlobCache(1024 * 1024)
{
// Select vulkan backend
const EGLint attribList[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE,
Expand All @@ -207,4 +210,35 @@ CLPlatformVk::CLPlatformVk(const cl::Platform &platform) : CLPlatformImpl(platfo
ANGLE_CL_IMPL_TRY(InitBackendRenderer(mDisplay));
}

// vk::GlobalOps
void CLPlatformVk::putBlob(const angle::BlobCacheKey &key, const angle::MemoryBuffer &value)
{
std::scoped_lock<std::mutex> lock(mBlobCacheMutex);
size_t valueSize = value.size();
mBlobCache.put(key, std::move(const_cast<angle::MemoryBuffer &>(value)), valueSize);
}

bool CLPlatformVk::getBlob(const angle::BlobCacheKey &key, angle::BlobCacheValue *valueOut)
{
std::scoped_lock<std::mutex> lock(mBlobCacheMutex);
const angle::MemoryBuffer *entry;
bool result = mBlobCache.get(key, &entry);
if (result)
{
*valueOut = angle::BlobCacheValue(entry->data(), entry->size());
}
return result;
}

std::shared_ptr<angle::WaitableEvent> CLPlatformVk::postMultiThreadWorkerTask(
const std::shared_ptr<angle::Closure> &task)
{
return mPlatform.getMultiThreadPool()->postWorkerTask(task);
}

void CLPlatformVk::notifyDeviceLost()
{
return;
}

} // namespace rx
16 changes: 15 additions & 1 deletion src/libANGLE/renderer/vulkan/CLPlatformVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#ifndef LIBANGLE_RENDERER_VULKAN_CLPLATFORMVK_H_
#define LIBANGLE_RENDERER_VULKAN_CLPLATFORMVK_H_

#include "common/MemoryBuffer.h"
#include "libANGLE/renderer/CLPlatformImpl.h"

#include "libANGLE/renderer/vulkan/vk_utils.h"

#include "libANGLE/Display.h"
#include "libANGLE/SizedMRUCache.h"

namespace rx
{

class CLPlatformVk : public CLPlatformImpl
class CLPlatformVk : public CLPlatformImpl, vk::GlobalOps
{
public:
~CLPlatformVk() override;
Expand All @@ -40,9 +44,19 @@ class CLPlatformVk : public CLPlatformImpl
static constexpr cl_version GetVersion();
static const std::string &GetVersionString();

// vk::GlobalOps
void putBlob(const angle::BlobCacheKey &key, const angle::MemoryBuffer &value) override;
bool getBlob(const angle::BlobCacheKey &key, angle::BlobCacheValue *valueOut) override;
std::shared_ptr<angle::WaitableEvent> postMultiThreadWorkerTask(
const std::shared_ptr<angle::Closure> &task) override;
void notifyDeviceLost() override;

private:
explicit CLPlatformVk(const cl::Platform &platform);
egl::Display *mDisplay;

mutable std::mutex mBlobCacheMutex;
angle::SizedMRUCache<angle::BlobCacheKey, angle::MemoryBuffer> mBlobCache;
};

constexpr cl_version CLPlatformVk::GetVersion()
Expand Down
7 changes: 3 additions & 4 deletions src/libANGLE/renderer/vulkan/CLProgramVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,9 @@ angle::Result CLProgramVk::build(const cl::DevicePtrs &devices,
if (notify)
{
std::shared_ptr<angle::WaitableEvent> asyncEvent =
mProgram.getContext().getPlatform().getMultiThreadPool()->postWorkerTask(
std::make_shared<CLAsyncBuildTask>(this, devicePtrs,
std::string(options ? options : ""), "",
buildType, LinkProgramsList{}, notify));
getPlatform()->postMultiThreadWorkerTask(std::make_shared<CLAsyncBuildTask>(
this, devicePtrs, std::string(options ? options : ""), "", buildType,
LinkProgramsList{}, notify));
ASSERT(asyncEvent != nullptr);
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/libANGLE/renderer/vulkan/CLProgramVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef LIBANGLE_RENDERER_VULKAN_CLPROGRAMVK_H_
#define LIBANGLE_RENDERER_VULKAN_CLPROGRAMVK_H_

#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/renderer/vulkan/CLKernelVk.h"
#include "libANGLE/renderer/vulkan/cl_types.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
Expand Down Expand Up @@ -193,6 +194,7 @@ class CLProgramVk : public CLProgramImpl

const DeviceProgramData *getDeviceProgramData(const char *kernelName) const;
const DeviceProgramData *getDeviceProgramData(const _cl_device_id *device) const;
CLPlatformVk *getPlatform() { return mContext->getPlatform(); }

bool buildInternal(const cl::DevicePtrs &devices,
std::string options,
Expand Down

0 comments on commit a8e9aa2

Please sign in to comment.