Fix Buffer creation from Lua
jadarve opened this issue · 0 comments
jadarve commented
The script below does not work:
local builder = ll.class(ll.ComputeNodeBuilder)
function builder.newDescriptor()
local desc = ll.ComputeNodeDescriptor.new()
desc.builderName = 'Square'
desc.localShape = ll.vec3ui.new(32, 1, 1)
desc.gridShape = ll.vec3ui.new(1, 1, 1)
desc.program = ll.getProgram('Square')
desc.functionName = 'main'
desc:addPort(ll.PortDescriptor.new(0, 'in_buffer', ll.PortDirection.In, ll.PortType.Buffer))
desc:addPort(ll.PortDescriptor.new(1, 'out_buffer', ll.PortDirection.Out, ll.PortType.Buffer))
return desc
end
function builder.onNodeInit(node)
local in_buffer = node:getPort('in_buffer')
-- Allocate out_buffer in the same Memory as in_buffer
local memory = in_buffer.memory
-- TODO: call createBuffer using default usage flags
-- TODO: overload of createBuffer with in_buffer.usageFlags does not work. Need unsafe version
local out_buffer = memory:createBuffer(in_buffer.size)
-- bind the output
node:bind('out_buffer', out_buffer)
-- configure the dispath shapes according to the size of in_buffer
node:configureGridShape(ll.vec3ui.new(in_buffer.size / 4, 1, 1))
end
ll.registerNodeBuilder('Square', builder)