Пример #1
0
cl_mem
clCreateSubBuffer(cl_mem                d_buffer,
                  cl_mem_flags          flags,
                  cl_buffer_create_type buffer_create_type,
                  const void *          buffer_create_info,
                  cl_int *              errcode_ret)
{
    cl_int dummy_errcode;
    // code below seems to be expecting a Coal::Buffer *, so convert to such:
    Coal::Buffer * buffer = (Coal::Buffer *)pobj(d_buffer);

    if (!errcode_ret)
        errcode_ret = &dummy_errcode;

    if (!buffer->isA(Coal::Object::T_MemObject))
    {
        *errcode_ret = CL_INVALID_MEM_OBJECT;
        return 0;
    }

    Coal::MemObject *memobject = (Coal::MemObject *)buffer;
    cl_buffer_region *region = (cl_buffer_region *)buffer_create_info;

    // NOTE: Is it right ? Couldn't we create SubBuffers of images ?
    if (memobject->type() != Coal::MemObject::Buffer)
    {
        *errcode_ret = CL_INVALID_MEM_OBJECT;
        return 0;
    }

    if (buffer_create_type != CL_BUFFER_CREATE_TYPE_REGION)
    {
        *errcode_ret = CL_INVALID_VALUE;
        return 0;
    }

    if (!buffer_create_info)
    {
        *errcode_ret = CL_INVALID_VALUE;
        return 0;
    }

    *errcode_ret = CL_SUCCESS;

    Coal::SubBuffer *buf = new Coal::SubBuffer(buffer,
                                               region->origin, region->size,
                                               flags, errcode_ret);

    if (*errcode_ret != CL_SUCCESS || (*errcode_ret = buf->init()) != CL_SUCCESS)
    {
        delete buf;
        return 0;
    }

    return desc(buf);
}
Пример #2
0
cl_mem
clCreateSubBuffer(cl_mem                buffer,
                  cl_mem_flags          flags,
                  cl_buffer_create_type buffer_create_type,
                  const void *          buffer_create_info,
                  cl_int *              errcode_ret)
{
    cl_int dummy_errcode;
    
    if (!errcode_ret)
        errcode_ret = &dummy_errcode;
    
    if (!buffer)
    {
        *errcode_ret = CL_INVALID_MEM_OBJECT;
        return 0;
    }
    
    Coal::MemObject *memobject = (Coal::MemObject *)buffer;
    cl_buffer_region *region = (cl_buffer_region *)buffer_create_info;
    
    // NOTE: Is it right ? Couldn't we create SubBuffers of images ?
    if (memobject->type() != Coal::MemObject::Buffer)
    {
        *errcode_ret = CL_INVALID_MEM_OBJECT;
        return 0;
    }
    
    if (buffer_create_type != CL_BUFFER_CREATE_TYPE_REGION)
    {
        *errcode_ret = CL_INVALID_VALUE;
        return 0;
    }
    
    if (!buffer_create_info)
    {
        *errcode_ret = CL_INVALID_VALUE;
        return 0;
    }
    
    *errcode_ret = CL_SUCCESS;
    
    Coal::SubBuffer *buf = new Coal::SubBuffer((Coal::Buffer *)buffer,
                                               region->origin, region->size, 
                                               flags, errcode_ret);
    
    if (*errcode_ret != CL_SUCCESS || (*errcode_ret = buf->init()) != CL_SUCCESS)
    {
        delete buf;
        return 0;
    }
    
    return (cl_mem)buf;
}