Skip to content

Commit

Permalink
address more
Browse files Browse the repository at this point in the history
  • Loading branch information
poweifeng committed May 2, 2024
1 parent c8c1a65 commit 6a0a9b8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion filament/src/details/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ void FMaterial::processSpecializationConstants(FEngine& engine, Material::Builde

void FMaterial::processPushConstants(FEngine& engine, Material::Builder const& builder) {
// TODO: for testing and illustrating push constants. To be removed.
// mPushConstants[(uint8_t) ShaderStage::VERTEX] = SKINNING_VERTEX_PUSH_CONSTANTS.names;
// mPushConstants[(uint8_t) ShaderStage::VERTEX] = PUSH_CONSTANT_NAMES;
}

void FMaterial::processDepthVariants(FEngine& engine, MaterialParser const* const parser) {
Expand Down
26 changes: 12 additions & 14 deletions libs/filabridge/include/private/filament/EngineEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,22 @@ enum class ReservedSpecializationConstants : uint8_t {
CONFIG_STEREO_EYE_COUNT = 8, // don't change (hardcoded in ShaderCompilerService.cpp)
};

enum class PushConstantType : uint8_t {
BOOL = 0,
INT = 1,
FLOAT = 2,
};

struct PushConstantStruct {
static constexpr char const* VAR_NAME = "pushConstants";
using PushConstantType = backend::ConstantType;

utils::FixedCapacityVector<char const*> names;
utils::FixedCapacityVector<PushConstantType> types;
// Note that the following enum/arrays should be ordered so that the ids correspond to indices in
// the two vectors.
enum class PushConstantIds {
MORPHING_BUFFER_OFFSET = 0,
};
const utils::FixedCapacityVector<char const*> PUSH_CONSTANT_NAMES = {
"morphingBufferOffset",
};
const utils::FixedCapacityVector<PushConstantType> PUSH_CONSTANT_TYPES = {
PushConstantType::INT,
};

// TODO: for testing and illustrating push constants. To be removed.
// const PushConstantStruct SKINNING_VERTEX_PUSH_CONSTANTS = {
// .names = {"test"},
// .types = {PushConstantType::FLOAT},
// };
constexpr char const* PUSH_CONSTANT_STRUCT_VAR_NAME = "pushConstants";

// This value is limited by UBO size, ES3.0 only guarantees 16 KiB.
// It's also limited by the Froxelizer's record buffer data type (uint8_t).
Expand Down
28 changes: 10 additions & 18 deletions libs/filamat/src/shaders/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ using namespace utils;

namespace {

io::sstream& generatePushConstant(PushConstantStruct const& pushConstant,
size_t const layoutLocation, bool const outputSpirv, io::sstream& out) {
io::sstream& generatePushConstantImpl(size_t const layoutLocation, bool const outputSpirv,
io::sstream& out) {
static constexpr char const* STRUCT_NAME = "Constants";
if (pushConstant.names.empty()) {
return out;
}
auto const getType = [](PushConstantType const& type) {
switch (type) {
case PushConstantType::BOOL:
Expand All @@ -62,18 +59,18 @@ io::sstream& generatePushConstant(PushConstantStruct const& pushConstant,
out << "struct " << STRUCT_NAME << " {\n";
}

for (size_t i = 0; i < pushConstant.names.size(); ++i) {
char const* type = getType(pushConstant.types[i]);
out << type << " " << pushConstant.names[i] << ";\n";
for (size_t i = 0; i < PUSH_CONSTANT_NAMES.size(); ++i) {
char const* type = getType(PUSH_CONSTANT_TYPES[i]);
out << type << " " << PUSH_CONSTANT_NAMES[i] << ";\n";
i++;
}

if (outputSpirv) {
out << "} " << PushConstantStruct::VAR_NAME << ";\n";
out << "} " << PUSH_CONSTANT_STRUCT_VAR_NAME << ";\n";
} else {
out << "};\n";
out << "LAYOUT_LOCATION(" << static_cast<int>(layoutLocation) << ") uniform " << STRUCT_NAME
<< " " << PushConstantStruct::VAR_NAME << ";\n";
<< " " << PUSH_CONSTANT_STRUCT_VAR_NAME << ";\n";
}
return out;
}
Expand Down Expand Up @@ -526,7 +523,7 @@ io::sstream& CodeGenerator::generateShaderInputs(io::sstream& out, ShaderStage t
});

out << "\n";
generateVertexPushConstants(out, attributes.size());
generatePushConstants(out, attributes.size());
}

out << "\n";
Expand Down Expand Up @@ -954,17 +951,12 @@ utils::io::sstream& CodeGenerator::generateSpecializationConstant(utils::io::sst
return out;
}

utils::io::sstream& CodeGenerator::generateVertexPushConstants(utils::io::sstream& out,
utils::io::sstream& CodeGenerator::generatePushConstants(utils::io::sstream& out,
size_t const layoutLocation) const {
// TODO: for testing and illustrating push constants. To be removed.
// bool const outputSpirv = mTargetLanguage == TargetLanguage::SPIRV
// && mTargetApi != TargetApi::OPENGL;
// generatePushConstant(SKINNING_VERTEX_PUSH_CONSTANTS, layoutLocation, outputSpirv, out);
return out;
}

utils::io::sstream& CodeGenerator::generateFragmentPushConstants(utils::io::sstream& out,
size_t const layoutLocation) const {
// generatePushConstantImpl(layoutLocation, outputSpirv, out);
return out;
}

Expand Down
4 changes: 1 addition & 3 deletions libs/filamat/src/shaders/CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ class UTILS_PRIVATE CodeGenerator {
utils::io::sstream& generateSpecializationConstant(utils::io::sstream& out,
const char* name, uint32_t id, std::variant<int, float, bool> value) const;

utils::io::sstream& generateVertexPushConstants(utils::io::sstream& out,
size_t const layoutLocation) const;
utils::io::sstream& generateFragmentPushConstants(utils::io::sstream& out,
utils::io::sstream& generatePushConstants(utils::io::sstream& out,
size_t const layoutLocation) const;

static utils::io::sstream& generatePostProcessGetters(utils::io::sstream& out, ShaderStage type);
Expand Down

0 comments on commit 6a0a9b8

Please sign in to comment.