vulkan: implement compute shaders

A lot of stuff probably isn't implemented yet, however the
following code already works:

```lua
local shader = love.graphics.newComputeShader [[
    layout (local_size_x = 1, local_size_y = 1) in;

    layout(r32f) uniform highp image2D out_tex;

    uniform float time;

    void computemain() {
        imageStore(out_tex, ivec2(love_GlobalThreadID.xy), vec4(time, 1.0, 1.0, 1.0));
    }
]]

local tex = love.graphics.newTexture(64, 64, {computewrite = true,format = "r32f"})

function love.draw()
    shader:send("out_tex", tex)
    shader:send("time", love.timer.getTime() % 1)
    love.graphics.dispatchThreadgroups(shader, 64, 64, 1)

    love.graphics.print("compute shader test")
    love.graphics.draw(tex, 25, 25)
end
```
This commit is contained in:
niki
2022-08-31 02:07:46 +02:00
parent e409770be1
commit a0ee9f7b9b
7 changed files with 380 additions and 157 deletions
+4 -1
View File
@@ -22,6 +22,8 @@ public:
void setSamplerState(const SamplerState &s) override;
VkImageLayout getImageLayout() const;
void copyFromBuffer(graphics::Buffer* source, size_t sourceoffset, int sourcewidth, size_t size, int slice, int mipmap, const Rect& rect) override;
void copyToBuffer(graphics::Buffer* dest, int slice, int mipmap, const Rect& rect, size_t destoffset, int destwidth, size_t size) override;
@@ -39,12 +41,13 @@ private:
void createTextureImageView();
void clear();
VkClearColorValue getClearValue(bool white);
VkClearColorValue getClearValue();
graphics::Graphics* gfx = nullptr;
VkDevice device = VK_NULL_HANDLE;
VmaAllocator allocator = VK_NULL_HANDLE;
VkImage textureImage = VK_NULL_HANDLE;
VkImageLayout imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
VmaAllocation textureImageAllocation = VK_NULL_HANDLE;
VkImageView textureImageView = VK_NULL_HANDLE;
VkSampler textureSampler = VK_NULL_HANDLE;