• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/lite/delegates/gpu/gl/gl_texture_helper.h"
17 
18 #include "tensorflow/lite/delegates/gpu/common/data_type.h"
19 #include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h"
20 
21 namespace tflite {
22 namespace gpu {
23 namespace gl {
24 
ToTextureFormat(DataType type)25 GLenum ToTextureFormat(DataType type) {
26   switch (type) {
27     case DataType::INT8:
28     case DataType::UINT16:
29     case DataType::UINT32:
30     case DataType::INT16:
31     case DataType::INT32:
32       return GL_RGBA_INTEGER;
33     case DataType::FLOAT16:
34     case DataType::FLOAT32:
35     case DataType::UINT8:  // this requires GL_RGBA8 internal format
36       return GL_RGBA;
37     default:
38       return 0;
39   }
40 }
41 
ToTextureInternalFormat(DataType type)42 GLenum ToTextureInternalFormat(DataType type) {
43   switch (type) {
44     case DataType::UINT8:
45       return GL_RGBA8;  // this requires GL_RGBA format
46     case DataType::INT8:
47       return GL_RGBA8I;
48     case DataType::UINT16:
49       return GL_RGBA16UI;
50     case DataType::UINT32:
51       return GL_RGBA32UI;
52     case DataType::INT16:
53       return GL_RGBA16I;
54     case DataType::INT32:
55       return GL_RGBA32I;
56     case DataType::FLOAT16:
57       return GL_RGBA16F;
58     case DataType::FLOAT32:
59       return GL_RGBA32F;
60     default:
61       return 0;
62   }
63 }
64 
ToTextureDataType(DataType type)65 GLenum ToTextureDataType(DataType type) {
66   switch (type) {
67     case DataType::UINT8:
68       return GL_UNSIGNED_BYTE;
69     case DataType::INT8:
70       return GL_BYTE;
71     case DataType::UINT16:
72       return GL_UNSIGNED_SHORT;
73     case DataType::UINT32:
74       return GL_UNSIGNED_INT;
75     case DataType::INT16:
76       return GL_SHORT;
77     case DataType::INT32:
78       return GL_INT;
79     case DataType::FLOAT16:
80       return GL_HALF_FLOAT;
81     case DataType::FLOAT32:
82       return GL_FLOAT;
83     default:
84       return 0;
85   }
86 }
87 
88 }  // namespace gl
89 }  // namespace gpu
90 }  // namespace tflite
91