• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4 //
5 // clspv_utils:
6 //     Utilities to map clspv interface variables to OpenCL and Vulkan mappings.
7 //
8 
9 #ifndef LIBANGLE_RENDERER_VULKAN_CLSPV_UTILS_H_
10 #define LIBANGLE_RENDERER_VULKAN_CLSPV_UTILS_H_
11 
12 #include <string>
13 #include <vector>
14 
15 #include <libANGLE/renderer/vulkan/CLDeviceVk.h>
16 
17 #include "clspv/Compiler.h"
18 #include "clspv/Sampler.h"
19 #include "spirv-tools/libspirv.h"
20 
21 namespace rx
22 {
23 struct ClspvPrintfBufferStorage
24 {
25     uint32_t descriptorSet = 0;
26     uint32_t binding       = 0;
27     uint32_t pcOffset      = 0;
28     uint32_t size          = 0;
29 };
30 
31 struct ClspvPrintfInfo
32 {
33     uint32_t id = 0;
34     std::string formatSpecifier;
35     std::vector<uint32_t> argSizes;
36 };
37 
38 struct ClspvLiteralSampler
39 {
40     uint32_t descriptorSet;
41     uint32_t binding;
42     cl_bool normalizedCoords;
43     cl::AddressingMode addressingMode;
44     cl::FilterMode filterMode;
45 };
46 
47 namespace clspv_cl
48 {
49 
50 cl::AddressingMode GetAddressingMode(uint32_t mask);
51 
52 cl::FilterMode GetFilterMode(uint32_t mask);
53 
IsNormalizedCoords(uint32_t mask)54 inline bool IsNormalizedCoords(uint32_t mask)
55 {
56     return (mask & clspv::kSamplerNormalizedCoordsMask) == clspv::CLK_NORMALIZED_COORDS_TRUE;
57 }
58 
59 }  // namespace clspv_cl
60 
61 angle::Result ClspvProcessPrintfBuffer(unsigned char *buffer,
62                                        const size_t bufferSize,
63                                        const angle::HashMap<uint32_t, ClspvPrintfInfo> *infoMap);
64 
65 // Populate a list of options that can be supported by clspv based on the features supported by the
66 // vulkan renderer.
67 std::string ClspvGetCompilerOptions(const CLDeviceVk *device);
68 
69 ClspvError ClspvCompileSource(const size_t programCount,
70                               const size_t *programSizes,
71                               const char **programs,
72                               const char *options,
73                               char **outputBinary,
74                               size_t *outputBinarySize,
75                               char **outputLog);
76 
77 spv_target_env ClspvGetSpirvVersion(const vk::Renderer *renderer);
78 
79 bool ClspvValidate(vk::Renderer *rendererVk, const angle::spirv::Blob &blob);
80 
81 }  // namespace rx
82 
83 #endif  // LIBANGLE_RENDERER_VULKAN_CLSPV_UTILS_H_
84