1// Copyright 2019 The Android Open Source Project
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// This file contains common code used by the image decompression shaders.
16
17// DIM is preprocessor macro set by the build script that determines whether the shader will
18// process 1D, 2D or 3D images
19#if DIM == 1
20#define IMG_TYPE 1DArray
21#elif DIM == 2
22#define IMG_TYPE 2DArray
23#elif DIM == 3
24#define IMG_TYPE 3D
25#else
26#error "Please set the `DIM` preprocessor macro to 1, 2 or 3. Example: glslc -DDIM=2"
27#endif
28
29// Concatenates 2 tokens while also performing macro replacement
30//
31// For example:
32//   #define FOO world
33//   CONCAT(hello, FOO)
34//
35// Becomes:
36//   helloworld
37#define CONCAT_(x, y) x##y          // concatenation
38#define CONCAT(x, y) CONCAT_(x, y)  // macro replacement
39
40// Appends the correct image type ("1DArray", "2DArray", or "3D") to x
41#define WITH_TYPE(x) CONCAT(x, IMG_TYPE)
42
43// TODO(gregschlom): do we actually use 1DArray images?
44ivec2 getPos1DArray(ivec3 pos) { return pos.xz; }
45ivec3 getPos2DArray(ivec3 pos) { return pos; }
46ivec3 getPos3D(ivec3 pos) { return pos; }