HIP: Heterogenous-computing Interface for Portability
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hip_texture.h
Go to the documentation of this file.
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 {
46 
48 {
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 Returns a channel descriptor with format f and number of bits of each ocmponent x,y,z and w.
116  *
117  * @par Parameters
118  * None.
119  * @return Channel descriptor
120  *
121  *
122  **/
123 template <class T>
124 hipChannelFormatDesc hipCreateChannelDesc()
125 {
127  return desc;
128 }
129 
130 /*
131  * @brief hipBindTexture Binds size bytes of the memory area pointed to by @p devPtr to the texture reference tex.
132  *
133  * @p desc describes how the memory is interpreted when fetching values from the texture. The @p offset parameter is an optional byte offset as with the low-level
134  * hipBindTexture() function. Any memory previously bound to tex is unbound.
135  *
136  * @param[in] offset - Offset in bytes
137  * @param[out] tex - texture to bind
138  * @param[in] devPtr - Memory area on device
139  * @param[in] desc - Channel format
140  * @param[in] size - Size of the memory area pointed to by devPtr
141  * @return #hipSuccess, #hipErrorInvalidValue, #hipErrorMemoryFree, #hipErrorUnknown
142  **/
143 template <class T, int dim, enum hipTextureReadMode readMode>
144 hipError_t hipBindTexture(size_t *offset,
145  struct texture<T, dim, readMode> &tex,
146  const void *devPtr,
147  const struct hipChannelFormatDesc *desc,
148  size_t size=UINT_MAX)
149 {
150  tex._dataPtr = static_cast<const T*>(devPtr);
151 
152  return hipSuccess;
153 }
154 
155 /*
156  * @brief hipBindTexture Binds size bytes of the memory area pointed to by @p devPtr to the texture reference tex.
157  *
158  * @p desc describes how the memory is interpreted when fetching values from the texture. The @p offset parameter is an optional byte offset as with the low-level
159  * hipBindTexture() function. Any memory previously bound to tex is unbound.
160  *
161  * @param[in] offset - Offset in bytes
162  * @param[in] tex - texture to bind
163  * @param[in] devPtr - Memory area on device
164  * @param[in] size - Size of the memory area pointed to by devPtr
165  * @return #hipSuccess, #hipErrorInvalidValue, #hipErrorMemoryFree, #hipErrorUnknown
166  **/
167 template <class T, int dim, enum hipTextureReadMode readMode>
168 hipError_t hipBindTexture(size_t *offset,
169  struct texture<T, dim, readMode> &tex,
170  const void *devPtr,
171  size_t size=UINT_MAX)
172 {
173  return hipBindTexture(offset, tex, devPtr, &tex.channelDesc, size);
174 }
175 
176 
177 /*
178  * @brief Unbinds the textuer bound to @p tex
179  *
180  * @param[in] tex - texture to unbind
181  *
182  * @return #hipSuccess
183  **/
184 template <class T, int dim, enum hipTextureReadMode readMode>
185 hipError_t hipUnbindTexture(struct texture<T, dim, readMode> *tex)
186 {
187  tex->_dataPtr = NULL;
188 
189  return hipSuccess;
190 }
191 
192 
193 
194 // doxygen end Texture
200 // End doxygen API:
Definition: hip_texture.h:43
Successful completion.
Definition: hip_runtime_api.h:143
Definition: hip_texture.h:49
Definition: hip_texture.h:53
Contains definitions of APIs for HIP runtime.
hipError_t
Definition: hip_runtime_api.h:142
hipTextureReadMode
Definition: hip_texture.h:41
hipTextureFilterMode
Definition: hip_texture.h:47
Definition: hip_texture.h:36
Definition: hip_texture.h:60