diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index ad53892da..ce45f9e83 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -322,6 +322,8 @@ bool Graphics::setMode(void* context, int width, int height, int pixelwidth, int currentFrame = 0; created = true; + drawCalls = 0; + drawCallsBatched = 0; return true; } @@ -462,6 +464,7 @@ void Graphics::draw(const DrawCommand& cmd) { prepareDraw(*cmd.attributes, *cmd.buffers, cmd.texture, cmd.primitiveType, cmd.cullMode); vkCmdDraw(commandBuffers.at(currentFrame), static_cast(cmd.vertexCount), static_cast(cmd.instanceCount), static_cast(cmd.vertexStart), 0); + drawCalls++; } void Graphics::draw(const DrawIndexedCommand& cmd) { @@ -469,6 +472,7 @@ void Graphics::draw(const DrawIndexedCommand& cmd) { vkCmdBindIndexBuffer(commandBuffers.at(currentFrame), (VkBuffer)cmd.indexBuffer->getHandle(), static_cast(cmd.indexBufferOffset), Vulkan::getVulkanIndexBufferType(cmd.indexType)); vkCmdDrawIndexed(commandBuffers.at(currentFrame), static_cast(cmd.indexCount), static_cast(cmd.instanceCount), 0, 0, 0); + drawCalls++; } void Graphics::drawQuads(int start, int count, const VertexAttributes& attributes, const BufferBindings& buffers, graphics::Texture* texture) { @@ -486,6 +490,8 @@ void Graphics::drawQuads(int start, int count, const VertexAttributes& attribute vkCmdDrawIndexed(commandBuffers.at(currentFrame), static_cast(quadcount * 6), 1, 0, baseVertex, 0); baseVertex += quadcount * 4; + + drawCalls++; } } diff --git a/src/modules/graphics/vulkan/Shader.cpp b/src/modules/graphics/vulkan/Shader.cpp index 7c98f5743..8dc4e20e0 100644 --- a/src/modules/graphics/vulkan/Shader.cpp +++ b/src/modules/graphics/vulkan/Shader.cpp @@ -118,7 +118,7 @@ static const TBuiltInResource defaultTBuiltInResource = { }; static const uint32_t STREAMBUFFER_DEFAULT_SIZE = 16; -static const uint32_t DESCRIPTOR_POOL_SIZE = 16; +static const uint32_t DESCRIPTOR_POOL_SIZE = 1; static VkShaderStageFlagBits getStageBit(ShaderStageType type) { switch (type) { @@ -394,7 +394,8 @@ void Shader::attach() { } int Shader::getVertexAttributeIndex(const std::string& name) { - return 0; + auto it = attributes.find(name); + return it == attributes.end() ? -1 : it->second; } const Shader::UniformInfo* Shader::getUniformInfo(const std::string& name) const { @@ -564,7 +565,8 @@ void Shader::compileShaders() { uniformInfos.clear(); for (int i = 0; i < SHADERSTAGE_MAX_ENUM; i++) { - auto glslangStage = getGlslShaderType((ShaderStageType)i); + auto shaderStage = (ShaderStageType)i; + auto glslangStage = getGlslShaderType(shaderStage); auto intermediate = program->getIntermediate(glslangStage); if (intermediate == nullptr) { continue; @@ -746,6 +748,14 @@ void Shader::compileShaders() { uniformInfos[u.name] = u; } + + if (shaderStage == SHADERSTAGE_VERTEX) { + for (const auto& r : shaderResources.stage_inputs) { + const auto& name = r.name; + const int attributeLocation = static_cast(comp.get_decoration(r.id, spv::DecorationLocation)); + attributes[name] = attributeLocation; + } + } } delete program; diff --git a/src/modules/graphics/vulkan/Shader.h b/src/modules/graphics/vulkan/Shader.h index e2f0566ab..63a44bd70 100644 --- a/src/modules/graphics/vulkan/Shader.h +++ b/src/modules/graphics/vulkan/Shader.h @@ -107,6 +107,8 @@ private: uint32_t uniformLocation; size_t builtinUniformDataOffset; + std::unordered_map attributes; + uint32_t currentFrame; uint32_t currentUsedUniformStreamBuffersCount; uint32_t currentUsedDescriptorSetsCount;