diff --git a/changes.txt b/changes.txt index d5a383905..4e20f44fa 100644 --- a/changes.txt +++ b/changes.txt @@ -15,6 +15,7 @@ Released: N/A * Added Joystick:getGamepadType. * Added new Gamepad API buttons: "misc1", "paddle1", "paddle2", "paddle3", "paddle4". and "touchpad". * Added a Metal backend to love.graphics, available on macOS 10.15+ and iOS 13+. +* Added a Vulkan backend to love.graphics, available on Windows, Linux, and Android 7+. * Added '--renderers a,b,c' and '--excluderenderers a,b,c' command line arguments. * Added t.renderers and t.excluderenderers love.conf options. * Added t.highdpi startup flag in love.conf, replacing t.window.highdpi and the highdpi flag of love.window.setMode. diff --git a/src/modules/graphics/vulkan/Buffer.h b/src/modules/graphics/vulkan/Buffer.h index 5c5212534..1c0311e6c 100644 --- a/src/modules/graphics/vulkan/Buffer.h +++ b/src/modules/graphics/vulkan/Buffer.h @@ -15,7 +15,7 @@ namespace vulkan class Graphics; -class Buffer +class Buffer final : public love::graphics::Buffer , public Volatile { diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index c2e30c63c..ff774e534 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -42,7 +42,11 @@ constexpr bool enableValidationLayers = true; constexpr int MAX_FRAMES_IN_FLIGHT = 2; +#if defined(VK_VERSION_1_1) +constexpr uint32_t vulkanApiVersion = VK_API_VERSION_1_1; +#else constexpr uint32_t vulkanApiVersion = VK_API_VERSION_1_0; +#endif const char *Graphics::getName() const { @@ -166,7 +170,10 @@ void Graphics::clear(const std::vector &colors, OptionalInt sten rect.rect.extent.width = static_cast(renderPassState.width); rect.rect.extent.height = static_cast(renderPassState.height); - vkCmdClearAttachments(commandBuffers[currentFrame], static_cast(attachments.size()), attachments.data(), 1, &rect); + vkCmdClearAttachments( + commandBuffers[currentFrame], + static_cast(attachments.size()), attachments.data(), + 1, &rect); } void Graphics::discard(const std::vector& colorbuffers, bool depthstencil) @@ -387,7 +394,7 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int createDefaultTexture(); createDefaultShaders(); - Shader::current = Shader::standardShaders[graphics::Shader::StandardShader::STANDARD_DEFAULT]; + Shader::current = Shader::standardShaders[Shader::StandardShader::STANDARD_DEFAULT]; createQuadIndexBuffer(); restoreState(states.back()); @@ -397,7 +404,6 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int Vulkan::resetShaderSwitches(); currentFrame = 0; - created = true; drawCalls = 0; drawCallsBatched = 0; @@ -561,7 +567,12 @@ 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); + vkCmdDraw( + commandBuffers.at(currentFrame), + static_cast(cmd.vertexCount), + static_cast(cmd.instanceCount), + static_cast(cmd.vertexStart), + 0); drawCalls++; } @@ -569,8 +580,18 @@ void Graphics::draw(const DrawIndexedCommand &cmd) { prepareDraw(*cmd.attributes, *cmd.buffers, cmd.texture, cmd.primitiveType, cmd.cullMode); - 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); + 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++; } @@ -581,7 +602,11 @@ void Graphics::drawQuads(int start, int count, const VertexAttributes &attribute prepareDraw(attributes, buffers, texture, PRIMITIVE_TRIANGLES, CULL_BACK); - vkCmdBindIndexBuffer(commandBuffers.at(currentFrame), (VkBuffer)quadIndexBuffer->getHandle(), 0, Vulkan::getVulkanIndexBufferType(INDEX_UINT16)); + vkCmdBindIndexBuffer( + commandBuffers.at(currentFrame), + (VkBuffer)quadIndexBuffer->getHandle(), + 0, + Vulkan::getVulkanIndexBufferType(INDEX_UINT16)); int baseVertex = start * 4; @@ -589,7 +614,13 @@ void Graphics::drawQuads(int start, int count, const VertexAttributes &attribute { int quadcount = std::min(MAX_QUADS_PER_DRAW, count - quadindex); - vkCmdDrawIndexed(commandBuffers.at(currentFrame), static_cast(quadcount * 6), 1, 0, baseVertex, 0); + vkCmdDrawIndexed( + commandBuffers.at(currentFrame), + static_cast(quadcount * 6), + 1, + 0, + baseVertex, + 0); baseVertex += quadcount * 4; drawCalls++; @@ -1958,7 +1989,6 @@ void Graphics::createVulkanVertexFormat( } } - // do we need to use a constant VertexColor? if (!usesColor) { // FIXME: is there a case where gaps happen between buffer bindings? @@ -2109,7 +2139,6 @@ void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, b transitionImages.push_back((VkImage) color.texture->getHandle()); } if (rts.depthStencil.texture != nullptr) - // fixme: layout transition of depth stencil image? configuration.staticData.depthView = (VkImageView)rts.depthStencil.texture->getRenderTargetHandle(); configuration.staticData.width = static_cast(pixelw); diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index 497781d50..540c1874b 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -323,9 +323,9 @@ public: const VkDeviceSize getMinUniformBufferOffsetAlignment() const; graphics::Texture *getDefaultTexture() const; - VkSampler getCachedSampler(const SamplerState &); + VkSampler getCachedSampler(const SamplerState &samplerState); - void setComputeShader(Shader *); + void setComputeShader(Shader *computeShader); std::set &getUsedShadersInFrame(); graphics::Shader::BuiltinUniformData getCurrentBuiltinUniformData(); @@ -361,11 +361,11 @@ private: void createImageViews(); void createDefaultRenderPass(); void createDefaultFramebuffers(); - VkFramebuffer createFramebuffer(FramebufferConfiguration &); - VkFramebuffer getFramebuffer(FramebufferConfiguration &); + VkFramebuffer createFramebuffer(FramebufferConfiguration &configuration); + VkFramebuffer getFramebuffer(FramebufferConfiguration &configuration); void createDefaultShaders(); - VkRenderPass createRenderPass(RenderPassConfiguration &); - VkPipeline createGraphicsPipeline(GraphicsPipelineConfiguration &); + VkRenderPass createRenderPass(RenderPassConfiguration &configuration); + VkPipeline createGraphicsPipeline(GraphicsPipelineConfiguration &configuration); void createColorResources(); VkFormat findSupportedFormat(const std::vector &candidates, VkImageTiling tiling, VkFormatFeatureFlags features); VkFormat findDepthFormat(); @@ -381,9 +381,9 @@ private: void beginFrame(); void startRecordingGraphicsCommands(bool newFrame); void endRecordingGraphicsCommands(bool present); - void ensureGraphicsPipelineConfiguration(GraphicsPipelineConfiguration &); + void ensureGraphicsPipelineConfiguration(GraphicsPipelineConfiguration &configuration); void updatedBatchedDrawBuffers(); - bool usesConstantVertexColor(const VertexAttributes &); + bool usesConstantVertexColor(const VertexAttributes &attribs); void createVulkanVertexFormat( VertexAttributes vertexAttributes, std::vector &bindingDescriptions, @@ -393,7 +393,7 @@ private: void setDefaultRenderPass(); void startRenderPass(); void endRenderPass(); - VkSampler createSampler(const SamplerState&); + VkSampler createSampler(const SamplerState &samplerState); VkInstance instance = VK_NULL_HANDLE; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; diff --git a/src/modules/graphics/vulkan/GraphicsReadback.h b/src/modules/graphics/vulkan/GraphicsReadback.h index 1d0355e7b..702de7b78 100644 --- a/src/modules/graphics/vulkan/GraphicsReadback.h +++ b/src/modules/graphics/vulkan/GraphicsReadback.h @@ -11,7 +11,7 @@ namespace vulkan class Graphics; -class GraphicsReadback : public graphics::GraphicsReadback +class GraphicsReadback final : public graphics::GraphicsReadback { public: GraphicsReadback(love::graphics::Graphics *gfx, ReadbackMethod method, love::graphics::Buffer *buffer, size_t offset, size_t size, data::ByteData *dest, size_t destoffset); diff --git a/src/modules/graphics/vulkan/StreamBuffer.h b/src/modules/graphics/vulkan/StreamBuffer.h index 8df9e0f2c..18e7b0202 100644 --- a/src/modules/graphics/vulkan/StreamBuffer.h +++ b/src/modules/graphics/vulkan/StreamBuffer.h @@ -15,7 +15,7 @@ namespace vulkan class Graphics; -class StreamBuffer +class StreamBuffer final : public love::graphics::StreamBuffer , public graphics::Volatile { diff --git a/src/modules/graphics/vulkan/Texture.h b/src/modules/graphics/vulkan/Texture.h index 2f9e845a5..59970eba0 100644 --- a/src/modules/graphics/vulkan/Texture.h +++ b/src/modules/graphics/vulkan/Texture.h @@ -15,7 +15,7 @@ namespace vulkan class Graphics; -class Texture +class Texture final : public graphics::Texture , public Volatile {