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 
23 //#pragma once
24 
25 #ifndef HIP_TEXTURE_H
26 #define HIP_TEXTURE_H
27 
33 #include <limits.h>
34 
35 #include <hip/hip_runtime.h>
36 
37 //----
38 //Texture - TODO - likely need to move this to a separate file only included with kernel compilation.
39 #define hipTextureType1D 1
40 
41 typedef struct hipChannelFormatDesc {
42  // TODO - this has 4-5 well-defined fields, we could just copy...
43  int _dummy;
45 
46 typedef enum hipTextureReadMode
47 {
51 
53 {
57 
59  hipTextureFilterMode filterMode;
60  bool normalized;
61  hipChannelFormatDesc channelDesc;
62 };
63 #if __cplusplus
64 template <class T, int texType=hipTextureType1D, enum hipTextureReadMode=hipReadModeElementType>
65 struct texture : public textureReference {
66 
67  const T * _dataPtr; // pointer to underlying data.
68 
69  //texture() : filterMode(hipFilterModePoint), normalized(false), _dataPtr(NULL) {};
70 };
71 #endif
72 
73 
74 
75 #define tex1Dfetch(_tex, _addr) (_tex._dataPtr[_addr])
76 
77 
78 
79 
87 // These are C++ APIs - maybe belong in separate file.
111 // C API:
112 #if 0
113 hipChannelFormatDesc hipBindTexture(size_t *offset, struct textureReference *tex, const void *devPtr, const struct hipChannelFormatDesc *desc, size_t size=UINT_MAX)
114 {
115  tex->_dataPtr = devPtr;
116 }
117 #endif
118 
119 /*
120  * @brief Returns a channel descriptor with format f and number of bits of each ocmponent x,y,z and w.
121  *
122  * @par Parameters
123  * None.
124  * @return Channel descriptor
125  *
126  *
127  **/
128 template <class T>
129 hipChannelFormatDesc hipCreateChannelDesc()
130 {
132  return desc;
133 }
134 
135 /*
136  * @brief hipBindTexture Binds size bytes of the memory area pointed to by @p devPtr to the texture reference tex.
137  *
138  * @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
139  * hipBindTexture() function. Any memory previously bound to tex is unbound.
140  *
141  * @param[in] offset - Offset in bytes
142  * @param[out] tex - texture to bind
143  * @param[in] devPtr - Memory area on device
144  * @param[in] desc - Channel format
145  * @param[in] size - Size of the memory area pointed to by devPtr
146  * @return #hipSuccess, #hipErrorInvalidValue, #hipErrorMemoryFree, #hipErrorUnknown
147  **/
148 template <class T, int dim, enum hipTextureReadMode readMode>
149 hipError_t hipBindTexture(size_t *offset,
150  struct texture<T, dim, readMode> &tex,
151  const void *devPtr,
152  const struct hipChannelFormatDesc *desc,
153  size_t size=UINT_MAX)
154 {
155  tex._dataPtr = static_cast<const T*>(devPtr);
156 
157  return hipSuccess;
158 }
159 
160 /*
161  * @brief hipBindTexture Binds size bytes of the memory area pointed to by @p devPtr to the texture reference tex.
162  *
163  * @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
164  * hipBindTexture() function. Any memory previously bound to tex is unbound.
165  *
166  * @param[in] offset - Offset in bytes
167  * @param[in] tex - texture to bind
168  * @param[in] devPtr - Memory area on device
169  * @param[in] size - Size of the memory area pointed to by devPtr
170  * @return #hipSuccess, #hipErrorInvalidValue, #hipErrorMemoryFree, #hipErrorUnknown
171  **/
172 template <class T, int dim, enum hipTextureReadMode readMode>
173 hipError_t hipBindTexture(size_t *offset,
174  struct texture<T, dim, readMode> &tex,
175  const void *devPtr,
176  size_t size=UINT_MAX)
177 {
178  return hipBindTexture(offset, tex, devPtr, &tex.channelDesc, size);
179 }
180 
181 
182 /*
183  * @brief Unbinds the textuer bound to @p tex
184  *
185  * @param[in] tex - texture to unbind
186  *
187  * @return #hipSuccess
188  **/
189 template <class T, int dim, enum hipTextureReadMode readMode>
190 hipError_t hipUnbindTexture(struct texture<T, dim, readMode> *tex)
191 {
192  tex->_dataPtr = NULL;
193 
194  return hipSuccess;
195 }
196 
197 
198 
199 // doxygen end Texture
205 // End doxygen API:
210 #endif
211 
Definition: hip_texture.h:48
Successful completion.
Definition: hip_runtime_api.h:143
Definition: hip_texture.h:54
Definition: hip_texture.h:58
hipError_t
Definition: hip_runtime_api.h:142
hipTextureReadMode
Definition: hip_texture.h:46
hipTextureFilterMode
Definition: hip_texture.h:52
Definition: hip_texture.h:41