Skip to content

Commit

Permalink
CL/Vulkan: Add utility function for clspv compile options
Browse files Browse the repository at this point in the history
Add a utility function for querying the options based on the vulkan
renderer for the clspv compiler.

Bug: angleproject:361717757
Change-Id: I9722b8a80bcad3f2b799d87b8fbe29c84a686a6e
Signed-off-by: Gowtham Tammana <[email protected]>
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5810696
Reviewed-by: Shahbaz Youssefi <[email protected]>
Reviewed-by: Charlie Lao <[email protected]>
  • Loading branch information
gowtham-sarc authored and Angle LUCI CQ committed Aug 28, 2024
1 parent 42ea855 commit 0929a8d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/libANGLE/renderer/vulkan/CLDeviceVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CLDeviceVk : public CLDeviceImpl

Info createInfo(cl::DeviceType type) const override;

const vk::Renderer *getRenderer() const { return mRenderer; }
angle::Result getInfoUInt(cl::DeviceInfo name, cl_uint *value) const override;
angle::Result getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override;
angle::Result getInfoSizeT(cl::DeviceInfo name, size_t *value) const override;
Expand Down
10 changes: 3 additions & 7 deletions src/libANGLE/renderer/vulkan/CLProgramVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "libANGLE/renderer/vulkan/CLProgramVk.h"
#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/renderer/vulkan/CLDeviceVk.h"
#include "libANGLE/renderer/vulkan/clspv_utils.h"

#include "libANGLE/CLContext.h"
#include "libANGLE/CLKernel.h"
Expand Down Expand Up @@ -229,9 +230,6 @@ std::string ProcessBuildOptions(const std::vector<std::string> &optionTokens,
break;
}

// Other internal Clspv compiler flags that are needed/required
processedOptions += " --long-vector";

return processedOptions;
}

Expand Down Expand Up @@ -779,10 +777,8 @@ bool CLProgramVk::buildInternal(const cl::DevicePtrs &devices,
const cl::RefPointer<cl::Device> &device = devices.at(i);
DeviceProgramData &deviceProgramData = mAssociatedDevicePrograms[device->getNative()];

cl_uint addressBits;
ANGLE_CL_IMPL_TRY(
device->getInfo(cl::DeviceInfo::AddressBits, sizeof(cl_uint), &addressBits, nullptr));
processedOptions += addressBits == 64 ? " -arch=spir64" : " -arch=spir";
// add clspv compiler options based on device features
processedOptions += ClspvGetCompilerOptions(&device->getImpl<CLDeviceVk>());

if (buildType != BuildType::BINARY)
{
Expand Down
64 changes: 64 additions & 0 deletions src/libANGLE/renderer/vulkan/clspv_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Copyright 2024 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.
//
// Utilities to map clspv interface variables to OpenCL and Vulkan mappings.
//

#include "libANGLE/renderer/vulkan/clspv_utils.h"
#include "libANGLE/renderer/vulkan/CLDeviceVk.h"

#include <string>

namespace rx
{
std::string ClspvGetCompilerOptions(const CLDeviceVk *device)
{
ASSERT(device && device->getRenderer());
const vk::Renderer *rendererVk = device->getRenderer();
std::string options{""};

cl_uint addressBits;
if (IsError(device->getInfoUInt(cl::DeviceInfo::AddressBits, &addressBits)))
{
// This should'nt fail here
ASSERT(false);
}
options += addressBits == 64 ? " -arch=spir64" : " -arch=spir";

// Other internal Clspv compiler flags that are needed/required
options += " --long-vector";

// 8 bit storage buffer support
if (!rendererVk->getFeatures().supports8BitStorageBuffer.enabled)
{
options += " --no-8bit-storage=ssbo";
}
if (!rendererVk->getFeatures().supports8BitUniformAndStorageBuffer.enabled)
{
options += " --no-8bit-storage=ubo";
}
if (!rendererVk->getFeatures().supports8BitPushConstant.enabled)
{
options += " --no-8bit-storage=pushconstant";
}

// 16 bit storage options
if (!rendererVk->getFeatures().supports16BitStorageBuffer.enabled)
{
options += " --no-16bit-storage=ssbo";
}
if (!rendererVk->getFeatures().supports16BitUniformAndStorageBuffer.enabled)
{
options += " --no-16bit-storage=ubo";
}
if (!rendererVk->getFeatures().supports16BitPushConstant.enabled)
{
options += " --no-16bit-storage=pushconstant";
}

return options;
}

} // namespace rx
17 changes: 17 additions & 0 deletions src/libANGLE/renderer/vulkan/clspv_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright 2024 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.
//
// clspv_utils:
// Utilities to map clspv interface variables to OpenCL and Vulkan mappings.
//

#include <libANGLE/renderer/vulkan/CLDeviceVk.h>

namespace rx
{
// Populate a list of options that can be supported by clspv based on the features supported by the
// vulkan renderer.
std::string ClspvGetCompilerOptions(const CLDeviceVk *device);

} // namespace rx
2 changes: 2 additions & 0 deletions src/libANGLE/renderer/vulkan/vulkan_backend.gni
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ if (angle_enable_cl) {
"CLSamplerVk.cpp",
"CLSamplerVk.h",
"cl_types.h",
"clspv_utils.cpp",
"clspv_utils.h",
]
}

Expand Down

0 comments on commit 0929a8d

Please sign in to comment.