Skip to content

Commit fcbc54a

Browse files
authored
cl_khr_spirv_queries (#139)
* initial changes for cl_khr_spirv_queries * switch to actual enums * fix reported capability: UniformDecoration is unrelated to images * fix incorrect check for SPIR-V 1.6 support * fix sample app name * add checks for SPIR-V headers
1 parent 6e8a40a commit fcbc54a

17 files changed

Lines changed: 1217 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ jobs:
6666
repository: bashbaug/opencl-extension-loader
6767
path: external/opencl-extension-loader
6868

69+
- name: Get SPIR-V Headers
70+
if: matrix.ext == 'YES'
71+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
72+
with:
73+
repository: KhronosGroup/SPIRV-Headers
74+
path: external/SPIRV-Headers
75+
6976
- name: Create Build Directory
7077
run: cmake -E make_directory ${{runner.workspace}}/build
7178

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ else()
3636
message(STATUS "OpenCL Extension Loader is not found.")
3737
endif()
3838

39+
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/SPIRV-Headers)
40+
add_subdirectory(external/SPIRV-Headers)
41+
else()
42+
message(STATUS "SPIR-V Headers are not found.")
43+
endif()
44+
3945
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
4046
enable_testing()
4147
endif()

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Many samples that use extensions additionally require the OpenCL Extension Loade
3939

4040
git clone https://github.com/bashbaug/opencl-extension-loader external/opencl-extension-loader
4141

42+
Several samples that interact with SPIR-V require the SPIR-V headres:
43+
44+
git clone https://github.com/KhronosGroup/SPIRV-Headers external/SPIRV-Headers
45+
4246
After satisfying the external dependencies create build files using CMake. For example:
4347

4448
mkdir build && cd build

include/CL/opencl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,12 @@ CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_LO
18001800
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_CLOCK_CAPABILITIES_KHR, cl_device_kernel_clock_capabilities_khr)
18011801
#endif /* cl_khr_kernel_clock */
18021802

1803+
#if defined(cl_khr_spirv_queries)
1804+
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_EXTENDED_INSTRUCTION_SETS_KHR, cl::vector<const char*>)
1805+
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_EXTENSIONS_KHR, cl::vector<const char*>)
1806+
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_CAPABILITIES_KHR, cl::vector<cl_uint>)
1807+
#endif /* cl_khr_spirv_queries */
1808+
18031809
#if defined(cl_ext_float_atomics)
18041810
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SINGLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
18051811
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_DOUBLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)

include/layer_util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static inline cl_int writeStringToMemory(
7777
return CL_SUCCESS;
7878
}
7979

80-
static cl_uint getOpenCLVersionFromString(
80+
static cl_version getOpenCLVersionFromString(
8181
const char* str)
8282
{
8383
cl_uint major = 0;
@@ -105,7 +105,7 @@ static cl_uint getOpenCLVersionFromString(
105105
}
106106
}
107107

108-
return (major << 16) | minor;
108+
return CL_MAKE_VERSION(major, minor, 0);
109109
}
110110

111111
static inline bool checkStringForExtension(

include/util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <CL/opencl.hpp>
99
#include <string>
1010

11-
static cl_uint getDeviceOpenCLVersion(
11+
static cl_version getDeviceOpenCLVersion(
1212
const cl::Device& device)
1313
{
1414
cl_uint major = 0;
@@ -36,7 +36,7 @@ static cl_uint getDeviceOpenCLVersion(
3636
}
3737
}
3838

39-
return (major << 16) | minor;
39+
return CL_MAKE_VERSION(major, minor, 0);
4040
}
4141

4242
static bool checkDeviceForExtension(

layers/10_cmdbufemu/emulate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@ bool clGetDeviceInfo_override(
28972897
deviceExtensions.data(),
28982898
CL_KHR_COMMAND_BUFFER_EXTENSION_NAME ) == false &&
28992899
getOpenCLVersionFromString(
2900-
deviceVersion.data() ) >= 0x00020001)
2900+
deviceVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
29012901
{
29022902
std::string newExtensions;
29032903
newExtensions += CL_KHR_COMMAND_BUFFER_EXTENSION_NAME;
@@ -2981,7 +2981,7 @@ bool clGetDeviceInfo_override(
29812981

29822982
if( found == false &&
29832983
getOpenCLVersionFromString(
2984-
deviceVersion.data() ) >= 0x00020001)
2984+
deviceVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
29852985
{
29862986
{
29872987
extensions.emplace_back();
@@ -3246,7 +3246,7 @@ bool clGetPlatformInfo_override(
32463246
platformExtensions.data(),
32473247
CL_KHR_COMMAND_BUFFER_EXTENSION_NAME ) == false &&
32483248
getOpenCLVersionFromString(
3249-
platformVersion.data() ) >= 0x00020001)
3249+
platformVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
32503250
{
32513251
std::string newExtensions;
32523252
newExtensions += CL_KHR_COMMAND_BUFFER_EXTENSION_NAME;
@@ -3330,7 +3330,7 @@ bool clGetPlatformInfo_override(
33303330

33313331
if( found == false &&
33323332
getOpenCLVersionFromString(
3333-
platformVersion.data() ) >= 0x00020001)
3333+
platformVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
33343334
{
33353335
{
33363336
extensions.emplace_back();

layers/11_semaemu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
add_opencl_layer(
6-
NUMBER 10
6+
NUMBER 11
77
TARGET SemaEmu
88
VERSION 300
99
SOURCES main.cpp emulate.cpp emulate.h)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 Ben Ashbaugh
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
add_opencl_layer(
6+
NUMBER 12
7+
TARGET SpirvQueriesEmu
8+
VERSION 300
9+
SOURCES main.cpp emulate.cpp emulate.h
10+
INCLUDES ${SPIRV-Headers_SOURCE_DIR}/include)

0 commit comments

Comments
 (0)