|
14 | 14 | UR_APIEXPORT ur_result_t UR_APICALL |
15 | 15 | urSamplerCreate(ur_context_handle_t hContext, const ur_sampler_desc_t *pDesc, |
16 | 16 | ur_sampler_handle_t *phSampler) { |
17 | | - std::unique_ptr<ur_sampler_handle_t_> Sampler{ |
18 | | - new ur_sampler_handle_t_(hContext)}; |
| 17 | + try { |
| 18 | + std::unique_ptr<ur_sampler_handle_t_> Sampler{ |
| 19 | + new ur_sampler_handle_t_(hContext)}; |
19 | 20 |
|
20 | | - if (pDesc->stype == UR_STRUCTURE_TYPE_SAMPLER_DESC) { |
21 | | - Sampler->Props |= static_cast<uint32_t>(pDesc->normalizedCoords); |
22 | | - Sampler->Props |= pDesc->filterMode << 1; |
23 | | - Sampler->Props |= pDesc->addressingMode << 2; |
24 | | - } else { |
25 | | - // Set default values |
26 | | - Sampler->Props |= true; // Normalized Coords |
27 | | - Sampler->Props |= UR_SAMPLER_ADDRESSING_MODE_CLAMP << 2; |
28 | | - } |
| 21 | + if (pDesc->stype == UR_STRUCTURE_TYPE_SAMPLER_DESC) { |
| 22 | + Sampler->Props |= static_cast<uint32_t>(pDesc->normalizedCoords); |
| 23 | + Sampler->Props |= pDesc->filterMode << 1; |
| 24 | + Sampler->Props |= pDesc->addressingMode << 2; |
| 25 | + } else { |
| 26 | + // Set default values |
| 27 | + Sampler->Props |= true; // Normalized Coords |
| 28 | + Sampler->Props |= UR_SAMPLER_ADDRESSING_MODE_CLAMP << 2; |
| 29 | + } |
29 | 30 |
|
30 | | - void *pNext = const_cast<void *>(pDesc->pNext); |
31 | | - while (pNext != nullptr) { |
32 | | - const ur_base_desc_t *BaseDesc = |
33 | | - reinterpret_cast<const ur_base_desc_t *>(pNext); |
34 | | - if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES) { |
35 | | - const ur_exp_sampler_mip_properties_t *SamplerMipProperties = |
36 | | - reinterpret_cast<const ur_exp_sampler_mip_properties_t *>(pNext); |
37 | | - Sampler->MaxMipmapLevelClamp = SamplerMipProperties->maxMipmapLevelClamp; |
38 | | - Sampler->MinMipmapLevelClamp = SamplerMipProperties->minMipmapLevelClamp; |
39 | | - Sampler->MaxAnisotropy = SamplerMipProperties->maxAnisotropy; |
40 | | - Sampler->Props |= SamplerMipProperties->mipFilterMode << 11; |
41 | | - } else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_SAMPLER_ADDR_MODES) { |
42 | | - const ur_exp_sampler_addr_modes_t *SamplerAddrModes = |
43 | | - reinterpret_cast<const ur_exp_sampler_addr_modes_t *>(pNext); |
44 | | - Sampler->Props |= SamplerAddrModes->addrModes[0] << 2; |
45 | | - Sampler->Props |= SamplerAddrModes->addrModes[1] << 5; |
46 | | - Sampler->Props |= SamplerAddrModes->addrModes[2] << 8; |
47 | | - } else if (BaseDesc->stype == |
48 | | - UR_STRUCTURE_TYPE_EXP_SAMPLER_CUBEMAP_PROPERTIES) { |
49 | | - const ur_exp_sampler_cubemap_properties_t *SamplerCubemapProperties = |
50 | | - reinterpret_cast<const ur_exp_sampler_cubemap_properties_t *>(pNext); |
51 | | - Sampler->Props |= SamplerCubemapProperties->cubemapFilterMode << 12; |
| 31 | + void *pNext = const_cast<void *>(pDesc->pNext); |
| 32 | + while (pNext != nullptr) { |
| 33 | + const ur_base_desc_t *BaseDesc = |
| 34 | + reinterpret_cast<const ur_base_desc_t *>(pNext); |
| 35 | + if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES) { |
| 36 | + const ur_exp_sampler_mip_properties_t *SamplerMipProperties = |
| 37 | + reinterpret_cast<const ur_exp_sampler_mip_properties_t *>(pNext); |
| 38 | + Sampler->MaxMipmapLevelClamp = |
| 39 | + SamplerMipProperties->maxMipmapLevelClamp; |
| 40 | + Sampler->MinMipmapLevelClamp = |
| 41 | + SamplerMipProperties->minMipmapLevelClamp; |
| 42 | + Sampler->MaxAnisotropy = SamplerMipProperties->maxAnisotropy; |
| 43 | + Sampler->Props |= SamplerMipProperties->mipFilterMode << 11; |
| 44 | + } else if (BaseDesc->stype == UR_STRUCTURE_TYPE_EXP_SAMPLER_ADDR_MODES) { |
| 45 | + const ur_exp_sampler_addr_modes_t *SamplerAddrModes = |
| 46 | + reinterpret_cast<const ur_exp_sampler_addr_modes_t *>(pNext); |
| 47 | + Sampler->Props |= SamplerAddrModes->addrModes[0] << 2; |
| 48 | + Sampler->Props |= SamplerAddrModes->addrModes[1] << 5; |
| 49 | + Sampler->Props |= SamplerAddrModes->addrModes[2] << 8; |
| 50 | + } else if (BaseDesc->stype == |
| 51 | + UR_STRUCTURE_TYPE_EXP_SAMPLER_CUBEMAP_PROPERTIES) { |
| 52 | + const ur_exp_sampler_cubemap_properties_t *SamplerCubemapProperties = |
| 53 | + reinterpret_cast<const ur_exp_sampler_cubemap_properties_t *>( |
| 54 | + pNext); |
| 55 | + Sampler->Props |= SamplerCubemapProperties->cubemapFilterMode << 12; |
| 56 | + } |
| 57 | + pNext = const_cast<void *>(BaseDesc->pNext); |
52 | 58 | } |
53 | | - pNext = const_cast<void *>(BaseDesc->pNext); |
54 | | - } |
55 | 59 |
|
56 | | - *phSampler = Sampler.release(); |
| 60 | + *phSampler = Sampler.release(); |
| 61 | + } catch (std::bad_alloc &) { |
| 62 | + return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; |
| 63 | + } catch (...) { |
| 64 | + return UR_RESULT_ERROR_UNKNOWN; |
| 65 | + } |
57 | 66 | return UR_RESULT_SUCCESS; |
58 | 67 | } |
59 | 68 |
|
|
0 commit comments