@@ -239,29 +239,38 @@ ur_result_t urTextureCreate(ur_sampler_handle_t hSampler,
239239
240240 try {
241241 // / pi_sampler_properties
242+ // / Layout of UR samplers for CUDA
243+ // /
244+ // / Sampler property layout:
242245 // / | <bits> | <usage>
243246 // / -----------------------------------
244- // / | 31 30 ... 6 | N/A
245- // / | 5 | mip filter mode
246- // / | 4 3 2 | addressing mode
247+ // / | 31 30 ... 12 | N/A
248+ // / | 11 | mip filter mode
249+ // / | 10 9 8 | addressing mode 3
250+ // / | 7 6 5 | addressing mode 2
251+ // / | 4 3 2 | addressing mode 1
247252 // / | 1 | filter mode
248253 // / | 0 | normalize coords
249254 CUDA_TEXTURE_DESC ImageTexDesc = {};
250- CUaddress_mode AddrMode = {};
251- ur_sampler_addressing_mode_t AddrModeProp = hSampler->getAddressingMode ();
252- if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE -
253- UR_SAMPLER_ADDRESSING_MODE_NONE)) {
254- AddrMode = CU_TR_ADDRESS_MODE_CLAMP;
255- } else if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_CLAMP -
256- UR_SAMPLER_ADDRESSING_MODE_NONE)) {
257- AddrMode = CU_TR_ADDRESS_MODE_BORDER;
258- } else if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_REPEAT -
259- UR_SAMPLER_ADDRESSING_MODE_NONE)) {
260- AddrMode = CU_TR_ADDRESS_MODE_WRAP;
261- } else if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT -
262- UR_SAMPLER_ADDRESSING_MODE_NONE)) {
263- AddrMode = CU_TR_ADDRESS_MODE_MIRROR;
255+ CUaddress_mode AddrMode[3 ];
256+ for (size_t i = 0 ; i < 3 ; i++) {
257+ ur_sampler_addressing_mode_t AddrModeProp =
258+ hSampler->getAddressingModeDim (i);
259+ if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE -
260+ UR_SAMPLER_ADDRESSING_MODE_NONE)) {
261+ AddrMode[i] = CU_TR_ADDRESS_MODE_CLAMP;
262+ } else if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_CLAMP -
263+ UR_SAMPLER_ADDRESSING_MODE_NONE)) {
264+ AddrMode[i] = CU_TR_ADDRESS_MODE_BORDER;
265+ } else if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_REPEAT -
266+ UR_SAMPLER_ADDRESSING_MODE_NONE)) {
267+ AddrMode[i] = CU_TR_ADDRESS_MODE_WRAP;
268+ } else if (AddrModeProp == (UR_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT -
269+ UR_SAMPLER_ADDRESSING_MODE_NONE)) {
270+ AddrMode[i] = CU_TR_ADDRESS_MODE_MIRROR;
271+ }
264272 }
273+
265274 CUfilter_mode FilterMode;
266275 ur_sampler_filter_mode_t FilterModeProp = hSampler->getFilterMode ();
267276 FilterMode =
@@ -278,14 +287,15 @@ ur_result_t urTextureCreate(ur_sampler_handle_t hSampler,
278287 ImageTexDesc.minMipmapLevelClamp = hSampler->MinMipmapLevelClamp ;
279288 ImageTexDesc.maxAnisotropy = static_cast <unsigned >(hSampler->MaxAnisotropy );
280289
281- // The address modes can interfere with other dimensionsenqueueEventsWait
290+ // The address modes can interfere with other dimensions
282291 // e.g. 1D texture sampling can be interfered with when setting other
283292 // dimension address modes despite their nonexistence.
284- ImageTexDesc.addressMode [0 ] = AddrMode; // 1D
285- ImageTexDesc.addressMode [1 ] =
286- pImageDesc->height > 0 ? AddrMode : ImageTexDesc.addressMode [1 ]; // 2D
293+ ImageTexDesc.addressMode [0 ] = AddrMode[0 ]; // 1D
294+ ImageTexDesc.addressMode [1 ] = pImageDesc->height > 0
295+ ? AddrMode[1 ]
296+ : ImageTexDesc.addressMode [1 ]; // 2D
287297 ImageTexDesc.addressMode [2 ] =
288- pImageDesc->depth > 0 ? AddrMode : ImageTexDesc.addressMode [2 ]; // 3D
298+ pImageDesc->depth > 0 ? AddrMode[ 2 ] : ImageTexDesc.addressMode [2 ]; // 3D
289299
290300 // flags takes the normalized coordinates setting -- unnormalized is default
291301 ImageTexDesc.flags = (hSampler->isNormalizedCoords ())
0 commit comments