29package com.jogamp.opencl;
31import com.jogamp.common.nio.Buffers;
35import com.jogamp.common.nio.PointerBuffer;
36import com.jogamp.opencl.llb.CL;
38import java.nio.Buffer;
39import java.util.ArrayList;
40import java.util.Collections;
48 private List<CLSubBuffer<B>> childs;
51 this(context,
null,
size, id, flags);
54 protected CLBuffer(
final CLContext context,
final B directBuffer,
final long size,
final long id,
final int flags) {
55 super(context, directBuffer,
size,
id, flags);
58 @SuppressWarnings(
"rawtypes")
62 throw new IllegalArgumentException(
"no host pointer defined");
65 final CL binding = context.getPlatform().getCLBinding();
66 final int[] result =
new int[1];
67 final long id = binding.clCreateBuffer(context.ID, flags,
size,
null, result, 0);
68 CLException.checkForError(result[0],
"can not create cl buffer");
73 static <B extends Buffer> CLBuffer<B> create(
final CLContext context,
final B directBuffer,
final int flags) {
75 if(!directBuffer.isDirect())
76 throw new IllegalArgumentException(
"buffer is not direct");
80 host_ptr = directBuffer;
83 final CL binding = context.getPlatform().getCLBinding();
84 final int[] result =
new int[1];
85 final int size = Buffers.sizeOfBufferElem(directBuffer) * directBuffer.limit();
86 final long id = binding.clCreateBuffer(context.ID, flags,
size, host_ptr, result, 0);
87 CLException.checkForError(result[0],
"can not create cl buffer");
89 return new CLBuffer<B>(context, directBuffer,
size,
id, flags);
105 slice = Buffers.slice(buffer, offset,
size);
106 final int elemSize = Buffers.sizeOfBufferElem(buffer);
113 final PointerBuffer info = PointerBuffer.allocateDirect(2);
118 final CL binding = getPlatform().getCLBinding();
119 final int[] err =
new int[1];
125 childs =
new ArrayList<CLSubBuffer<B>>();
127 childs.add(clSubBuffer);
134 while(!childs.isEmpty()) {
135 childs.get(0).release();
148 @SuppressWarnings(
"unchecked")
151 return Collections.EMPTY_LIST;
153 return Collections.unmodifiableList(childs);
165 public <T extends Buffer>
CLBuffer<T> cloneWith(
final T directBuffer) {
OpenCL buffer object wrapping an optional NIO buffer.
CLSubBuffer< B > createSubBuffer(int offset, int size, final Mem... flags)
Creates a sub buffer with the specified region from this buffer.
List< CLSubBuffer< B > > getSubBuffers()
Returns the list of subbuffers.
CLBuffer(final CLContext context, final long size, final long id, final int flags)
CLBuffer(final CLContext context, final B directBuffer, final long size, final long id, final int flags)
boolean isSubBuffer()
Returns true if this is a sub buffer.
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
Main Exception type for runtime OpenCL errors and failed function calls (e.g.
static void checkForError(final int status, final String message)
Throws a CLException when status != CL_SUCCESS.
Common superclass for all OpenCL memory types.
static boolean isHostPointerFlag(final int flags)
Returns true if a host pointer must be specified on mem object creation.
A sub buffer of a CLBuffer.
Memory settings for configuring CLMemory.
static int flagsToInt(final Mem[] flags)
Java bindings to OpenCL, the Open Computing Language.
long clCreateSubBuffer(long buffer, long flags, int buffer_create_type, Buffer buffer_create_info, IntBuffer errcode_ret)
Interface to C language function: cl_mem {@native clCreateSubBuffer}(cl_mem buffer,...
static final int CL_BUFFER_CREATE_TYPE_REGION
Define "CL_BUFFER_CREATE_TYPE_REGION" with expression '0x1220', CType: int.