Debian Codegraph @

libs/matdbg/src/ShaderInfo.cpp

raw
1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <matdbg/ShaderInfo.h>
18
19 #include <filaflat/BlobDictionary.h>
20 #include <filaflat/ChunkContainer.h>
21 #include <filaflat/DictionaryReader.h>
22 #include <filaflat/MaterialChunk.h>
23 #include <filaflat/ShaderBuilder.h>
24 #include <filaflat/Unflattener.h>
25
26 #include <filament/MaterialChunkType.h>
27 #include <filament/MaterialEnums.h>
28
29 #include <backend/DriverEnums.h>
30
31 namespace filament {
32 namespace matdbg {
33
34 using namespace filament;
35 using namespace backend;
36 using namespace filaflat;
37 using namespace filamat;
38 using namespace std;
39 using namespace utils;
40
41 size_t getShaderCount(ChunkContainer container, filamat::ChunkType type) {
42 if (!container.hasChunk(type)) {
43 return 0;
44 }
45
46 Unflattener unflattener(container.getChunkStart(type), container.getChunkEnd(type));
47
48 uint64_t shaderCount = 0;
49 if (!unflattener.read(&shaderCount) || shaderCount == 0) {
50 return 0;
51 }
52 return shaderCount;
53 }
54
55 bool getMetalShaderInfo(ChunkContainer container, ShaderInfo* info) {
56 if (!container.hasChunk(filamat::ChunkType::MaterialMetal)) {
57 return true;
58 }
59
60 Unflattener unflattener(
61 container.getChunkStart(filamat::ChunkType::MaterialMetal),
62 container.getChunkEnd(filamat::ChunkType::MaterialMetal));
63
64 uint64_t shaderCount = 0;
65 if (!unflattener.read(&shaderCount) || shaderCount == 0) {
66 return false;
67 }
68
69 for (uint64_t i = 0; i < shaderCount; i++) {
70 uint8_t shaderModelValue;
71 uint8_t variantValue;
72 uint8_t pipelineStageValue;
73 uint32_t offsetValue;
74
75 if (!unflattener.read(&shaderModelValue)) {
76 return false;
77 }
78
79 if (!unflattener.read(&variantValue)) {
80 return false;
81 }
82
83 if (!unflattener.read(&pipelineStageValue)) {
84 return false;
85 }
86
87 if (!unflattener.read(&offsetValue)) {
88 return false;
89 }
90
91 *info++ = {
92 .shaderModel = ShaderModel(shaderModelValue),
93 .variant = variantValue,
94 .pipelineStage = ShaderType(pipelineStageValue),
95 .offset = offsetValue
96 };
97 }
98
99 return true;
100 }
101
102 bool getGlShaderInfo(ChunkContainer container, ShaderInfo* info) {
103 if (!container.hasChunk(filamat::ChunkType::MaterialGlsl)) {
104 return true;
105 }
106
107 Unflattener unflattener(
108 container.getChunkStart(filamat::ChunkType::MaterialGlsl),
109 container.getChunkEnd(filamat::ChunkType::MaterialGlsl));
110
111 uint64_t shaderCount;
112 if (!unflattener.read(&shaderCount) || shaderCount == 0) {
113 return false;
114 }
115
116 for (uint64_t i = 0; i < shaderCount; i++) {
117 uint8_t shaderModelValue;
118 uint8_t variantValue;
119 uint8_t pipelineStageValue;
120 uint32_t offsetValue;
121
122 if (!unflattener.read(&shaderModelValue)) {
123 return false;
124 }
125
126 if (!unflattener.read(&variantValue)) {
127 return false;
128 }
129
130 if (!unflattener.read(&pipelineStageValue)) {
131 return false;
132 }
133
134 if (!unflattener.read(&offsetValue)) {
135 return false;
136 }
137
138 *info++ = {
139 .shaderModel = ShaderModel(shaderModelValue),
140 .variant = variantValue,
141 .pipelineStage = ShaderType(pipelineStageValue),
142 .offset = offsetValue
143 };
144 }
145 return true;
146 }
147
148 bool getVkShaderInfo(ChunkContainer container, ShaderInfo* info) {
149 if (!container.hasChunk(filamat::ChunkType::MaterialSpirv)) {
150 return true;
151 }
152
153 Unflattener unflattener(
154 container.getChunkStart(filamat::ChunkType::MaterialSpirv),
155 container.getChunkEnd(filamat::ChunkType::MaterialSpirv));
156
157 uint64_t shaderCount;
158 if (!unflattener.read(&shaderCount) || shaderCount == 0) {
159 return false;
160 }
161
162 for (uint64_t i = 0; i < shaderCount; i++) {
163 uint8_t shaderModelValue;
164 uint8_t variantValue;
165 uint8_t pipelineStageValue;
166 uint32_t dictionaryIndex;
167
168 if (!unflattener.read(&shaderModelValue)) {
169 return false;
170 }
171
172 if (!unflattener.read(&variantValue)) {
173 return false;
174 }
175
176 if (!unflattener.read(&pipelineStageValue)) {
177 return false;
178 }
179
180 if (!unflattener.read(&dictionaryIndex)) {
181 return false;
182 }
183
184 *info++ = {
185 .shaderModel = ShaderModel(shaderModelValue),
186 .variant = variantValue,
187 .pipelineStage = ShaderType(pipelineStageValue),
188 .offset = dictionaryIndex
189 };
190 }
191 return true;
192 }
193
194 } // namespace matdbg
195 } // namespace filament