mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
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:
@@ -25,11 +25,13 @@ public:
|
||||
bool loadVolatile() override;
|
||||
void unloadVolatile() override;
|
||||
|
||||
VkPipeline getComputePipeline() const;
|
||||
|
||||
const std::vector<VkPipelineShaderStageCreateInfo>& getShaderStages() const;
|
||||
|
||||
const VkPipelineLayout getGraphicsPipelineLayout() const;
|
||||
|
||||
void cmdPushDescriptorSets(VkCommandBuffer, uint32_t currentFrame);
|
||||
void cmdPushDescriptorSets(VkCommandBuffer, uint32_t currentFrame, VkPipelineBindPoint);
|
||||
|
||||
void attach() override;
|
||||
|
||||
@@ -74,6 +76,8 @@ private:
|
||||
|
||||
VkDeviceSize uniformBufferSizeAligned;
|
||||
|
||||
VkPipeline computePipeline;
|
||||
|
||||
VkDescriptorSetLayout descriptorSetLayout;
|
||||
VkPipelineLayout pipelineLayout;
|
||||
|
||||
@@ -90,6 +94,8 @@ private:
|
||||
Graphics* gfx;
|
||||
VkDevice device;
|
||||
|
||||
bool isCompute = false;
|
||||
|
||||
std::unordered_map<std::string, graphics::Shader::UniformInfo> uniformInfos;
|
||||
UniformInfo* builtinUniformInfo[BUILTIN_MAX_ENUM];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user