Do not indent C++ namespace contents This is a style change. Visual Studio defaults to indenting namespace contents, and this was adopted for a long time, but with the new Vulkan implementation this was abandoned. However the legacy code borrowed from the OpenGL ES implementation still used indentation so it was inconsistent. The justification for not indenting namespace contents is that namespaces are merely a way to avoid name clashes with other projects we don't control directly (and in rare cases internal subprojects when we want to reuse the same names). Hence the vast majority of files have a single namespace, and unlike indentation used for ease of discerning control flow blocks, class contents, or function contents, which can become highly nested, there is no such readability advantage to indenting namespace contents. This is also the Google style recommendation (though no justification or discussion is provided): https://google.github.io/styleguide/cppguide.html#Namespace_Formatting One reasonable counter-argument is consistency with other blocks of curly brackets, but considering that most namespaces span almost the entire file, it's a substantial waste of line length. Because there is no indentation, there's also no need to have the open and closing brackets line up as a visual aid, like we prefer for other uses of curly brackets. So we place the open bracket on the same line as the namespace keyword. A comment is added to the closing bracket to discern it from other closing brackets. It also makes it easier to find the end of anonymous namespaces which typically go at the top of the source file. This change is make separately from applying clang-format because diff tools mark all these unindented lines as changes and this makes it hard to review the smaller style changes made by clang-format. The OpenGL ES and Direct3D code is left untouched because it is in maintenance mode and in case of regressions we want easy 'blame' tool usage. Bug: b/144825072 Change-Id: Ie2925ebd697e1ffa7c4cbdc9a946531f11f4d934 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39348 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Device/VertexProcessor.cpp b/src/Device/VertexProcessor.cpp index c6b96e1..e77b2f7 100644 --- a/src/Device/VertexProcessor.cpp +++ b/src/Device/VertexProcessor.cpp
@@ -21,124 +21,125 @@ #include <cstring> -namespace sw +namespace sw { + +void VertexCache::clear() { - void VertexCache::clear() + for(uint32_t i = 0; i < SIZE; i++) { - for(uint32_t i = 0; i < SIZE; i++) - { - tag[i] = 0xFFFFFFFF; - } - } - - uint32_t VertexProcessor::States::computeHash() - { - uint32_t *state = reinterpret_cast<uint32_t*>(this); - uint32_t hash = 0; - - for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++) - { - hash ^= state[i]; - } - - return hash; - } - - unsigned int VertexProcessor::States::Input::bytesPerAttrib() const - { - switch(type) - { - case STREAMTYPE_FLOAT: - case STREAMTYPE_INT: - case STREAMTYPE_UINT: - return count * sizeof(uint32_t); - case STREAMTYPE_HALF: - case STREAMTYPE_SHORT: - case STREAMTYPE_USHORT: - return count * sizeof(uint16_t); - case STREAMTYPE_BYTE: - case STREAMTYPE_SBYTE: - return count * sizeof(uint8_t); - case STREAMTYPE_COLOR: - case STREAMTYPE_2_10_10_10_INT: - case STREAMTYPE_2_10_10_10_UINT: - return sizeof(int); - default: - UNSUPPORTED("stream.type %d", int(type)); - } - - return 0; - } - - bool VertexProcessor::State::operator==(const State &state) const - { - if(hash != state.hash) - { - return false; - } - - static_assert(is_memcmparable<State>::value, "Cannot memcmp States"); - return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0; - } - - VertexProcessor::VertexProcessor() - { - routineCache = nullptr; - setRoutineCacheSize(1024); - } - - VertexProcessor::~VertexProcessor() - { - delete routineCache; - routineCache = nullptr; - } - - void VertexProcessor::setRoutineCacheSize(int cacheSize) - { - delete routineCache; - routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536)); - } - - const VertexProcessor::State VertexProcessor::update(const sw::Context* context) - { - State state; - - state.shaderID = context->vertexShader->getSerialID(); - state.robustBufferAccess = context->robustBufferAccess; - state.isPoint = context->topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST; - - for(int i = 0; i < MAX_INTERFACE_COMPONENTS / 4; i++) - { - state.input[i].type = context->input[i].type; - state.input[i].count = context->input[i].count; - state.input[i].normalized = context->input[i].normalized; - // TODO: get rid of attribType -- just keep the VK format all the way through, this fully determines - // how to handle the attribute. - state.input[i].attribType = context->vertexShader->inputs[i*4].Type; - } - - state.hash = state.computeHash(); - - return state; - } - - VertexProcessor::RoutineType VertexProcessor::routine(const State &state, - vk::PipelineLayout const *pipelineLayout, - SpirvShader const *vertexShader, - const vk::DescriptorSet::Bindings &descriptorSets) - { - auto routine = routineCache->query(state); - - if(!routine) // Create one - { - VertexRoutine *generator = new VertexProgram(state, pipelineLayout, vertexShader, descriptorSets); - generator->generate(); - routine = (*generator)("VertexRoutine_%0.8X", state.shaderID); - delete generator; - - routineCache->add(state, routine); - } - - return routine; + tag[i] = 0xFFFFFFFF; } } + +uint32_t VertexProcessor::States::computeHash() +{ + uint32_t *state = reinterpret_cast<uint32_t*>(this); + uint32_t hash = 0; + + for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++) + { + hash ^= state[i]; + } + + return hash; +} + +unsigned int VertexProcessor::States::Input::bytesPerAttrib() const +{ + switch(type) + { + case STREAMTYPE_FLOAT: + case STREAMTYPE_INT: + case STREAMTYPE_UINT: + return count * sizeof(uint32_t); + case STREAMTYPE_HALF: + case STREAMTYPE_SHORT: + case STREAMTYPE_USHORT: + return count * sizeof(uint16_t); + case STREAMTYPE_BYTE: + case STREAMTYPE_SBYTE: + return count * sizeof(uint8_t); + case STREAMTYPE_COLOR: + case STREAMTYPE_2_10_10_10_INT: + case STREAMTYPE_2_10_10_10_UINT: + return sizeof(int); + default: + UNSUPPORTED("stream.type %d", int(type)); + } + + return 0; +} + +bool VertexProcessor::State::operator==(const State &state) const +{ + if(hash != state.hash) + { + return false; + } + + static_assert(is_memcmparable<State>::value, "Cannot memcmp States"); + return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0; +} + +VertexProcessor::VertexProcessor() +{ + routineCache = nullptr; + setRoutineCacheSize(1024); +} + +VertexProcessor::~VertexProcessor() +{ + delete routineCache; + routineCache = nullptr; +} + +void VertexProcessor::setRoutineCacheSize(int cacheSize) +{ + delete routineCache; + routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536)); +} + +const VertexProcessor::State VertexProcessor::update(const sw::Context* context) +{ + State state; + + state.shaderID = context->vertexShader->getSerialID(); + state.robustBufferAccess = context->robustBufferAccess; + state.isPoint = context->topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + + for(int i = 0; i < MAX_INTERFACE_COMPONENTS / 4; i++) + { + state.input[i].type = context->input[i].type; + state.input[i].count = context->input[i].count; + state.input[i].normalized = context->input[i].normalized; + // TODO: get rid of attribType -- just keep the VK format all the way through, this fully determines + // how to handle the attribute. + state.input[i].attribType = context->vertexShader->inputs[i*4].Type; + } + + state.hash = state.computeHash(); + + return state; +} + +VertexProcessor::RoutineType VertexProcessor::routine(const State &state, + vk::PipelineLayout const *pipelineLayout, + SpirvShader const *vertexShader, + const vk::DescriptorSet::Bindings &descriptorSets) +{ + auto routine = routineCache->query(state); + + if(!routine) // Create one + { + VertexRoutine *generator = new VertexProgram(state, pipelineLayout, vertexShader, descriptorSets); + generator->generate(); + routine = (*generator)("VertexRoutine_%0.8X", state.shaderID); + delete generator; + + routineCache->add(state, routine); + } + + return routine; +} + +} // namespace sw