Make ShaderStage an enum class

This commit is contained in:
Mathias Agopian
2022-09-12 15:54:07 -07:00
committed by Mathias Agopian
parent ba8abb9031
commit 441708ea12
11 changed files with 115 additions and 87 deletions
@@ -893,7 +893,7 @@ struct RasterState {
* \privatesection
*/
enum ShaderType : uint8_t {
enum class ShaderType : uint8_t {
VERTEX = 0,
FRAGMENT = 1
};
@@ -908,9 +908,9 @@ enum class ShaderStageFlags : uint8_t {
static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderType type) noexcept {
switch (type) {
case VERTEX:
case ShaderType::VERTEX:
return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));
case FRAGMENT:
case ShaderType::FRAGMENT:
return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::FRAGMENT));
}
}
+11 -2
View File
@@ -415,9 +415,18 @@ MetalProgram::MetalProgram(id<MTLDevice> device, const Program& program) noexcep
// 3 depth
auto& samplerGroupInfo = program.getSamplerGroupInfo();
for (size_t shaderType = 0; shaderType != PIPELINE_STAGE_COUNT; ++shaderType) {
ShaderType stage = (ShaderType)shaderType;
size_t bindingIdx = 0;
auto& samplerBlockInfo = (shaderType == ShaderType::VERTEX) ? vertexSamplerBlockInfo
: fragmentSamplerBlockInfo;
auto getShaderStage = [this](ShaderType type) -> auto& {
switch (type) {
case ShaderType::VERTEX: return vertexSamplerBlockInfo;
case ShaderType::FRAGMENT: return fragmentSamplerBlockInfo;
}
};
auto& samplerBlockInfo = getShaderStage(stage);
for (size_t samplerGroupIdx = 0; samplerGroupIdx != SAMPLER_GROUP_COUNT; ++samplerGroupIdx) {
auto& groupData = samplerGroupInfo[samplerGroupIdx];
auto stageFlags = groupData.stageFlags;
+1 -1
View File
@@ -309,7 +309,7 @@ bool MaterialParser::getReflectionMode(ReflectionMode* value) const noexcept {
bool MaterialParser::getShader(ShaderContent& shader,
ShaderModel shaderModel, Variant variant, ShaderType stage) noexcept {
return mImpl.mMaterialChunk.getShader(shader,
mImpl.mBlobDictionary, (uint8_t)shaderModel, variant, stage);
mImpl.mBlobDictionary, uint8_t(shaderModel), variant, uint8_t(stage));
}
// ------------------------------------------------------------------------------------------------
+3 -3
View File
@@ -232,10 +232,10 @@ bool GLSLPostProcessor::process(const std::string& inputShader, Config const& co
};
switch (config.shaderType) {
case VERTEX:
case ShaderType::VERTEX:
internalConfig.shLang = EShLangVertex;
break;
case FRAGMENT:
case ShaderType::FRAGMENT:
internalConfig.shLang = EShLangFragment;
break;
}
@@ -269,7 +269,7 @@ bool GLSLPostProcessor::process(const std::string& inputShader, Config const& co
}
// add texture lod bias
if (config.shaderType == backend::FRAGMENT &&
if (config.shaderType == backend::ShaderType::FRAGMENT &&
config.domain == MaterialDomain::SURFACE) {
GLSLTools::textureLodBias(tShader);
}
+27 -21
View File
@@ -789,31 +789,37 @@ bool MaterialBuilder::generateShaders(JobSystem& jobSystem, const std::vector<Va
// NOTE: do not execute expensive work from here on!
std::unique_lock<Mutex> lock(entriesLock);
if (targetApi == TargetApi::OPENGL) {
glslEntry.stage = v.stage;
glslEntry.shader = shader;
// below we rely on casting ShaderType to uint8_t
static_assert(sizeof(filament::backend::ShaderType) == 1);
glslEntries.push_back(glslEntry);
}
switch (targetApi) {
case TargetApi::ALL:
// should never happen
break;
case TargetApi::OPENGL:
glslEntry.stage = uint8_t(v.stage);
glslEntry.shader = shader;
glslEntries.push_back(glslEntry);
break;
case TargetApi::VULKAN:
#ifndef FILAMAT_LITE
if (targetApi == TargetApi::VULKAN) {
assert(!spirv.empty());
spirvEntry.stage = v.stage;
spirvEntry.spirv = std::move(spirv);
spirvEntries.push_back(spirvEntry);
}
if (targetApi == TargetApi::METAL) {
assert(!spirv.empty());
assert(msl.length() > 0);
metalEntry.stage = v.stage;
metalEntry.shader = msl;
metalEntries.push_back(metalEntry);
}
assert(!spirv.empty());
spirvEntry.stage = uint8_t(v.stage);
spirvEntry.spirv = std::move(spirv);
spirvEntries.push_back(spirvEntry);
#endif
break;
case TargetApi::METAL:
#ifndef FILAMAT_LITE
assert(!spirv.empty());
assert(msl.length() > 0);
metalEntry.stage = uint8_t(v.stage);
metalEntry.shader = msl;
metalEntries.push_back(metalEntry);
#endif
break;
}
});
// NOTE: We run the first job separately to work the lack of thread safety
+1
View File
@@ -32,6 +32,7 @@ struct TextEntry {
std::string shader;
};
struct SpirvEntry {
uint8_t shaderModel;
filament::Variant::type_t variantKey;
+9 -3
View File
@@ -181,8 +181,14 @@ bool GLSLTools::findProperties(
ShaderModel model) const noexcept {
const char* shaderCString = shaderCode.c_str();
TShader tShader(type == FRAGMENT ?
EShLanguage::EShLangFragment : EShLanguage::EShLangVertex);
auto getShaderStage = [](ShaderType type) {
switch (type) {
case ShaderType::VERTEX: return EShLanguage::EShLangVertex;
case ShaderType::FRAGMENT: return EShLanguage::EShLangFragment;
}
};
TShader tShader(getShaderStage(type));
tShader.setStrings(&shaderCString, 1);
GLSLangCleaner cleaner;
@@ -199,7 +205,7 @@ bool GLSLTools::findProperties(
TIntermNode* rootNode = tShader.getIntermediate()->getTreeRoot();
std::string mainFunction(type == FRAGMENT ?
std::string mainFunction(type == ShaderType::FRAGMENT ?
"material" : "materialVertex");
TIntermAggregate* functionMaterialDef = ASTUtils::getFunctionByNameOnly(mainFunction, *rootNode);
+30 -30
View File
@@ -119,7 +119,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerNothingDetected) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
EXPECT_TRUE(PropertyListsMatch(expected, properties));
}
@@ -140,7 +140,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerNothingDetectedVertex) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::VERTEX, shaderCode, properties);
glslTools.findProperties(ShaderType::VERTEX, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
EXPECT_TRUE(PropertyListsMatch(expected, properties));
}
@@ -162,7 +162,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerNotFollowingINParameters) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
EXPECT_TRUE(PropertyListsMatch(expected, properties));
}
@@ -180,7 +180,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerDirectAssign) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -206,7 +206,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerDirectAssignVertex) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::VERTEX, shaderCode, properties);
glslTools.findProperties(ShaderType::VERTEX, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::CLIP_SPACE_TRANSFORM)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -225,7 +225,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerDirectAssignWithSwizzling) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -249,7 +249,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSymbolAsOutParameterWithAliasing) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -273,7 +273,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSymbolAsOutParameterWithAliasingAndSw
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -302,7 +302,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSymbolInOutInChainWithDirectIndexInto
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -331,7 +331,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSymbolInOutInChain) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -351,7 +351,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerBaseColor) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -370,7 +370,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerRoughness) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::ROUGHNESS)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -389,7 +389,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerMetallic) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::METALLIC)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -408,7 +408,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerReflectance) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::REFLECTANCE)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -427,7 +427,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerAmbientOcclusion) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::AMBIENT_OCCLUSION)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -446,7 +446,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerClearCoat) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::CLEAR_COAT)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -469,7 +469,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerTransmission) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::ABSORPTION)] = true;
expected[size_t(filamat::MaterialBuilder::Property::TRANSMISSION)] = true;
@@ -490,7 +490,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerClearCoatRoughness) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::CLEAR_COAT_ROUGHNESS)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -510,7 +510,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerClearCoatNormal) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::CLEAR_COAT)] = true;
expected[size_t(filamat::MaterialBuilder::Property::CLEAR_COAT_NORMAL)] = true;
@@ -531,7 +531,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerThickness) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::THICKNESS)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -551,7 +551,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSubsurfacePower) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::SUBSURFACE_POWER)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -571,7 +571,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSubsurfaceColor) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::SUBSURFACE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -590,7 +590,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerAnisotropicDirection) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::ANISOTROPY_DIRECTION)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -609,7 +609,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerAnisotropic) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::ANISOTROPY)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -629,7 +629,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSheenColor) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::SHEEN_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -648,7 +648,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerSheenRoughness) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::SHEEN_ROUGHNESS)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -667,7 +667,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerNormal) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::NORMAL)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -686,7 +686,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerBentNormal) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::BENT_NORMAL)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -705,7 +705,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerOutputFactor) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::POST_LIGHTING_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -724,7 +724,7 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerWithinInclude) {
GLSLTools glslTools;
MaterialBuilder::PropertyList properties{ false };
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected{ false };
expected[size_t(filamat::MaterialBuilder::Property::NORMAL)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
+15 -16
View File
@@ -22,6 +22,7 @@
#include <filamat/Enums.h>
using namespace filamat;
using namespace filament::backend;
static ::testing::AssertionResult PropertyListsMatch(const MaterialBuilder::PropertyList& expected,
const MaterialBuilder::PropertyList& actual) {
@@ -38,13 +39,11 @@ static ::testing::AssertionResult PropertyListsMatch(const MaterialBuilder::Prop
class FilamatLite : public ::testing::Test {
protected:
FilamatLite() {
}
FilamatLite() = default;
virtual ~FilamatLite() {
}
~FilamatLite() override = default;
virtual void SetUp() {
void SetUp() override {
MaterialBuilder::init();
}
};
@@ -58,7 +57,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerNothingDetected) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
EXPECT_TRUE(PropertyListsMatch(expected, properties));
}
@@ -71,7 +70,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerNothingDetectedinVertex) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::VERTEX, shaderCode, properties);
glslTools.findProperties(ShaderType::VERTEX, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
EXPECT_TRUE(PropertyListsMatch(expected, properties));
}
@@ -86,7 +85,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerDirectAssign) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::BASE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -101,7 +100,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerDirectAssignVertex) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::VERTEX, shaderCode, properties);
glslTools.findProperties(ShaderType::VERTEX, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::CLIP_SPACE_TRANSFORM)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -119,7 +118,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerAssignMultiple) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::CLEAR_COAT)] = true;
expected[size_t(MaterialBuilder::Property::BASE_COLOR)] = true;
@@ -137,7 +136,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerDirectAssignWithSwizzling) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::SUBSURFACE_COLOR)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -153,7 +152,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerNoSpace) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::AMBIENT_OCCLUSION)] = true;
EXPECT_TRUE(PropertyListsMatch(expected, properties));
@@ -172,7 +171,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerWhitespace) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::SUBSURFACE_COLOR)] = true;
expected[size_t(MaterialBuilder::Property::AMBIENT_OCCLUSION)] = true;
@@ -187,7 +186,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerEndOfShader) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
EXPECT_TRUE(PropertyListsMatch(expected, properties));
}
@@ -206,7 +205,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerSlashComments) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::METALLIC)] = true;
expected[size_t(MaterialBuilder::Property::CLEAR_COAT)] = true;
@@ -229,7 +228,7 @@ TEST_F(FilamatLite, StaticCodeAnalyzerMultilineComments) {
GLSLToolsLite glslTools;
MaterialBuilder::PropertyList properties {false};
glslTools.findProperties(filament::backend::FRAGMENT, shaderCode, properties);
glslTools.findProperties(ShaderType::FRAGMENT, shaderCode, properties);
MaterialBuilder::PropertyList expected {false};
expected[size_t(MaterialBuilder::Property::METALLIC)] = true;
expected[size_t(MaterialBuilder::Property::CLEAR_COAT)] = true;
+4 -4
View File
@@ -33,7 +33,6 @@ using namespace filament;
using namespace backend;
using namespace filaflat;
using namespace filamat;
using namespace std;
using namespace utils;
namespace filament {
@@ -83,7 +82,8 @@ bool ShaderExtractor::getShader(ShaderModel shaderModel,
return false;
}
return mMaterialChunk.getShader(shader, blobDictionary, (uint8_t)shaderModel, variant, stage);
return mMaterialChunk.getShader(shader, blobDictionary,
uint8_t(shaderModel), variant, uint8_t(stage));
}
CString ShaderExtractor::spirvToGLSL(const uint32_t* data, size_t wordCount) {
@@ -94,8 +94,8 @@ CString ShaderExtractor::spirvToGLSL(const uint32_t* data, size_t wordCount) {
emitOptions.version = 410;
emitOptions.vulkan_semantics = true;
vector<uint32_t> spirv(data, data + wordCount);
CompilerGLSL glslCompiler(move(spirv));
std::vector<uint32_t> spirv(data, data + wordCount);
CompilerGLSL glslCompiler(std::move(spirv));
glslCompiler.set_common_options(emitOptions);
return CString(glslCompiler.compile().c_str());
+11 -4
View File
@@ -174,7 +174,14 @@ bool ShaderReplacer::replaceSpirv(ShaderModel shaderModel, Variant variant,
ShaderType stage, const char* source, size_t sourceLength) {
assert_invariant(mMaterialTag == ChunkType::MaterialSpirv);
const EShLanguage shLang = stage == VERTEX ? EShLangVertex : EShLangFragment;
auto getShaderStage = [](ShaderType type) {
switch (type) {
case ShaderType::VERTEX: return EShLanguage::EShLangVertex;
case ShaderType::FRAGMENT: return EShLanguage::EShLangFragment;
}
};
const EShLanguage shLang = getShaderStage(stage);
std::string nullTerminated(source, sourceLength);
source = nullTerminated.c_str();
@@ -305,10 +312,10 @@ void ShaderIndex::writeChunks(ostream& stream) {
void ShaderIndex::replaceShader(backend::ShaderModel shaderModel, Variant variant,
backend::ShaderType stage, const char* source, size_t sourceLength) {
const uint8_t model = (uint8_t) shaderModel;
const uint8_t model = uint8_t(shaderModel);
for (auto& record : mShaderRecords) {
if (record.shaderModel == model && record.variantKey == variant.key &&
record.stage == stage) {
record.stage == uint8_t(stage)) {
record.shader = std::string(source, sourceLength);
return;
}
@@ -378,7 +385,7 @@ void BlobIndex::replaceShader(ShaderModel shaderModel, Variant variant,
const uint8_t model = (uint8_t) shaderModel;
for (auto& record : mShaderRecords) {
if (record.shaderModel == model && record.variantKey == variant.key &&
record.stage == stage) {
record.stage == uint8_t(stage)) {
// TODO: because a single blob entry might be used by more than one variant, matdbg
// users may unwittingly edit more than 1 variant when multiple variants have the exact