1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright 2012 Francisco Jerez
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Permission is hereby granted, free of charge, to any person obtaining a
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// copy of this software and associated documentation files (the "Software"),
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to deal in the Software without restriction, including without limitation
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and/or sell copies of the Software, and to permit persons to whom the
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Software is furnished to do so, subject to the following conditions:
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The above copyright notice and this permission notice shall be included in
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// all copies or substantial portions of the Software.
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// SOFTWARE.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <algorithm>
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "core/format.hpp"
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "core/memory.hpp"
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_screen.h"
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_context.h"
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace clover {
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   static const std::map<cl_image_format, pipe_format> formats {
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_BGRA, CL_UNORM_INT8 }, PIPE_FORMAT_B8G8R8A8_UNORM },
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_ARGB, CL_UNORM_INT8 }, PIPE_FORMAT_A8R8G8B8_UNORM },
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_UNORM_SHORT_565 }, PIPE_FORMAT_B5G6R5_UNORM },
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_UNORM_INT8 }, PIPE_FORMAT_L8_UNORM },
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_UNORM_INT8 }, PIPE_FORMAT_A8_UNORM },
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_UNORM_INT8 }, PIPE_FORMAT_I8_UNORM },
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_UNORM_INT16 }, PIPE_FORMAT_L16_UNORM },
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_FLOAT }, PIPE_FORMAT_R32_FLOAT },
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_FLOAT }, PIPE_FORMAT_R32G32_FLOAT },
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_FLOAT }, PIPE_FORMAT_R32G32B32_FLOAT },
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_FLOAT }, PIPE_FORMAT_R32G32B32A32_FLOAT },
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_UNORM_INT16 }, PIPE_FORMAT_R16_UNORM },
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_UNORM_INT16 }, PIPE_FORMAT_R16G16_UNORM },
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_UNORM_INT16 }, PIPE_FORMAT_R16G16B16_UNORM },
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_UNORM_INT16 }, PIPE_FORMAT_R16G16B16A16_UNORM },
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_SNORM_INT16 }, PIPE_FORMAT_R16_SNORM },
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_SNORM_INT16 }, PIPE_FORMAT_R16G16_SNORM },
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_SNORM_INT16 }, PIPE_FORMAT_R16G16B16_SNORM },
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_SNORM_INT16 }, PIPE_FORMAT_R16G16B16A16_SNORM },
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_UNORM_INT8 }, PIPE_FORMAT_R8_UNORM },
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_UNORM_INT8 }, PIPE_FORMAT_R8G8_UNORM },
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_UNORM_INT8 }, PIPE_FORMAT_R8G8B8_UNORM },
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_UNORM_INT8 }, PIPE_FORMAT_R8G8B8A8_UNORM },
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_SNORM_INT8 }, PIPE_FORMAT_R8_SNORM },
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_SNORM_INT8 }, PIPE_FORMAT_R8G8_SNORM },
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_SNORM_INT8 }, PIPE_FORMAT_R8G8B8_SNORM },
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_SNORM_INT8 }, PIPE_FORMAT_R8G8B8A8_SNORM },
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_HALF_FLOAT }, PIPE_FORMAT_R16_FLOAT },
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_HALF_FLOAT }, PIPE_FORMAT_R16G16_FLOAT },
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_HALF_FLOAT }, PIPE_FORMAT_R16G16B16_FLOAT },
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_HALF_FLOAT }, PIPE_FORMAT_R16G16B16A16_FLOAT },
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBx, CL_UNORM_SHORT_555 }, PIPE_FORMAT_B5G5R5X1_UNORM },
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBx, CL_UNORM_INT8 }, PIPE_FORMAT_R8G8B8X8_UNORM },
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_UNORM_INT16 }, PIPE_FORMAT_A16_UNORM },
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_UNORM_INT16 }, PIPE_FORMAT_I16_UNORM },
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_SNORM_INT8 }, PIPE_FORMAT_L8_SNORM },
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_SNORM_INT8 }, PIPE_FORMAT_I8_SNORM },
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_SNORM_INT16 }, PIPE_FORMAT_A16_SNORM },
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_SNORM_INT16 }, PIPE_FORMAT_L16_SNORM },
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_SNORM_INT16 }, PIPE_FORMAT_I16_SNORM },
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_HALF_FLOAT }, PIPE_FORMAT_A16_FLOAT },
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_HALF_FLOAT }, PIPE_FORMAT_L16_FLOAT },
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_HALF_FLOAT }, PIPE_FORMAT_I16_FLOAT },
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_FLOAT }, PIPE_FORMAT_A32_FLOAT },
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_FLOAT }, PIPE_FORMAT_L32_FLOAT },
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_FLOAT }, PIPE_FORMAT_I32_FLOAT },
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RA, CL_UNORM_INT8 }, PIPE_FORMAT_R8A8_UNORM },
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_UNSIGNED_INT8 }, PIPE_FORMAT_R8_UINT },
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_UNSIGNED_INT8 }, PIPE_FORMAT_R8G8_UINT },
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_UNSIGNED_INT8 }, PIPE_FORMAT_R8G8B8_UINT },
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_UNSIGNED_INT8 }, PIPE_FORMAT_R8G8B8A8_UINT },
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_SIGNED_INT8 }, PIPE_FORMAT_R8_SINT },
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_SIGNED_INT8 }, PIPE_FORMAT_R8G8_SINT },
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_SIGNED_INT8 }, PIPE_FORMAT_R8G8B8_SINT },
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_SIGNED_INT8 }, PIPE_FORMAT_R8G8B8A8_SINT },
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_UNSIGNED_INT16 }, PIPE_FORMAT_R16_UINT },
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_UNSIGNED_INT16 }, PIPE_FORMAT_R16G16_UINT },
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_UNSIGNED_INT16 }, PIPE_FORMAT_R16G16B16_UINT },
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_UNSIGNED_INT16 }, PIPE_FORMAT_R16G16B16A16_UINT },
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_SIGNED_INT16 }, PIPE_FORMAT_R16_SINT },
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_SIGNED_INT16 }, PIPE_FORMAT_R16G16_SINT },
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_SIGNED_INT16 }, PIPE_FORMAT_R16G16B16_SINT },
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_SIGNED_INT16 }, PIPE_FORMAT_R16G16B16A16_SINT },
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_UNSIGNED_INT32 }, PIPE_FORMAT_R32_UINT },
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_UNSIGNED_INT32 }, PIPE_FORMAT_R32G32_UINT },
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_UNSIGNED_INT32 }, PIPE_FORMAT_R32G32B32_UINT },
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_UNSIGNED_INT32 }, PIPE_FORMAT_R32G32B32A32_UINT },
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_R, CL_SIGNED_INT32 }, PIPE_FORMAT_R32_SINT },
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RG, CL_SIGNED_INT32 }, PIPE_FORMAT_R32G32_SINT },
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGB, CL_SIGNED_INT32 }, PIPE_FORMAT_R32G32B32_SINT },
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_RGBA, CL_SIGNED_INT32 }, PIPE_FORMAT_R32G32B32A32_SINT },
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_UNSIGNED_INT8 }, PIPE_FORMAT_A8_UINT },
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_UNSIGNED_INT8 }, PIPE_FORMAT_I8_UINT },
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_UNSIGNED_INT8 }, PIPE_FORMAT_L8_UINT },
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_SIGNED_INT8 }, PIPE_FORMAT_A8_SINT },
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_SIGNED_INT8 }, PIPE_FORMAT_I8_SINT },
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_SIGNED_INT8 }, PIPE_FORMAT_L8_SINT },
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_UNSIGNED_INT16 }, PIPE_FORMAT_A16_UINT },
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_UNSIGNED_INT16 }, PIPE_FORMAT_I16_UINT },
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_UNSIGNED_INT16 }, PIPE_FORMAT_L16_UINT },
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_SIGNED_INT16 }, PIPE_FORMAT_A16_SINT },
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_SIGNED_INT16 }, PIPE_FORMAT_I16_SINT },
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_SIGNED_INT16 }, PIPE_FORMAT_L16_SINT },
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_UNSIGNED_INT32 }, PIPE_FORMAT_A32_UINT },
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_UNSIGNED_INT32 }, PIPE_FORMAT_I32_UINT },
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_UNSIGNED_INT32 }, PIPE_FORMAT_L32_UINT },
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_A, CL_SIGNED_INT32 }, PIPE_FORMAT_A32_SINT },
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_INTENSITY, CL_SIGNED_INT32 }, PIPE_FORMAT_I32_SINT },
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      { { CL_LUMINANCE, CL_SIGNED_INT32 }, PIPE_FORMAT_L32_SINT }
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   };
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe_texture_target
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   translate_target(cl_mem_object_type type) {
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      switch (type) {
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case CL_MEM_OBJECT_BUFFER:
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return PIPE_BUFFER;
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case CL_MEM_OBJECT_IMAGE2D:
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return PIPE_TEXTURE_2D;
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case CL_MEM_OBJECT_IMAGE3D:
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return PIPE_TEXTURE_3D;
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      default:
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         throw error(CL_INVALID_VALUE);
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe_format
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   translate_format(const cl_image_format &format) {
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      auto it = formats.find(format);
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (it == formats.end())
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return it->second;
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   std::set<cl_image_format>
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   supported_formats(cl_context ctx, cl_mem_object_type type) {
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      std::set<cl_image_format> s;
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pipe_texture_target target = translate_target(type);
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned bindings = (PIPE_BIND_SAMPLER_VIEW |
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           PIPE_BIND_COMPUTE_RESOURCE |
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           PIPE_BIND_TRANSFER_READ |
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           PIPE_BIND_TRANSFER_WRITE);
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      for (auto f : formats) {
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         if (std::all_of(ctx->devs.begin(), ctx->devs.end(),
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         [=](const device *dev) {
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            return dev->pipe->is_format_supported(
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                               dev->pipe, f.second, target, 1, bindings);
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         }))
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            s.insert(f.first);
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return s;
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
168