|
3 | 3 | // See LICENSE.TXT
|
4 | 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
5 | 5 |
|
| 6 | +#include "uur/raii.h" |
6 | 7 | #include <uur/fixtures.h>
|
7 | 8 |
|
8 | 9 | using urSamplerCreateWithNativeHandleTest = uur::urSamplerTest;
|
@@ -32,3 +33,84 @@ TEST_P(urSamplerCreateWithNativeHandleTest, Success) {
|
32 | 33 | ASSERT_EQ(addr_mode, sampler_desc.addressingMode);
|
33 | 34 | ASSERT_SUCCESS(urSamplerRelease(hSampler));
|
34 | 35 | }
|
| 36 | + |
| 37 | +TEST_P(urSamplerCreateWithNativeHandleTest, InvalidNullHandle) { |
| 38 | + ur_native_handle_t native_sampler = 0; |
| 39 | + { |
| 40 | + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( |
| 41 | + urSamplerGetNativeHandle(sampler, &native_sampler)); |
| 42 | + } |
| 43 | + |
| 44 | + ur_sampler_handle_t hSampler = nullptr; |
| 45 | + ur_sampler_native_properties_t props{}; |
| 46 | + ASSERT_EQ(urSamplerCreateWithNativeHandle(native_sampler, nullptr, &props, |
| 47 | + &hSampler), |
| 48 | + UR_RESULT_ERROR_INVALID_NULL_HANDLE); |
| 49 | +} |
| 50 | + |
| 51 | +TEST_P(urSamplerCreateWithNativeHandleTest, InvalidNullPointer) { |
| 52 | + ur_native_handle_t native_sampler = 0; |
| 53 | + { |
| 54 | + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( |
| 55 | + urSamplerGetNativeHandle(sampler, &native_sampler)); |
| 56 | + } |
| 57 | + |
| 58 | + ur_sampler_native_properties_t props{}; |
| 59 | + ASSERT_EQ(urSamplerCreateWithNativeHandle(native_sampler, context, &props, |
| 60 | + nullptr), |
| 61 | + UR_RESULT_ERROR_INVALID_NULL_POINTER); |
| 62 | +} |
| 63 | + |
| 64 | +TEST_P(urSamplerCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) { |
| 65 | + |
| 66 | + ur_native_handle_t native_handle = 0; |
| 67 | + uur::raii::Sampler hSampler = nullptr; |
| 68 | + { |
| 69 | + ur_sampler_desc_t sampler_desc{ |
| 70 | + UR_STRUCTURE_TYPE_SAMPLER_DESC, /* stype */ |
| 71 | + nullptr, /* pNext */ |
| 72 | + true, /* normalizedCoords */ |
| 73 | + UR_SAMPLER_ADDRESSING_MODE_NONE, /* addressing mode */ |
| 74 | + UR_SAMPLER_FILTER_MODE_NEAREST, /* filterMode */ |
| 75 | + }; |
| 76 | + |
| 77 | + ASSERT_SUCCESS(urSamplerCreate(context, &sampler_desc, hSampler.ptr())); |
| 78 | + |
| 79 | + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( |
| 80 | + urSamplerGetNativeHandle(hSampler, &native_handle)); |
| 81 | + } |
| 82 | + |
| 83 | + ur_sampler_native_properties_t props = { |
| 84 | + UR_STRUCTURE_TYPE_SAMPLER_NATIVE_PROPERTIES, nullptr, true}; |
| 85 | + ur_sampler_handle_t sampler = nullptr; |
| 86 | + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urSamplerCreateWithNativeHandle( |
| 87 | + native_handle, context, &props, &sampler)); |
| 88 | + ASSERT_NE(sampler, nullptr); |
| 89 | +} |
| 90 | + |
| 91 | +TEST_P(urSamplerCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) { |
| 92 | + |
| 93 | + ur_native_handle_t native_handle = 0; |
| 94 | + uur::raii::Sampler hSampler = nullptr; |
| 95 | + { |
| 96 | + ur_sampler_desc_t sampler_desc{ |
| 97 | + UR_STRUCTURE_TYPE_SAMPLER_DESC, /* stype */ |
| 98 | + nullptr, /* pNext */ |
| 99 | + true, /* normalizedCoords */ |
| 100 | + UR_SAMPLER_ADDRESSING_MODE_NONE, /* addressing mode */ |
| 101 | + UR_SAMPLER_FILTER_MODE_NEAREST, /* filterMode */ |
| 102 | + }; |
| 103 | + |
| 104 | + ASSERT_SUCCESS(urSamplerCreate(context, &sampler_desc, hSampler.ptr())); |
| 105 | + |
| 106 | + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( |
| 107 | + urSamplerGetNativeHandle(hSampler, &native_handle)); |
| 108 | + } |
| 109 | + |
| 110 | + ur_sampler_native_properties_t props = { |
| 111 | + UR_STRUCTURE_TYPE_SAMPLER_NATIVE_PROPERTIES, nullptr, false}; |
| 112 | + ur_sampler_handle_t sampler = nullptr; |
| 113 | + UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urSamplerCreateWithNativeHandle( |
| 114 | + native_handle, context, &props, &sampler)); |
| 115 | + ASSERT_NE(sampler, nullptr); |
| 116 | +} |
0 commit comments