HIP: Heterogenous-computing Interface for Portability
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hip_texture.h
1 /*
2 Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 #pragma once
23 
28 #include <limits.h>
29 
30 #include <hip_runtime.h>
31 
32 //----
33 //Texture - TODO - likely need to move this to a separate file only included with kernel compilation.
34 #define hipTextureType1D 1
35 
36 typedef struct hipChannelFormatDesc {
37  // TODO - this has 4-5 well-defined fields, we could just copy...
38  int _dummy;
40 
41 typedef enum hipTextureReadMode
42 {
43  hipReadModeElementType,
44 } hipTextureReadMode;
46 
47 typedef enum hipTextureFilterMode
48 {
49  hipFilterModePoint,
50 } hipTextureFilterMode;
52 
54  hipTextureFilterMode filterMode;
55  bool normalized;
56  hipChannelFormatDesc channelDesc;
57 };
58 
59 template <class T, int texType=hipTextureType1D, enum hipTextureReadMode=hipReadModeElementType>
60 struct texture : public textureReference {
61 
62  const T * _dataPtr; // pointer to underlying data.
63 
64  //texture() : filterMode(hipFilterModePoint), normalized(false), _dataPtr(NULL) {};
65 };
66 
67 
68 
69 
70 #define tex1Dfetch(_tex, _addr) (_tex._dataPtr[_addr])
71 
72 
73 
74 
82 // These are C++ APIs - maybe belong in separate file.
106 // C API:
107 #if 0
108 hipChannelFormatDesc hipBindTexture(size_t *offset, struct textureReference *tex, const void *devPtr, const struct hipChannelFormatDesc *desc, size_t size=UINT_MAX)
109 {
110  tex->_dataPtr = devPtr;
111 }
112 #endif
113 
114 /*
115  * @brief hipChannelFormatDesc
116  **/
117 // TODO
118 template <class T>
119 hipChannelFormatDesc hipCreateChannelDesc()
120 {
122  return desc;
123 }
124 
125 /*
126  * @brief hipBindTexture
127  **/
128 // TODO-doc
129 template <class T, int dim, enum hipTextureReadMode readMode>
130 hipError_t hipBindTexture(size_t *offset,
131  struct texture<T, dim, readMode> &tex,
132  const void *devPtr,
133  const struct hipChannelFormatDesc *desc,
134  size_t size=UINT_MAX)
135 {
136  tex._dataPtr = static_cast<const T*>(devPtr);
137 
138  return hipSuccess;
139 }
140 
141 
142 /*
143  * @brief hipBindTexture
144  **/
145 // TODO-doc
146 template <class T, int dim, enum hipTextureReadMode readMode>
147 hipError_t hipBindTexture(size_t *offset,
148  struct texture<T, dim, readMode> &tex,
149  const void *devPtr,
150  size_t size=UINT_MAX)
151 {
152  return hipBindTexture(offset, tex, devPtr, &tex.channelDesc, size);
153 }
154 
155 
156 /*
157  * @brief hipUnbindTexture
158  **/
159 // TODO-doc
160 template <class T, int dim, enum hipTextureReadMode readMode>
161 hipError_t hipUnbindTexture(struct texture<T, dim, readMode> *tex)
162 {
163  tex->_dataPtr = NULL;
164 
165  return hipSuccess;
166 }
167 
168 
169 
170 // doxygen end Texture
176 // End doxygen API:
Successful completion.
Definition: hip_runtime_api.h:113
Definition: hip_texture.h:53
hipError_t
Definition: hip_runtime_api.h:112
Definition: hip_texture.h:36
Definition: hip_texture.h:60