diff --git a/drape/render_state.cpp b/drape/render_state.cpp index 77055cb9d2..dbe0844f7b 100644 --- a/drape/render_state.cpp +++ b/drape/render_state.cpp @@ -1,9 +1,12 @@ #include "drape/render_state.hpp" + #include "drape/drape_global.hpp" #include "drape/gl_functions.hpp" #include "drape/gl_gpu_program.hpp" -#include "base/buffer_vector.hpp" +#include "drape/vulkan/vulkan_base_context.hpp" +#include "drape/vulkan/vulkan_gpu_program.hpp" +#include "drape/vulkan/vulkan_texture.hpp" namespace dp { @@ -225,7 +228,24 @@ void TextureState::ApplyTextures(ref_ptr context, RenderState c } else if (apiVersion == dp::ApiVersion::Vulkan) { - //TODO(@rokuz, @darina): Implement. Use Bind! + ref_ptr vulkanContext = context; + ref_ptr p = program; + auto const & bindings = p->GetTextureBindings(); + for (auto const & texture : state.GetTextures()) + { + auto const it = bindings.find(texture.first); + CHECK(it != bindings.end(), ("Texture bindings inconsistency.")); + + ref_ptr t = texture.second->GetHardwareTexture(); + + dp::vulkan::ParamDescriptor descriptor; + descriptor.m_type = dp::vulkan::ParamDescriptor::Type::Texture; + descriptor.m_imageDescriptor.imageView = t->GetTextureView(); + descriptor.m_imageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + //descriptor.m_imageDescriptor.sampler =; //TODO(@rokuz, @darina): Implement. + descriptor.m_textureSlot = it->second; + vulkanContext->ApplyParamDescriptor(std::move(descriptor)); + } } else { @@ -254,7 +274,9 @@ void ApplyState(ref_ptr context, ref_ptr program, R } else if (apiVersion == dp::ApiVersion::Vulkan) { - //TODO(@rokuz, @darina): Implement. + ref_ptr vulkanContext = context; + vulkanContext->SetProgram(program); + vulkanContext->SetBlendingEnabled(state.GetBlending().m_isEnabled); } else { @@ -272,20 +294,26 @@ void ApplyState(ref_ptr context, ref_ptr program, R ApplyDepthStencilStateForMetal(context); #endif } - else if (apiVersion == dp::ApiVersion::Vulkan) - { - //TODO(@rokuz, @darina): Implement. - } - // Metal does not support line width. - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (state.GetDrawAsLine()) { - ASSERT_GREATER_OR_EQUAL(state.GetLineWidth(), 0, ()); - GLFunctions::glLineWidth(static_cast(state.GetLineWidth())); - } - else if (apiVersion == dp::ApiVersion::Vulkan) - { - //TODO(@rokuz, @darina): Implement. + if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + { + ASSERT_GREATER_OR_EQUAL(state.GetLineWidth(), 0, ()); + GLFunctions::glLineWidth(static_cast(state.GetLineWidth())); + } + else if (apiVersion == dp::ApiVersion::Metal) + { + // Do nothing. Metal does not support line width. + } + else if (apiVersion == dp::ApiVersion::Vulkan) + { + ASSERT_GREATER_OR_EQUAL(state.GetLineWidth(), 0, ()); + ref_ptr vulkanContext = context; + VkCommandBuffer commandBuffer = vulkanContext->GetCurrentCommandBuffer(); + CHECK(commandBuffer != nullptr, ()); + vkCmdSetLineWidth(commandBuffer, static_cast(state.GetLineWidth())); + } } } } // namespace dp diff --git a/drape/vulkan/vulkan_base_context.cpp b/drape/vulkan/vulkan_base_context.cpp index 87fbecd397..8fdabe610e 100644 --- a/drape/vulkan/vulkan_base_context.cpp +++ b/drape/vulkan/vulkan_base_context.cpp @@ -608,9 +608,29 @@ void VulkanBaseContext::SetBindingInfo(std::vector const & bind //TODO } +void VulkanBaseContext::SetProgram(ref_ptr program) +{ + //TODO +} + +void VulkanBaseContext::SetBlendingEnabled(bool blendingEnabled) +{ + //TODO +} + +void VulkanBaseContext::ApplyParamDescriptor(ParamDescriptor && descriptor) +{ + //TODO +} + +void VulkanBaseContext::ClearParamDescriptors() +{ + //TODO +} + VkPipeline VulkanBaseContext::GetCurrentPipeline() { - return nullptr; + return {}; } } // namespace vulkan } // namespace dp diff --git a/drape/vulkan/vulkan_base_context.hpp b/drape/vulkan/vulkan_base_context.hpp index 48b96dc005..edab1f7ef1 100644 --- a/drape/vulkan/vulkan_base_context.hpp +++ b/drape/vulkan/vulkan_base_context.hpp @@ -2,8 +2,10 @@ #include "drape/graphics_context.hpp" #include "drape/pointers.hpp" +#include "drape/vulkan/vulkan_gpu_program.hpp" #include "drape/vulkan/vulkan_object_manager.hpp" #include "drape/vulkan/vulkan_pipeline.hpp" +#include "drape/vulkan/vulkan_utils.hpp" #include "geometry/point2d.hpp" @@ -64,6 +66,11 @@ public: void SetPrimitiveTopology(VkPrimitiveTopology topology); void SetBindingInfo(std::vector const & bindingInfo); + void SetProgram(ref_ptr program); + void SetBlendingEnabled(bool blendingEnabled); + + void ApplyParamDescriptor(ParamDescriptor && descriptor); + void ClearParamDescriptors(); void SetSurface(VkSurfaceKHR surface, VkSurfaceFormatKHR surfaceFormat, VkSurfaceCapabilitiesKHR surfaceCapabilities, int width, int height); diff --git a/drape/vulkan/vulkan_gpu_program.hpp b/drape/vulkan/vulkan_gpu_program.hpp index a874bc40c1..ca230494d9 100644 --- a/drape/vulkan/vulkan_gpu_program.hpp +++ b/drape/vulkan/vulkan_gpu_program.hpp @@ -38,7 +38,7 @@ public: std::array GetShaders() const { - return {m_vertexShader, m_fragmentShader}; + return {{m_vertexShader, m_fragmentShader}}; } VkDescriptorSetLayout GetDescriptorSetLayout() const { return m_descriptorSetLayout; } diff --git a/drape/vulkan/vulkan_mesh_object_impl.cpp b/drape/vulkan/vulkan_mesh_object_impl.cpp index 1e53227cf4..0b6ec6f32b 100644 --- a/drape/vulkan/vulkan_mesh_object_impl.cpp +++ b/drape/vulkan/vulkan_mesh_object_impl.cpp @@ -171,6 +171,8 @@ public: vkCmdBindVertexBuffers(commandBuffer, i, 1, &m_geometryBuffers[i].m_buffer, offsets); vkCmdDraw(commandBuffer, verticesCount, 1, 0, 0); + + vulkanContext->ClearParamDescriptors(); } void Bind(ref_ptr program) override {} diff --git a/drape/vulkan/vulkan_utils.hpp b/drape/vulkan/vulkan_utils.hpp index d290440cde..f98b80176e 100644 --- a/drape/vulkan/vulkan_utils.hpp +++ b/drape/vulkan/vulkan_utils.hpp @@ -13,6 +13,23 @@ namespace dp namespace vulkan { extern std::string GetVulkanResultString(VkResult result); + +struct ParamDescriptor +{ + enum class Type : uint8_t + { + DynamicUniformBuffer, + Texture + }; + + Type m_type = Type::DynamicUniformBuffer; + + VkDescriptorBufferInfo m_bufferDescriptor = {}; + uint32_t m_bufferDynamicOffset = 0; + + VkDescriptorImageInfo m_imageDescriptor = {}; + int8_t m_textureSlot = 0; +}; } // namespace vulkan } // namespace dp diff --git a/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp b/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp index 3f44d9f663..a08b418ef2 100644 --- a/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp +++ b/drape/vulkan/vulkan_vertex_array_buffer_impl.cpp @@ -102,6 +102,8 @@ public: vkCmdBindIndexBuffer(commandBuffer, vulkanIndexBuffer, 0, indexType); vkCmdDrawIndexed(commandBuffer, range.m_idxCount, 1, range.m_idxStart, 0, 0); + + vulkanContext->ClearParamDescriptors(); } private: diff --git a/shaders/vulkan_program_params.cpp b/shaders/vulkan_program_params.cpp index 2e07d7154b..4dfd8a5cdd 100644 --- a/shaders/vulkan_program_params.cpp +++ b/shaders/vulkan_program_params.cpp @@ -89,7 +89,6 @@ void VulkanProgramParamsSetter::Finish() } void VulkanProgramParamsSetter::ApplyBytes(ref_ptr context, - ref_ptr program, void const * data, uint32_t sizeInBytes) { auto const & mm = m_objectManager->GetMemoryManager(); @@ -126,8 +125,12 @@ void VulkanProgramParamsSetter::ApplyBytes(ref_ptrApplyParamDescriptor(std::move(descriptor)); } void VulkanProgramParamsSetter::Apply(ref_ptr context, diff --git a/shaders/vulkan_program_params.hpp b/shaders/vulkan_program_params.hpp index 0fee30fc3b..d82b6a8a6b 100644 --- a/shaders/vulkan_program_params.hpp +++ b/shaders/vulkan_program_params.hpp @@ -59,11 +59,12 @@ private: void ApplyImpl(ref_ptr context, ref_ptr program, T const & params) { - ApplyBytes(context, program, reinterpret_cast(¶ms), sizeof(params)); + ASSERT_EQUAL(T::GetName(), ProgramParams::GetBoundParamsName(program), + ("Mismatched program and parameters", program->GetName())); + ApplyBytes(context, reinterpret_cast(¶ms), sizeof(params)); } void ApplyBytes(ref_ptr context, - ref_ptr program, void const * data, uint32_t sizeInBytes); ref_ptr m_objectManager; diff --git a/shaders/vulkan_program_pool.cpp b/shaders/vulkan_program_pool.cpp index f8536dc356..dc1e3d18f9 100644 --- a/shaders/vulkan_program_pool.cpp +++ b/shaders/vulkan_program_pool.cpp @@ -143,6 +143,10 @@ std::vector GetLayoutBindings(ReflectionInfo const uniformsBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; result.push_back(std::move(uniformsBinding)); } + else + { + CHECK(false, ("Uniforms must be at least in one shader.")); + } for (auto const & t : reflectionInfo.m_textures) {