| 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 <filaflat/BlobDictionary.h> |
| 18 |
#include <filaflat/ChunkContainer.h> |
| 19 |
#include <filaflat/DictionaryReader.h> |
| 20 |
#include <filaflat/MaterialChunk.h> |
| 21 |
#include <filaflat/ShaderBuilder.h> |
| 22 |
#include <filaflat/Unflattener.h> |
| 23 |
|
| 24 |
#include <filament/MaterialChunkType.h> |
| 25 |
#include <filament/MaterialEnums.h> |
| 26 |
|
| 27 |
#include <backend/DriverEnums.h> |
| 28 |
|
| 29 |
#include <matdbg/JsonWriter.h> |
| 30 |
#include <matdbg/ShaderInfo.h> |
| 31 |
|
| 32 |
#include <string> |
| 33 |
|
| 34 |
namespace filament { |
| 35 |
namespace matdbg { |
| 36 |
|
| 37 |
template<typename T> |
| 38 |
static bool read(const filaflat::ChunkContainer& container, filamat::ChunkType type, |
| 39 |
T* value) noexcept { |
| 40 |
if (!container.hasChunk(type)) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
filaflat::Unflattener unflattener(container.getChunkStart(type), container.getChunkEnd(type)); |
| 45 |
return unflattener.read(value); |
| 46 |
} |
| 47 |
|
| 48 |
inline |
| 49 |
const char* toString(Shading shadingModel) noexcept { |
| 50 |
switch (shadingModel) { |
| 51 |
case Shading::UNLIT: return "unlit"; |
| 52 |
case Shading::LIT: return "lit"; |
| 53 |
case Shading::SUBSURFACE: return "subsurface"; |
| 54 |
case Shading::CLOTH: return "cloth"; |
| 55 |
case Shading::SPECULAR_GLOSSINESS: return "specularGlossiness"; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
inline |
| 60 |
const char* toString(BlendingMode blendingMode) noexcept { |
| 61 |
switch (blendingMode) { |
| 62 |
case BlendingMode::OPAQUE: return "opaque"; |
| 63 |
case BlendingMode::TRANSPARENT: return "transparent"; |
| 64 |
case BlendingMode::ADD: return "add"; |
| 65 |
case BlendingMode::MASKED: return "masked"; |
| 66 |
case BlendingMode::FADE: return "fade"; |
| 67 |
case BlendingMode::MULTIPLY: return "multiply"; |
| 68 |
case BlendingMode::SCREEN: return "screen"; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
inline |
| 73 |
const char* toString(Interpolation interpolation) noexcept { |
| 74 |
switch (interpolation) { |
| 75 |
case Interpolation::SMOOTH: return "smooth"; |
| 76 |
case Interpolation::FLAT: return "flat"; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
inline |
| 81 |
const char* toString(VertexDomain domain) noexcept { |
| 82 |
switch (domain) { |
| 83 |
case VertexDomain::OBJECT: return "object"; |
| 84 |
case VertexDomain::WORLD: return "world"; |
| 85 |
case VertexDomain::VIEW: return "view"; |
| 86 |
case VertexDomain::DEVICE: return "device"; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
inline |
| 92 |
const char* toString(MaterialDomain domain) noexcept { |
| 93 |
switch (domain) { |
| 94 |
case MaterialDomain::SURFACE: return "surface"; |
| 95 |
case MaterialDomain::POST_PROCESS: return "post process"; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
inline |
| 100 |
const char* toString(backend::CullingMode cullingMode) noexcept { |
| 101 |
switch (cullingMode) { |
| 102 |
case backend::CullingMode::NONE: return "none"; |
| 103 |
case backend::CullingMode::FRONT: return "front"; |
| 104 |
case backend::CullingMode::BACK: return "back"; |
| 105 |
case backend::CullingMode::FRONT_AND_BACK: return "front & back"; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
inline |
| 110 |
const char* toString(TransparencyMode transparencyMode) noexcept { |
| 111 |
switch (transparencyMode) { |
| 112 |
case TransparencyMode::DEFAULT: return "default"; |
| 113 |
case TransparencyMode::TWO_PASSES_ONE_SIDE: return "two passes, one side"; |
| 114 |
case TransparencyMode::TWO_PASSES_TWO_SIDES: return "two passes, two sides"; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
inline |
| 119 |
const char* toString(VertexAttribute attribute) noexcept { |
| 120 |
switch (attribute) { |
| 121 |
case VertexAttribute::POSITION: return "position"; |
| 122 |
case VertexAttribute::TANGENTS: return "tangents"; |
| 123 |
case VertexAttribute::COLOR: return "color"; |
| 124 |
case VertexAttribute::UV0: return "uv0"; |
| 125 |
case VertexAttribute::UV1: return "uv1"; |
| 126 |
case VertexAttribute::BONE_INDICES: return "bone indices"; |
| 127 |
case VertexAttribute::BONE_WEIGHTS: return "bone weights"; |
| 128 |
case VertexAttribute::CUSTOM0: return "custom0"; |
| 129 |
case VertexAttribute::CUSTOM1: return "custom1"; |
| 130 |
case VertexAttribute::CUSTOM2: return "custom2"; |
| 131 |
case VertexAttribute::CUSTOM3: return "custom3"; |
| 132 |
case VertexAttribute::CUSTOM4: return "custom4"; |
| 133 |
case VertexAttribute::CUSTOM5: return "custom5"; |
| 134 |
case VertexAttribute::CUSTOM6: return "custom6"; |
| 135 |
case VertexAttribute::CUSTOM7: return "custom7"; |
| 136 |
} |
| 137 |
return "--"; |
| 138 |
} |
| 139 |
|
| 140 |
inline |
| 141 |
const char* toString(bool value) { |
| 142 |
return value ? "true" : "false"; |
| 143 |
} |
| 144 |
|
| 145 |
inline |
| 146 |
const char* toString(backend::ShaderType stage) noexcept { |
| 147 |
switch (stage) { |
| 148 |
case backend::ShaderType::VERTEX: return "vs"; |
| 149 |
case backend::ShaderType::FRAGMENT: return "fs"; |
| 150 |
default: break; |
| 151 |
} |
| 152 |
return "--"; |
| 153 |
} |
| 154 |
|
| 155 |
inline |
| 156 |
const char* toString(backend::ShaderModel model) noexcept { |
| 157 |
switch (model) { |
| 158 |
case backend::ShaderModel::UNKNOWN: return "--"; |
| 159 |
case backend::ShaderModel::GL_ES_30: return "gles30"; |
| 160 |
case backend::ShaderModel::GL_CORE_41: return "gl41"; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
inline |
| 165 |
const char* toString(backend::UniformType type) noexcept { |
| 166 |
switch (type) { |
| 167 |
case backend::UniformType::BOOL: return "bool"; |
| 168 |
case backend::UniformType::BOOL2: return "bool2"; |
| 169 |
case backend::UniformType::BOOL3: return "bool3"; |
| 170 |
case backend::UniformType::BOOL4: return "bool4"; |
| 171 |
case backend::UniformType::FLOAT: return "float"; |
| 172 |
case backend::UniformType::FLOAT2: return "float2"; |
| 173 |
case backend::UniformType::FLOAT3: return "float3"; |
| 174 |
case backend::UniformType::FLOAT4: return "float4"; |
| 175 |
case backend::UniformType::INT: return "int"; |
| 176 |
case backend::UniformType::INT2: return "int2"; |
| 177 |
case backend::UniformType::INT3: return "int3"; |
| 178 |
case backend::UniformType::INT4: return "int4"; |
| 179 |
case backend::UniformType::UINT: return "uint"; |
| 180 |
case backend::UniformType::UINT2: return "uint2"; |
| 181 |
case backend::UniformType::UINT3: return "uint3"; |
| 182 |
case backend::UniformType::UINT4: return "uint4"; |
| 183 |
case backend::UniformType::MAT3: return "float3x3"; |
| 184 |
case backend::UniformType::MAT4: return "float4x4"; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
inline |
| 189 |
const char* toString(backend::SamplerType type) noexcept { |
| 190 |
switch (type) { |
| 191 |
case backend::SamplerType::SAMPLER_2D: return "sampler2D"; |
| 192 |
case backend::SamplerType::SAMPLER_3D: return "sampler3D"; |
| 193 |
case backend::SamplerType::SAMPLER_2D_ARRAY: return "sampler2DArray"; |
| 194 |
case backend::SamplerType::SAMPLER_CUBEMAP: return "samplerCubemap"; |
| 195 |
case backend::SamplerType::SAMPLER_EXTERNAL: return "samplerExternal"; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
inline |
| 200 |
const char* toString(backend::SubpassType type) noexcept { |
| 201 |
switch (type) { |
| 202 |
case backend::SubpassType::SUBPASS_INPUT: return "subpassInput"; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
inline |
| 207 |
const char* toString(backend::Precision precision) noexcept { |
| 208 |
switch (precision) { |
| 209 |
case backend::Precision::LOW: return "lowp"; |
| 210 |
case backend::Precision::MEDIUM: return "mediump"; |
| 211 |
case backend::Precision::HIGH: return "highp"; |
| 212 |
case backend::Precision::DEFAULT: return "default"; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
inline |
| 217 |
const char* toString(backend::SamplerFormat format) noexcept { |
| 218 |
switch (format) { |
| 219 |
case backend::SamplerFormat::INT: return "int"; |
| 220 |
case backend::SamplerFormat::UINT: return "uint"; |
| 221 |
case backend::SamplerFormat::FLOAT: return "float"; |
| 222 |
case backend::SamplerFormat::SHADOW: return "shadow"; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
// Returns a human-readable variant description. |
| 227 |
// For example: DYN|DIR |
| 228 |
std::string formatVariantString(uint8_t variant, MaterialDomain domain) noexcept; |
| 229 |
|
| 230 |
} // namespace matdbg |
| 231 |
} // namespace filament |