mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
love.graphics.dispatchThreadgroups;
This commit is contained in:
@@ -1066,6 +1066,25 @@ void Graphics::copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, siz
|
||||
source->copyTo(dest, sourceoffset, destoffset, size);
|
||||
}
|
||||
|
||||
void Graphics::dispatchThreadgroups(Shader* shader, int x, int y, int z)
|
||||
{
|
||||
if (!shader->hasStage(SHADERSTAGE_COMPUTE))
|
||||
throw love::Exception("Only compute shaders can have threads dispatched.");
|
||||
|
||||
if (x <= 0 || y <= 0 || z <= 0)
|
||||
throw love::Exception("Threadgroup dispatch size must be positive.");
|
||||
|
||||
if (x > capabilities.limits[LIMIT_THREADGROUPS_X]
|
||||
|| y > capabilities.limits[LIMIT_THREADGROUPS_Y]
|
||||
|| z > capabilities.limits[LIMIT_THREADGROUPS_Z])
|
||||
{
|
||||
throw love::Exception("Too many threadgroups dispatched.");
|
||||
}
|
||||
|
||||
shader->attach();
|
||||
dispatch(x, y, z);
|
||||
}
|
||||
|
||||
Graphics::BatchedVertexData Graphics::requestBatchedDraw(const BatchedDrawCommand &cmd)
|
||||
{
|
||||
BatchedDrawState &state = batchedDrawState;
|
||||
|
||||
@@ -674,6 +674,8 @@ public:
|
||||
|
||||
void copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, size_t destoffset, size_t size);
|
||||
|
||||
void dispatchThreadgroups(Shader* shader, int x, int y, int z);
|
||||
|
||||
void draw(Drawable *drawable, const Matrix4 &m);
|
||||
void draw(Texture *texture, Quad *quad, const Matrix4 &m);
|
||||
void drawLayer(Texture *texture, int layer, const Matrix4 &m);
|
||||
@@ -935,6 +937,8 @@ protected:
|
||||
virtual Shader *newShaderInternal(StrongRef<ShaderStage> stages[SHADERSTAGE_MAX_ENUM]) = 0;
|
||||
virtual StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) = 0;
|
||||
|
||||
virtual void dispatch(int x, int y, int z) = 0;
|
||||
|
||||
virtual void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) = 0;
|
||||
|
||||
virtual void initCapabilities() = 0;
|
||||
|
||||
@@ -469,6 +469,11 @@ void Graphics::setActive(bool enable)
|
||||
active = enable;
|
||||
}
|
||||
|
||||
void Graphics::dispatch(int x, int y, int z)
|
||||
{
|
||||
glDispatchCompute(x, y, z);
|
||||
}
|
||||
|
||||
void Graphics::draw(const DrawCommand &cmd)
|
||||
{
|
||||
gl.prepareDraw(this);
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
void setActive(bool active) override;
|
||||
|
||||
void dispatch(int x, int y, int z) override;
|
||||
|
||||
void draw(const DrawCommand &cmd) override;
|
||||
void draw(const DrawIndexedCommand &cmd) override;
|
||||
void drawQuads(int start, int count, const VertexAttributes &attributes, const BufferBindings &buffers, love::graphics::Texture *texture) override;
|
||||
|
||||
@@ -3255,6 +3255,16 @@ int w_polygon(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_dispatchThreadgroups(lua_State* L)
|
||||
{
|
||||
Shader *shader = luax_checkshader(L, 1);
|
||||
int x = (int) luaL_checkinteger(L, 2);
|
||||
int y = (int) luaL_optinteger(L, 3, 1);
|
||||
int z = (int) luaL_optinteger(L, 4, 1);
|
||||
luax_catchexcept(L, [&](){ instance()->dispatchThreadgroups(shader, x, y, z); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_copyBuffer(lua_State *L)
|
||||
{
|
||||
Buffer *source = luax_checkbuffer(L, 1);
|
||||
@@ -3472,6 +3482,8 @@ static const luaL_Reg functions[] =
|
||||
{ "print", w_print },
|
||||
{ "printf", w_printf },
|
||||
|
||||
{ "dispatchThreadgroups", w_dispatchThreadgroups },
|
||||
|
||||
{ "copyBuffer", w_copyBuffer },
|
||||
|
||||
{ "isCreated", w_isCreated },
|
||||
|
||||
Reference in New Issue
Block a user