xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/cm/cm_sampler_rt.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2007-2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file      cm_sampler_rt.cpp
24 //! \brief     Contains CmSamplerRT implementations.
25 //!
26 
27 #include "cm_sampler_rt.h"
28 
29 #include "cm_debug.h"
30 #include "cm_mem.h"
31 
32 namespace CMRT_UMD
33 {
34 //*-----------------------------------------------------------------------------
35 //| Purpose:    Create CmSampler
36 //| Returns:    Result of the operation.
37 //*-----------------------------------------------------------------------------
Create(uint32_t index,CmSamplerRT * & sampler)38 int32_t CmSamplerRT::Create( uint32_t index, CmSamplerRT* & sampler )
39 {
40     int32_t result = CM_SUCCESS;
41     sampler = new (std::nothrow) CmSamplerRT();
42     if( sampler )
43     {
44         result = sampler->Initialize( index );
45         if( result != CM_SUCCESS )
46         {
47             CmSamplerRT::Destroy( sampler );
48         }
49     }
50     else
51     {
52         CM_ASSERTMESSAGE("Error: Failed to create CmSampler due to out of system memory.")
53         result = CM_OUT_OF_HOST_MEMORY;
54     }
55     return result;
56 }
57 
58 //*-----------------------------------------------------------------------------
59 //| Purpose:    Destory CmSampler
60 //| Returns:    Result of the operation.
61 //*-----------------------------------------------------------------------------
Destroy(CmSamplerRT * & sampler)62 int32_t CmSamplerRT::Destroy( CmSamplerRT* &sampler )
63 {
64     CmSafeDelete( sampler );
65 
66     return CM_SUCCESS;
67 }
68 
69 //*-----------------------------------------------------------------------------
70 //| Purpose:    Construtor of CmSamplerRT
71 //| Returns:    Result of the operation.
72 //*-----------------------------------------------------------------------------
CmSamplerRT(void)73 CmSamplerRT::CmSamplerRT( void ):
74                     m_index( nullptr )
75 {
76 }
77 
78 //*-----------------------------------------------------------------------------
79 //| Purpose:    Destructor of CmSamplerRT
80 //| Returns:    Result of the operation.
81 //*-----------------------------------------------------------------------------
~CmSamplerRT(void)82 CmSamplerRT::~CmSamplerRT( void )
83 {
84     if( m_index )
85     {
86         MOS_Delete(m_index);
87     }
88 }
89 
90 //*-----------------------------------------------------------------------------
91 //| Purpose:    Initialize  CmSamplerRT and get its index
92 //| Returns:    Result of the operation.
93 //*-----------------------------------------------------------------------------
Initialize(uint32_t index)94 int32_t CmSamplerRT::Initialize( uint32_t index )
95 {
96     // using CM compiler data structures
97     m_index = MOS_New(SamplerIndex, index);
98     if( m_index )
99     {
100         return CM_SUCCESS;
101     }
102     else
103     {
104         return CM_OUT_OF_HOST_MEMORY;
105     }
106 }
107 
108 //*-----------------------------------------------------------------------------
109 //! Each CmSamplerRT is assigned an index when it is created by the CmDevice_RT.
110 //! CmDevice_RT keep a mapping b/w index and CmSamplerRT.
111 //! The index is passed to CM kernel function (genx_main) as argument to indicate sampler.
112 //! INPUT:
113 //!     Reference to index
114 //! OUTPUT:
115 //!     CM_SUCCESS if index is successfully returned
116 //*-----------------------------------------------------------------------------
GetIndex(SamplerIndex * & index)117 CM_RT_API int32_t CmSamplerRT::GetIndex( SamplerIndex* & index )
118 {
119     index = m_index;
120     return CM_SUCCESS;
121 }
122 
123 }  // namespace
124