naming convention NUM_FOOS -> FOO_COUNT

This commit is contained in:
Mathias Agopian
2019-03-25 17:55:19 -07:00
committed by Mathias Agopian
parent 8ec3b62715
commit 4bec201717
16 changed files with 103 additions and 103 deletions
@@ -30,9 +30,9 @@ namespace driver {
class Program {
public:
static constexpr size_t NUM_SHADER_TYPES = 2;
static constexpr size_t NUM_UNIFORM_BINDINGS = 6; //BindingPoints::COUNT;
static constexpr size_t NUM_SAMPLER_BINDINGS = 6; //BindingPoints::COUNT;
static constexpr size_t SHADER_TYPE_COUNT = 2;
static constexpr size_t UNIFORM_BINDING_COUNT = 6; //BindingPoints::COUNT;
static constexpr size_t SAMPLER_BINDING_COUNT = 6; //BindingPoints::COUNT;
enum class Shader : uint8_t {
VERTEX = 0,
@@ -44,8 +44,8 @@ public:
size_t binding = 0; // binding point of the sampler in the shader
};
using SamplerGroupInfo = std::array<std::vector<Sampler>, NUM_SAMPLER_BINDINGS>;
using UniformBlockInfo = std::array<utils::CString, NUM_UNIFORM_BINDINGS>;
using SamplerGroupInfo = std::array<std::vector<Sampler>, SAMPLER_BINDING_COUNT>;
using UniformBlockInfo = std::array<utils::CString, UNIFORM_BINDING_COUNT>;
Program() noexcept;
Program(const Program& rhs) = delete;
@@ -83,7 +83,7 @@ public:
return shader(Shader::FRAGMENT, data, size);
}
std::array<std::vector<uint8_t>, NUM_SHADER_TYPES> const& getShadersSource() const noexcept {
std::array<std::vector<uint8_t>, SHADER_TYPE_COUNT> const& getShadersSource() const noexcept {
return mShadersSource;
}
@@ -105,7 +105,7 @@ private:
// FIXME: none of these fields should be public as this is a public API
UniformBlockInfo mUniformBlocks = {};
SamplerGroupInfo mSamplerGroups = {};
std::array<std::vector<uint8_t>, NUM_SHADER_TYPES> mShadersSource;
std::array<std::vector<uint8_t>, SHADER_TYPE_COUNT> mShadersSource;
utils::CString mName;
bool mHasSamplers = false;
uint8_t mVariant;
+1 -1
View File
@@ -59,7 +59,7 @@ struct MetalContext {
PipelineStateCache pipelineStateCache;
SamplerStateCache samplerStateCache;
MetalSamplerGroup* samplerBindings[NUM_SAMPLER_BINDINGS] = {};
MetalSamplerGroup* samplerBindings[SAMPLER_BINDING_COUNT] = {};
// Surface-related properties.
MetalSwapChain* currentSurface = nullptr;
+4 -4
View File
@@ -695,8 +695,8 @@ void MetalDriver::draw(driver::PipelineState ps, Handle<HwRenderPrimitive> rph)
// Enumerate all the sampler buffers for the program and check which textures and samplers need
// to be bound.
id<MTLTexture> texturesToBind[NUM_SAMPLER_BINDINGS] = {};
id<MTLSamplerState> samplersToBind[NUM_SAMPLER_BINDINGS] = {};
id<MTLTexture> texturesToBind[SAMPLER_BINDING_COUNT] = {};
id<MTLSamplerState> samplersToBind[SAMPLER_BINDING_COUNT] = {};
enumerateSamplerGroups(program, [this, &texturesToBind, &samplersToBind](
const SamplerGroup::Sampler* sampler,
@@ -712,7 +712,7 @@ void MetalDriver::draw(driver::PipelineState ps, Handle<HwRenderPrimitive> rph)
// to both the vertex and fragment stages.
NSRange range {
.length = NUM_SAMPLER_BINDINGS,
.length = SAMPLER_BINDING_COUNT,
.location = 0
};
[mContext->currentCommandEncoder setFragmentTextures:texturesToBind
@@ -742,7 +742,7 @@ void MetalDriver::draw(driver::PipelineState ps, Handle<HwRenderPrimitive> rph)
void MetalDriver::enumerateSamplerGroups(
const MetalProgram* program,
const std::function<void(const SamplerGroup::Sampler*, size_t)>& f) {
for (uint8_t samplerGroupIdx = 0; samplerGroupIdx < NUM_SAMPLER_GROUPS; samplerGroupIdx++) {
for (uint8_t samplerGroupIdx = 0; samplerGroupIdx < SAMPLER_GROUP_COUNT; samplerGroupIdx++) {
const auto& samplerGroup = program->samplerGroupInfo[samplerGroupIdx];
if (samplerGroup.empty()) {
continue;
+2 -2
View File
@@ -194,11 +194,11 @@ MetalProgram::MetalProgram(id<MTLDevice> device, const Program& program) noexcep
using MetalFunctionPtr = id<MTLFunction>*;
static_assert(Program::NUM_SHADER_TYPES == 2, "Only vertex and fragment shaders expected.");
static_assert(Program::SHADER_TYPE_COUNT == 2, "Only vertex and fragment shaders expected.");
MetalFunctionPtr shaderFunctions[2] = { &vertexFunction, &fragmentFunction };
const auto& sources = program.getShadersSource();
for (size_t i = 0; i < Program::NUM_SHADER_TYPES; i++) {
for (size_t i = 0; i < Program::SHADER_TYPE_COUNT; i++) {
const auto& source = sources[i];
// It's okay for some shaders to be empty, they shouldn't be used in any draw calls.
if (source.empty()) {
+8 -8
View File
@@ -37,10 +37,10 @@ inline bool operator==(const driver::SamplerParams& lhs, const driver::SamplerPa
namespace metal {
static constexpr uint32_t MAX_VERTEX_ATTRIBUTES = driver::MAX_VERTEX_ATTRIBUTE_COUNT;
static constexpr uint32_t NUM_SAMPLER_GROUPS = Program::NUM_UNIFORM_BINDINGS;
static constexpr uint32_t NUM_SAMPLER_BINDINGS = driver::MAX_SAMPLER_COUNT;
static constexpr uint32_t VERTEX_BUFFER_START = Program::NUM_UNIFORM_BINDINGS;
static constexpr uint32_t MAX_VERTEX_ATTRIBUTE_COUNT = driver::MAX_VERTEX_ATTRIBUTE_COUNT;
static constexpr uint32_t SAMPLER_GROUP_COUNT = Program::UNIFORM_BINDING_COUNT;
static constexpr uint32_t SAMPLER_BINDING_COUNT = driver::MAX_SAMPLER_COUNT;
static constexpr uint32_t VERTEX_BUFFER_START = Program::UNIFORM_BINDING_COUNT;
// Forward declarations necessary here, definitions at end of file.
inline bool operator==(const MTLViewport& lhs, const MTLViewport& rhs);
@@ -59,19 +59,19 @@ struct VertexDescription {
struct Layout {
uint32_t stride;
};
Attribute attributes[MAX_VERTEX_ATTRIBUTES] = {};
Layout layouts[MAX_VERTEX_ATTRIBUTES] = {};
Attribute attributes[MAX_VERTEX_ATTRIBUTE_COUNT] = {};
Layout layouts[MAX_VERTEX_ATTRIBUTE_COUNT] = {};
bool operator==(const VertexDescription& rhs) const noexcept {
bool result = true;
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTES; i++) {
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTE_COUNT; i++) {
result &= (
this->attributes[i].format == rhs.attributes[i].format &&
this->attributes[i].buffer == rhs.attributes[i].buffer &&
this->attributes[i].offset == rhs.attributes[i].offset
);
}
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTES; i++) {
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTE_COUNT; i++) {
result &= this->layouts[i].stride == rhs.layouts[i].stride;
}
return result;
+2 -2
View File
@@ -39,7 +39,7 @@ id<MTLRenderPipelineState> PipelineStateCreator::operator()(id<MTLDevice> device
const auto& vertexDescription = state.vertexDescription;
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTES; i++) {
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTE_COUNT; i++) {
if (vertexDescription.attributes[i].format > MTLVertexFormatInvalid) {
const auto& attribute = vertexDescription.attributes[i];
vertex.attributes[i].format = attribute.format;
@@ -48,7 +48,7 @@ id<MTLRenderPipelineState> PipelineStateCreator::operator()(id<MTLDevice> device
}
}
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTES; i++) {
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTE_COUNT; i++) {
if (vertexDescription.layouts[i].stride > 0) {
const auto& layout = vertexDescription.layouts[i];
vertex.layouts[VERTEX_BUFFER_START + i].stride = layout.stride;
+19 -19
View File
@@ -385,7 +385,7 @@ void OpenGLDriver::unbindTexture(GLenum target, GLuint texture_id) noexcept {
// no need unbind the texture from FBOs because we're not tracking that state (and there is
// no need to).
const size_t index = getIndexForTextureTarget(target);
for (GLuint unit = 0; unit < MAX_TEXTURE_UNITS; unit++) {
for (GLuint unit = 0; unit < MAX_TEXTURE_UNIT_COUNT; unit++) {
if (state.textures.units[unit].targets[index].texture_id == texture_id) {
bindTexture(unit, target, (GLuint)0, index);
}
@@ -395,7 +395,7 @@ void OpenGLDriver::unbindTexture(GLenum target, GLuint texture_id) noexcept {
void OpenGLDriver::unbindSampler(GLuint sampler) noexcept {
// unbind this sampler from all the units it might be bound to
#pragma nounroll // clang generates >800B of code!!!
for (GLuint unit = 0; unit < MAX_TEXTURE_UNITS; unit++) {
for (GLuint unit = 0; unit < MAX_TEXTURE_UNIT_COUNT; unit++) {
if (state.textures.units[unit].sampler == sampler) {
bindSampler(unit, 0);
}
@@ -945,8 +945,8 @@ UTILS_NOINLINE
void OpenGLDriver::textureStorage(OpenGLDriver::GLTexture* t,
uint32_t width, uint32_t height, uint32_t depth) noexcept {
bindTexture(MAX_TEXTURE_UNITS - 1, t->gl.target, t, t->gl.targetIndex);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, t->gl.target, t, t->gl.targetIndex);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
switch (t->gl.target) {
case GL_TEXTURE_2D:
@@ -1859,8 +1859,8 @@ void OpenGLDriver::generateMipmaps(Handle<HwTexture> th) {
assert(t->gl.target != GL_TEXTURE_2D_MULTISAMPLE);
// Note: glGenerateMimap can also fail if the internal format is not both
// color-renderable and filterable (i.e.: doesn't work for depth)
bindTexture(MAX_TEXTURE_UNITS - 1, t->gl.target, t, t->gl.targetIndex);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, t->gl.target, t, t->gl.targetIndex);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
t->gl.baseLevel = 0;
t->gl.maxLevel = static_cast<uint8_t>(t->levels - 1);
@@ -1909,8 +1909,8 @@ void OpenGLDriver::setTextureData(GLTexture* t,
// fallthrough...
case SamplerType::SAMPLER_2D:
// NOTE: GL_TEXTURE_2D_MULTISAMPLE is not allowed
bindTexture(MAX_TEXTURE_UNITS - 1, t->gl.target, t);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, t->gl.target, t);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
switch (t->gl.target) {
case GL_TEXTURE_2D:
glTexSubImage2D(t->gl.target, GLint(level),
@@ -1929,8 +1929,8 @@ void OpenGLDriver::setTextureData(GLTexture* t,
break;
case SamplerType::SAMPLER_CUBEMAP: {
assert(t->gl.target == GL_TEXTURE_CUBE_MAP);
bindTexture(MAX_TEXTURE_UNITS - 1, GL_TEXTURE_CUBE_MAP, t);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, GL_TEXTURE_CUBE_MAP, t);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
FaceOffsets const& offsets = *faceOffsets;
#pragma nounroll
for (size_t face = 0; face < 6; face++) {
@@ -1990,8 +1990,8 @@ void OpenGLDriver::setCompressedTextureData(GLTexture* t,
// fallthrough...
case SamplerType::SAMPLER_2D:
// NOTE: GL_TEXTURE_2D_MULTISAMPLE is not allowed
bindTexture(MAX_TEXTURE_UNITS - 1, t->gl.target, t);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, t->gl.target, t);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
switch (t->gl.target) {
case GL_TEXTURE_2D:
glCompressedTexSubImage2D(t->gl.target, GLint(level),
@@ -2011,8 +2011,8 @@ void OpenGLDriver::setCompressedTextureData(GLTexture* t,
case SamplerType::SAMPLER_CUBEMAP: {
assert(faceOffsets);
assert(t->gl.target == GL_TEXTURE_CUBE_MAP);
bindTexture(MAX_TEXTURE_UNITS - 1, GL_TEXTURE_CUBE_MAP, t);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, GL_TEXTURE_CUBE_MAP, t);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
FaceOffsets const& offsets = *faceOffsets;
#pragma nounroll
for (size_t face = 0; face < 6; face++) {
@@ -2051,8 +2051,8 @@ void OpenGLDriver::setExternalImage(Handle<HwTexture> th, void* image) {
assert(t->target == SamplerType::SAMPLER_EXTERNAL);
assert(t->gl.target == GL_TEXTURE_EXTERNAL_OES);
bindTexture(MAX_TEXTURE_UNITS - 1, GL_TEXTURE_EXTERNAL_OES, t);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, GL_TEXTURE_EXTERNAL_OES, t);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
#ifdef GL_OES_EGL_image
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, static_cast<GLeglImageOES>(image));
@@ -2617,7 +2617,7 @@ void OpenGLDriver::bindSamplers(size_t index, Handle<HwSamplerGroup> sbh) {
DEBUG_MARKER()
GLSamplerGroup* sb = handle_cast<GLSamplerGroup *>(sbh);
assert(index < Program::NUM_SAMPLER_BINDINGS);
assert(index < Program::SAMPLER_BINDING_COUNT);
mSamplerBindings[index] = sb;
CHECK_GL_ERROR(utils::slog.e)
}
@@ -2903,8 +2903,8 @@ void OpenGLDriver::blit(TargetBufferFlags buffers,
int8_t targetLevel = d->gl.colorLevel;
if (targetLevel < baseLevel || targetLevel > maxLevel) {
GLenum target = dtexture->gl.target;
bindTexture(MAX_TEXTURE_UNITS - 1, target, dtexture, dtexture->gl.targetIndex);
activeTexture(MAX_TEXTURE_UNITS - 1);
bindTexture(MAX_TEXTURE_UNIT_COUNT - 1, target, dtexture, dtexture->gl.targetIndex);
activeTexture(MAX_TEXTURE_UNIT_COUNT - 1);
if (targetLevel < baseLevel) {
dtexture->gl.baseLevel = targetLevel;
glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, targetLevel);
+6 -6
View File
@@ -377,14 +377,14 @@ private:
return pos->second;
}
const std::array<driver::HwSamplerGroup*, driver::Program::NUM_SAMPLER_BINDINGS>& getSamplerBindings() const {
const std::array<driver::HwSamplerGroup*, driver::Program::SAMPLER_BINDING_COUNT>& getSamplerBindings() const {
return mSamplerBindings;
}
GLsizei getAttachments(std::array<GLenum, 3>& attachments,
GLRenderTarget const* rt, uint8_t buffers) const noexcept;
static constexpr const size_t MAX_TEXTURE_UNITS = 16; // All mobile GPUs as of 2016
static constexpr const size_t MAX_TEXTURE_UNIT_COUNT = 16; // All mobile GPUs as of 2016
static constexpr const size_t MAX_BUFFER_BINDINGS = 32;
GLRenderPrimitive mDefaultVAO;
@@ -454,7 +454,7 @@ private:
struct {
GLuint texture_id = 0;
} targets[5];
} units[MAX_TEXTURE_UNITS];
} units[MAX_TEXTURE_UNIT_COUNT];
} textures;
struct {
@@ -513,7 +513,7 @@ private:
bool clearStencil, uint32_t stencil) noexcept;
// sampler buffer binding points (nullptr if not used)
std::array<driver::HwSamplerGroup*, driver::Program::NUM_SAMPLER_BINDINGS> mSamplerBindings; // 8 pointers
std::array<driver::HwSamplerGroup*, driver::Program::SAMPLER_BINDING_COUNT> mSamplerBindings; // 8 pointers
mutable tsl::robin_map<uint32_t, GLuint> mSamplerMap;
mutable std::vector<GLTexture*> mExternalStreams;
@@ -634,7 +634,7 @@ constexpr size_t OpenGLDriver::getIndexForBufferTarget(GLenum target) noexcept {
}
void OpenGLDriver::activeTexture(GLuint unit) noexcept {
assert(unit < MAX_TEXTURE_UNITS);
assert(unit < MAX_TEXTURE_UNIT_COUNT);
update_state(state.textures.active, unit, [&]() {
glActiveTexture(GL_TEXTURE0 + unit);
});
@@ -654,7 +654,7 @@ void UTILS_UNUSED OpenGLDriver::bindTexture(GLuint unit, GLuint target, GLuint t
}
void OpenGLDriver::bindSampler(GLuint unit, GLuint sampler) noexcept {
assert(unit < MAX_TEXTURE_UNITS);
assert(unit < MAX_TEXTURE_UNIT_COUNT);
update_state(state.textures.units[unit].sampler, sampler, [&]() {
glBindSampler(unit, sampler);
});
@@ -39,7 +39,7 @@ OpenGLProgram::OpenGLProgram(OpenGLDriver* gl, const Program& programBuilder) no
// build all shaders
#pragma nounroll
for (size_t i = 0; i < Program::NUM_SHADER_TYPES; i++) {
for (size_t i = 0; i < Program::SHADER_TYPE_COUNT; i++) {
GLenum glShaderType;
Shader type = (Shader)i;
switch (type) {
@@ -76,7 +76,7 @@ OpenGLProgram::OpenGLProgram(OpenGLDriver* gl, const Program& programBuilder) no
if (UTILS_LIKELY((mValidShaderSet & mask) == mask)) {
GLint status;
GLuint program = glCreateProgram();
for (size_t i = 0; i < Program::NUM_SHADER_TYPES; i++) {
for (size_t i = 0; i < Program::SHADER_TYPE_COUNT; i++) {
if (validShaderSet & (1U << i)) {
glAttachShader(program, this->gl.shaders[i]);
}
@@ -164,7 +164,7 @@ OpenGLProgram::~OpenGLProgram() noexcept {
GLuint program = gl.program;
if (validShaderSet) {
#pragma nounroll
for (size_t i = 0; i < Program::NUM_SHADER_TYPES; i++) {
for (size_t i = 0; i < Program::SHADER_TYPE_COUNT; i++) {
if (validShaderSet & (1U << i)) {
const GLuint shader = gl.shaders[i];
if (isValid) {
+8 -8
View File
@@ -61,14 +61,14 @@ public:
}
struct {
GLuint shaders[driver::Program::NUM_SHADER_TYPES];
GLuint shaders[driver::Program::SHADER_TYPE_COUNT];
GLuint program;
} gl; // 12 bytes
static void logCompilationError(utils::io::ostream& out, GLuint shaderId, char const* source) noexcept;
private:
static constexpr uint8_t NUM_TEXTURE_UNITS = OpenGLDriver::MAX_TEXTURE_UNITS;
static constexpr uint8_t TEXTURE_UNIT_COUNT = OpenGLDriver::MAX_TEXTURE_UNIT_COUNT;
static constexpr uint8_t VERTEX_SHADER_BIT = uint8_t(1) << size_t(driver::Program::Shader::VERTEX);
static constexpr uint8_t FRAGMENT_SHADER_BIT = uint8_t(1) << size_t(driver::Program::Shader::FRAGMENT);
@@ -77,11 +77,11 @@ private:
uint8_t unused : 1; // padding / available
uint8_t count : 4; // number of TMUs actually used minus 1
// if NUM_TEXTURE_UNITS > 16, the count bitfield must be increased accordingly
static_assert(NUM_TEXTURE_UNITS <= 16, "NUM_TEXTURE_UNITS must be <= 16");
// if TEXTURE_UNIT_COUNT > 16, the count bitfield must be increased accordingly
static_assert(TEXTURE_UNIT_COUNT <= 16, "TEXTURE_UNIT_COUNT must be <= 16");
// if NUM_SAMPLER_BINDINGS > 8, the binding bitfield must be increased accordingly
static_assert(driver::Program::NUM_SAMPLER_BINDINGS <= 8, "NUM_SAMPLER_BINDINGS must be <= 8");
// if SAMPLER_BINDING_COUNT > 8, the binding bitfield must be increased accordingly
static_assert(driver::Program::SAMPLER_BINDING_COUNT <= 8, "SAMPLER_BINDING_COUNT must be <= 8");
};
uint8_t mUsedBindingsCount = 0;
@@ -89,10 +89,10 @@ private:
bool mIsValid = false;
// information about each USED sampler buffer (no gaps)
std::array<BlockInfo, driver::Program::NUM_SAMPLER_BINDINGS> mBlockInfos; // 8 bytes
std::array<BlockInfo, driver::Program::SAMPLER_BINDING_COUNT> mBlockInfos; // 8 bytes
// runs of indices into SamplerGroup -- run start index and size given by BlockInfo
std::array<uint8_t, NUM_TEXTURE_UNITS> mIndicesRuns; // 16 bytes
std::array<uint8_t, TEXTURE_UNIT_COUNT> mIndicesRuns; // 16 bytes
void updateSamplers(OpenGLDriver* gl) noexcept;
};
+22 -22
View File
@@ -127,7 +127,7 @@ bool VulkanBinder::getOrCreateDescriptor(VkDescriptorSet* descriptor,
uint32_t& nwrites = mDescriptorUpdateOp.count;
VkWriteDescriptorSet* writes = &mDescriptorUpdateOp.writes[0];
nwrites = 0;
for (uint32_t binding = 0; binding < NUM_UBUFFER_BINDINGS; binding++) {
for (uint32_t binding = 0; binding < UBUFFER_BINDING_COUNT; binding++) {
if (mDescriptorKey.uniformBuffers[binding]) {
VkDescriptorBufferInfo& bufferInfo = mDescriptorBuffers[binding];
bufferInfo.buffer = mDescriptorKey.uniformBuffers[binding];
@@ -146,7 +146,7 @@ bool VulkanBinder::getOrCreateDescriptor(VkDescriptorSet* descriptor,
writeInfo.pTexelBufferView = nullptr;
}
}
for (uint32_t binding = 0; binding < NUM_SAMPLER_BINDINGS; binding++) {
for (uint32_t binding = 0; binding < SAMPLER_BINDING_COUNT; binding++) {
if (mDescriptorKey.samplers[binding].sampler) {
VkDescriptorImageInfo& imageInfo = mDescriptorSamplers[binding];
imageInfo = mDescriptorKey.samplers[binding];
@@ -154,7 +154,7 @@ bool VulkanBinder::getOrCreateDescriptor(VkDescriptorSet* descriptor,
writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeInfo.pNext = nullptr;
writeInfo.dstSet = mCurrentDescriptor->handle;
writeInfo.dstBinding = NUM_UBUFFER_BINDINGS + binding;
writeInfo.dstBinding = UBUFFER_BINDING_COUNT + binding;
writeInfo.dstArrayElement = 0;
writeInfo.descriptorCount = 1;
writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
@@ -211,7 +211,7 @@ bool VulkanBinder::getOrCreatePipeline(VkPipeline* pipeline) noexcept {
// entries because these arrays have a small fixed-size capacity.
uint32_t numVertexAttribs = 0;
uint32_t numVertexBuffers = 0;
for (uint32_t i = 0; i < MAX_VERTEX_ATTRIBUTES; i++) {
for (uint32_t i = 0; i < VERTEX_ATTRIBUTE_COUNT; i++) {
if (mPipelineKey.vertexAttributes[i].format > 0) {
numVertexAttribs++;
}
@@ -251,7 +251,7 @@ bool VulkanBinder::getOrCreatePipeline(VkPipeline* pipeline) noexcept {
pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineCreateInfo.layout = mPipelineLayout;
pipelineCreateInfo.renderPass = mPipelineKey.renderPass;
pipelineCreateInfo.stageCount = hasFragmentShader ? NUM_SHADER_MODULES : 1;
pipelineCreateInfo.stageCount = hasFragmentShader ? SHADER_MODULE_COUNT : 1;
pipelineCreateInfo.pStages = mShaderStages;
pipelineCreateInfo.pVertexInputState = &vertexInputState;
pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
@@ -288,7 +288,7 @@ bool VulkanBinder::getOrCreatePipeline(VkPipeline* pipeline) noexcept {
void VulkanBinder::bindProgramBundle(const ProgramBundle& bundle) noexcept {
const VkShaderModule shaders[2] = { bundle.vertex, bundle.fragment };
for (uint32_t ssi = 0; ssi < NUM_SHADER_MODULES; ssi++) {
for (uint32_t ssi = 0; ssi < SHADER_MODULE_COUNT; ssi++) {
if (mPipelineKey.shaders[ssi] != shaders[ssi]) {
mDirtyPipeline = true;
mPipelineKey.shaders[ssi] = shaders[ssi];
@@ -341,7 +341,7 @@ void VulkanBinder::bindPrimitiveTopology(VkPrimitiveTopology topology) noexcept
}
void VulkanBinder::bindVertexArray(const VertexArray& varray) noexcept {
for (size_t i = 0; i < MAX_VERTEX_ATTRIBUTES; i++) {
for (size_t i = 0; i < VERTEX_ATTRIBUTE_COUNT; i++) {
VkVertexInputAttributeDescription& attrib0 = mPipelineKey.vertexAttributes[i];
const VkVertexInputAttributeDescription& attrib1 = varray.attributes[i];
if (attrib1.location != attrib0.location || attrib1.binding != attrib0.binding ||
@@ -365,7 +365,7 @@ void VulkanBinder::bindVertexArray(const VertexArray& varray) noexcept {
void VulkanBinder::unbindUniformBuffer(VkBuffer uniformBuffer) noexcept {
auto& key = mDescriptorKey;
for (uint32_t bindingIndex = 0u; bindingIndex < NUM_UBUFFER_BINDINGS; ++bindingIndex) {
for (uint32_t bindingIndex = 0u; bindingIndex < UBUFFER_BINDING_COUNT; ++bindingIndex) {
if (key.uniformBuffers[bindingIndex] == uniformBuffer) {
key.uniformBuffers[bindingIndex] = {};
key.uniformBufferSizes[bindingIndex] = {};
@@ -423,9 +423,9 @@ void VulkanBinder::evictDescriptors(std::function<bool(const DescriptorKey&)> fi
void VulkanBinder::bindUniformBuffer(uint32_t bindingIndex, VkBuffer uniformBuffer,
VkDeviceSize offset, VkDeviceSize size) noexcept {
ASSERT_POSTCONDITION(bindingIndex < NUM_UBUFFER_BINDINGS,
ASSERT_POSTCONDITION(bindingIndex < UBUFFER_BINDING_COUNT,
"Uniform bindings overflow: index = %d, capacity = %d.",
bindingIndex, NUM_UBUFFER_BINDINGS);
bindingIndex, UBUFFER_BINDING_COUNT);
auto& key = mDescriptorKey;
if (key.uniformBuffers[bindingIndex] != uniformBuffer ||
key.uniformBufferOffsets[bindingIndex] != offset ||
@@ -438,11 +438,11 @@ void VulkanBinder::bindUniformBuffer(uint32_t bindingIndex, VkBuffer uniformBuff
}
void VulkanBinder::bindSampler(uint32_t bindingIndex, VkDescriptorImageInfo samplerInfo) noexcept {
const uint32_t offset = NUM_UBUFFER_BINDINGS;
const uint32_t offset = UBUFFER_BINDING_COUNT;
assert(bindingIndex >= offset);
ASSERT_POSTCONDITION(bindingIndex < offset + NUM_SAMPLER_BINDINGS,
ASSERT_POSTCONDITION(bindingIndex < offset + SAMPLER_BINDING_COUNT,
"Sampler bindings overflow: index = %d, capacity = %d.",
bindingIndex - offset, NUM_SAMPLER_BINDINGS);
bindingIndex - offset, SAMPLER_BINDING_COUNT);
VkDescriptorImageInfo& imageInfo = mDescriptorKey.samplers[bindingIndex - offset];
if (imageInfo.sampler != samplerInfo.sampler || imageInfo.imageView != samplerInfo.imageView ||
imageInfo.imageLayout != samplerInfo.imageLayout) {
@@ -517,29 +517,29 @@ void VulkanBinder::gc() noexcept {
}
void VulkanBinder::createLayoutsAndDescriptors() noexcept {
VkDescriptorSetLayoutBinding bindings[NUM_UBUFFER_BINDINGS + NUM_SAMPLER_BINDINGS];
VkDescriptorSetLayoutBinding bindings[UBUFFER_BINDING_COUNT + SAMPLER_BINDING_COUNT];
VkDescriptorSetLayoutBinding binding = {};
binding.descriptorCount = 1; // NOTE: We never use arrays-of-blocks.
binding.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS; // NOTE: This is potentially non-optimal.
// The first range of binding slots is reserved for UBO's.
binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
for (uint32_t i = 0; i < NUM_UBUFFER_BINDINGS; i++) {
for (uint32_t i = 0; i < UBUFFER_BINDING_COUNT; i++) {
binding.binding = i;
bindings[i] = binding;
}
// The second range of binding slots is reserved for samplers.
binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
for (uint32_t i = 0; i < NUM_SAMPLER_BINDINGS; i++) {
binding.binding = NUM_UBUFFER_BINDINGS + i;
for (uint32_t i = 0; i < SAMPLER_BINDING_COUNT; i++) {
binding.binding = UBUFFER_BINDING_COUNT + i;
bindings[binding.binding] = binding;
}
// Create the one and only VkDescriptorSetLayout that we'll ever use.
VkDescriptorSetLayoutCreateInfo dlinfo = {};
dlinfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
dlinfo.bindingCount = NUM_UBUFFER_BINDINGS + NUM_SAMPLER_BINDINGS;
dlinfo.bindingCount = UBUFFER_BINDING_COUNT + SAMPLER_BINDING_COUNT;
dlinfo.pBindings = &bindings[0];
VkResult err = vkCreateDescriptorSetLayout(mDevice, &dlinfo, VKALLOC, &mDescriptorSetLayout);
ASSERT_POSTCONDITION(!err, "Unable to create descriptor set layout.");
@@ -562,9 +562,9 @@ void VulkanBinder::createLayoutsAndDescriptors() noexcept {
.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
};
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
poolSizes[0].descriptorCount = poolInfo.maxSets * NUM_UBUFFER_BINDINGS;
poolSizes[0].descriptorCount = poolInfo.maxSets * UBUFFER_BINDING_COUNT;
poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
poolSizes[1].descriptorCount = poolInfo.maxSets * NUM_SAMPLER_BINDINGS;
poolSizes[1].descriptorCount = poolInfo.maxSets * SAMPLER_BINDING_COUNT;
err = vkCreateDescriptorPool(mDevice, &poolInfo, VKALLOC, &mDescriptorPool);
ASSERT_POSTCONDITION(!err, "Unable to create descriptor pool.");
}
@@ -599,14 +599,14 @@ bool VulkanBinder::PipelineEqual::operator()(const VulkanBinder::PipelineKey& k1
bool VulkanBinder::DescEqual::operator()(const VulkanBinder::DescriptorKey& k1,
const VulkanBinder::DescriptorKey& k2) const {
for (uint32_t i = 0; i < NUM_UBUFFER_BINDINGS; i++) {
for (uint32_t i = 0; i < UBUFFER_BINDING_COUNT; i++) {
if (k1.uniformBuffers[i] != k2.uniformBuffers[i] ||
k1.uniformBufferOffsets[i] != k2.uniformBufferOffsets[i] ||
k1.uniformBufferSizes[i] != k2.uniformBufferSizes[i]) {
return false;
}
}
for (uint32_t i = 0; i < NUM_SAMPLER_BINDINGS; i++) {
for (uint32_t i = 0; i < SAMPLER_BINDING_COUNT; i++) {
if (k1.samplers[i].sampler != k2.samplers[i].sampler ||
k1.samplers[i].imageView != k2.samplers[i].imageView ||
k1.samplers[i].imageLayout != k2.samplers[i].imageLayout) {
+17 -17
View File
@@ -71,18 +71,18 @@ namespace driver {
//
class VulkanBinder {
public:
static constexpr uint32_t NUM_UBUFFER_BINDINGS = Program::NUM_UNIFORM_BINDINGS;
static constexpr uint32_t NUM_SAMPLER_BINDINGS = driver::MAX_SAMPLER_COUNT;
static constexpr uint32_t NUM_SHADER_MODULES = 2;
static constexpr uint32_t MAX_VERTEX_ATTRIBUTES = driver::MAX_VERTEX_ATTRIBUTE_COUNT;
static constexpr uint32_t UBUFFER_BINDING_COUNT = Program::UNIFORM_BINDING_COUNT;
static constexpr uint32_t SAMPLER_BINDING_COUNT = driver::MAX_SAMPLER_COUNT;
static constexpr uint32_t SHADER_MODULE_COUNT = 2;
static constexpr uint32_t VERTEX_ATTRIBUTE_COUNT = driver::MAX_VERTEX_ATTRIBUTE_COUNT;
// The VertexArray POD is an array of buffer targets and an array of attributes that refer to
// those targets. It does not include any references to actual buffers, so you can think of it
// as a vertex assembler configuration. For simplicity it contains fixed-size arrays and does
// not store sizes; all unused entries are simply zeroed out.
struct VertexArray {
VkVertexInputAttributeDescription attributes[MAX_VERTEX_ATTRIBUTES];
VkVertexInputBindingDescription buffers[MAX_VERTEX_ATTRIBUTES];
VkVertexInputAttributeDescription attributes[VERTEX_ATTRIBUTE_COUNT];
VkVertexInputBindingDescription buffers[VERTEX_ATTRIBUTE_COUNT];
};
// The ProgramBundle contains weak references to the compiled vertex and fragment shaders.
@@ -105,7 +105,7 @@ public:
// Encapsulates the arguments passed to vkUpdateDescriptorSets.
struct DescriptorUpdateOp {
uint32_t count;
VkWriteDescriptorSet writes[NUM_UBUFFER_BINDINGS + NUM_SAMPLER_BINDINGS];
VkWriteDescriptorSet writes[UBUFFER_BINDING_COUNT + SAMPLER_BINDING_COUNT];
};
// Upon construction, the binder initializes some internal state but does not make any Vulkan
@@ -167,12 +167,12 @@ private:
// VkPipeline object. We apply a hash function to its contents only if has been mutated since
// the previous call to getOrCreatePipeline.
struct alignas(8) PipelineKey {
VkShaderModule shaders[NUM_SHADER_MODULES]; // 8*2 bytes
VkShaderModule shaders[SHADER_MODULE_COUNT]; // 8*2 bytes
RasterState rasterState; // 248 bytes
VkRenderPass renderPass; // 8 bytes
VkPrimitiveTopology topology; // 4 bytes
VkVertexInputAttributeDescription vertexAttributes[MAX_VERTEX_ATTRIBUTES]; // 16*5 bytes
VkVertexInputBindingDescription vertexBuffers[MAX_VERTEX_ATTRIBUTES]; // 12*5 bytes
VkVertexInputAttributeDescription vertexAttributes[VERTEX_ATTRIBUTE_COUNT]; // 16*5 bytes
VkVertexInputBindingDescription vertexBuffers[VERTEX_ATTRIBUTE_COUNT]; // 12*5 bytes
};
static_assert(sizeof(PipelineKey) ==
@@ -207,10 +207,10 @@ private:
// descriptor set. We apply a hash function to its contents only if has been mutated since
// the previous call to getOrCreateDescriptor.
struct alignas(8) DescriptorKey {
VkBuffer uniformBuffers[NUM_UBUFFER_BINDINGS];
VkDescriptorImageInfo samplers[NUM_SAMPLER_BINDINGS];
VkDeviceSize uniformBufferOffsets[NUM_UBUFFER_BINDINGS];
VkDeviceSize uniformBufferSizes[NUM_UBUFFER_BINDINGS];
VkBuffer uniformBuffers[UBUFFER_BINDING_COUNT];
VkDescriptorImageInfo samplers[SAMPLER_BINDING_COUNT];
VkDeviceSize uniformBufferOffsets[UBUFFER_BINDING_COUNT];
VkDeviceSize uniformBufferSizes[UBUFFER_BINDING_COUNT];
};
static_assert(sizeof(DescriptorKey) ==
@@ -247,10 +247,10 @@ private:
const RasterState mDefaultRasterState;
// Info structs used only in a transient way but they are stored for convenience.
VkPipelineShaderStageCreateInfo mShaderStages[NUM_SHADER_MODULES];
VkPipelineShaderStageCreateInfo mShaderStages[SHADER_MODULE_COUNT];
VkPipelineColorBlendStateCreateInfo mColorBlendState;
VkDescriptorBufferInfo mDescriptorBuffers[NUM_UBUFFER_BINDINGS];
VkDescriptorImageInfo mDescriptorSamplers[NUM_SAMPLER_BINDINGS];
VkDescriptorBufferInfo mDescriptorBuffers[UBUFFER_BINDING_COUNT];
VkDescriptorImageInfo mDescriptorSamplers[SAMPLER_BINDING_COUNT];
DescriptorUpdateOp mDescriptorUpdateOp;
// Current bindings are divided into two "keys" which are composed of a mix of actual values
+1 -1
View File
@@ -1017,7 +1017,7 @@ void VulkanDriver::draw(PipelineState pipelineState, Handle<HwRenderPrimitive> r
// Query the program for the mapping from (SamplerBufferBinding,Offset) to (SamplerBinding),
// where "SamplerBinding" is the integer in the GLSL, and SamplerBufferBinding is the abstract
// Filament concept used to form groups of samplers.
for (uint8_t bufferIdx = 0; bufferIdx < VulkanBinder::NUM_SAMPLER_BINDINGS; bufferIdx++) {
for (uint8_t bufferIdx = 0; bufferIdx < VulkanBinder::SAMPLER_BINDING_COUNT; bufferIdx++) {
VulkanSamplerGroup* vksb = mSamplerBindings[bufferIdx];
if (!vksb) {
continue;
+1 -1
View File
@@ -148,7 +148,7 @@ private:
VulkanFboCache mFramebufferCache;
VulkanSamplerCache mSamplerCache;
VulkanRenderTarget* mCurrentRenderTarget = nullptr;
VulkanSamplerGroup* mSamplerBindings[VulkanBinder::NUM_SAMPLER_BINDINGS] = {};
VulkanSamplerGroup* mSamplerBindings[VulkanBinder::SAMPLER_BINDING_COUNT] = {};
VkDebugReportCallbackEXT mDebugCallback = VK_NULL_HANDLE;
};
@@ -51,7 +51,7 @@ VulkanProgram::VulkanProgram(VulkanContext& context, const Program& builder) noe
auto const& blobs = builder.getShadersSource();
VkShaderModule* modules[2] = { &bundle.vertex, &bundle.fragment };
bool missing = false;
for (size_t i = 0; i < Program::NUM_SHADER_TYPES; i++) {
for (size_t i = 0; i < Program::SHADER_TYPE_COUNT; i++) {
const auto& blob = blobs[i];
VkShaderModule* module = modules[i];
if (blob.empty()) {
@@ -40,7 +40,7 @@ namespace BindingPoints {
constexpr uint8_t POST_PROCESS = 4; // samplers for the post process pass
constexpr uint8_t PER_MATERIAL_INSTANCE = 5; // uniforms/samplers updates per material
constexpr uint8_t COUNT = 6;
// These are limited by Program::NUM_UNIFORM_BINDINGS (currently 6)
// These are limited by Program::UNIFORM_BINDING_COUNT (currently 6)
}
static_assert(BindingPoints::PER_MATERIAL_INSTANCE == BindingPoints::COUNT - 1,