Skip to content

Commit b11a19b

Browse files
authored
[Bindless][SYCL][Doc] Add HintT tparam to cubemap fetch and sample (intel#13742)
Add HintT template parameter to the fetch_cubemap and sample_cubemap funcs in the bindless spec. Add HintT template parameter and doxygen to the fetch_cubemap and sample_cubemap implementation. Modify existing cubemap_sampled.cpp test to test the sampling with a user-defined type.
1 parent ecc812d commit b11a19b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_bindless_images.asciidoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,13 +1506,13 @@ sampling depends on the sampler attributes passed upon creation of the cubemap.
15061506

15071507
```c++
15081508
// Unsampled cubemap read
1509-
template <typename DataT>
1509+
template <typename DataT, typename HintT = DataT>
15101510
DataT fetch_cubemap(const unsampled_image_handle &ImageHandle,
15111511
const int2 &Coords,
15121512
const int Face);
15131513

15141514
// Sampled cubemap read
1515-
template <typename DataT>
1515+
template <typename DataT, typename HintT = DataT>
15161516
DataT sample_cubemap(const sampled_image_handle &ImageHandle,
15171517
const float3 &Vec);
15181518

@@ -2684,4 +2684,6 @@ These features still need to be handled:
26842684
parameter.
26852685
|5.7|2024-04-09| - Allow fetching of sampled image data through the
26862686
`fetch_image` API.
2687+
|5.8|2024-05-09| - Add missing cubemap `HintT` template parameter to
2688+
`fetch_cubemap` and `sample_cubemap`.
26872689
|======================

sycl/include/sycl/ext/oneapi/bindless_images.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,22 +1244,30 @@ DataT fetch_image_array(const unsampled_image_handle &imageHandle
12441244
* @brief Fetch data from an unsampled cubemap image using its handle
12451245
*
12461246
* @tparam DataT The return type
1247+
* @tparam HintT A hint type that can be used to select for a specialized
1248+
* backend intrinsic when a user-defined type is passed as `DataT`.
1249+
* HintT should be a `sycl::vec` type, `sycl::half` type, or POD type.
1250+
* HintT must also have the same size as DataT.
12471251
*
12481252
* @param imageHandle The image handle
12491253
* @param coords The coordinates at which to fetch image data (int2 only)
12501254
* @param face The cubemap face at which to fetch
12511255
* @return Image data
12521256
*/
1253-
template <typename DataT>
1257+
template <typename DataT, typename HintT = DataT>
12541258
DataT fetch_cubemap(const unsampled_image_handle &imageHandle,
12551259
const int2 &coords, const unsigned int face) {
1256-
return fetch_image_array<DataT>(imageHandle, coords, face);
1260+
return fetch_image_array<DataT, HintT>(imageHandle, coords, face);
12571261
}
12581262

12591263
/**
12601264
* @brief Sample a cubemap image using its handle
12611265
*
12621266
* @tparam DataT The return type
1267+
* @tparam HintT A hint type that can be used to select for a specialized
1268+
* backend intrinsic when a user-defined type is passed as `DataT`.
1269+
* HintT should be a `sycl::vec` type, `sycl::half` type, or POD type.
1270+
* HintT must also have the same size as DataT.
12631271
*
12641272
* @param imageHandle The image handle
12651273
* @param dirVec The direction vector at which to sample image data (float3
@@ -1280,7 +1288,7 @@ DataT sample_cubemap(const sampled_image_handle &imageHandle [[maybe_unused]],
12801288
"the same size as the user-defined DataT.");
12811289
static_assert(detail::is_recognized_standard_type<HintT>(),
12821290
"HintT must always be a recognized standard type");
1283-
return sycl::bit_cast<DataT>(__invoke__ImageReadCubemap<DataT, uint64_t>(
1291+
return sycl::bit_cast<DataT>(__invoke__ImageReadCubemap<HintT, uint64_t>(
12841292
imageHandle.raw_handle, dirVec));
12851293
}
12861294
#else

sycl/test-e2e/bindless_images/cubemap/cubemap_sampled.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %{build} -o %t.out
55
// RUN: %{run} %t.out
66

7+
#include "../user_types/user_types_common.hpp"
78
#include <iostream>
89
#include <sycl/sycl.hpp>
910

@@ -27,12 +28,12 @@ int main() {
2728
size_t N = width * height;
2829
std::vector<float> out(N);
2930
std::vector<float> expected(N);
30-
std::vector<sycl::float4> dataIn1(N * 6);
31+
std::vector<sycl::float4> dataIn(N * 6);
3132
for (int i = 0; i < width; i++) {
3233
for (int j = 0; j < height; j++) {
3334
for (int k = 0; k < 6; k++) {
34-
dataIn1[i + width * (j + height * k)] = {i + width * (j + height * k),
35-
0, 0, 0};
35+
dataIn[i + width * (j + height * k)] = {i + width * (j + height * k), 0,
36+
0, 0};
3637
}
3738
}
3839
}
@@ -63,7 +64,7 @@ int main() {
6364

6465
// Extension: copy over data to device (handler variant).
6566
q.submit([&](sycl::handler &cgh) {
66-
cgh.ext_oneapi_copy(dataIn1.data(), imgMem.get_handle(), desc);
67+
cgh.ext_oneapi_copy(dataIn.data(), imgMem.get_handle(), desc);
6768
});
6869
q.wait_and_throw();
6970

@@ -95,11 +96,13 @@ int main() {
9596
float fdim2 = (((float(dim1) / (float)height) * 1.98) - 0.99) +
9697
(1.f / (float)height);
9798

99+
my_float4 myPixel{};
100+
98101
// Extension: sample cubemap data from handle.
99-
sycl::float4 px = syclexp::sample_cubemap<sycl::float4>(
102+
myPixel = syclexp::sample_cubemap<my_float4, sycl::float4>(
100103
imgHandle, sycl::float3(fdim0, fdim1, fdim2));
101104

102-
outAcc[sycl::id<2>{dim0, dim1}] = px[0];
105+
outAcc[sycl::id<2>{dim0, dim1}] = myPixel.x;
103106
});
104107
});
105108
q.wait_and_throw();

0 commit comments

Comments
 (0)