clray

diff src/ocl.cc @ 12:85fd61f374d9

fixed the bloody intersection bug
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 03 Aug 2010 13:06:59 +0100
parents d9a1bab1c3f5
children 407935b73af3
line diff
     1.1 --- a/src/ocl.cc	Sat Jul 31 22:23:57 2010 +0100
     1.2 +++ b/src/ocl.cc	Tue Aug 03 13:06:59 2010 +0100
     1.3 @@ -78,9 +78,14 @@
     1.4  {
     1.5  	int err;
     1.6  	cl_mem mem;
     1.7 +	cl_mem_flags flags = rdwr | CL_MEM_ALLOC_HOST_PTR;
     1.8  
     1.9 +	if(buf) {
    1.10 +		flags |= CL_MEM_COPY_HOST_PTR;
    1.11 +	}
    1.12  
    1.13 -	if(!(mem = clCreateBuffer(ctx, rdwr | CL_MEM_USE_HOST_PTR, sz, buf, &err))) {
    1.14 +
    1.15 +	if(!(mem = clCreateBuffer(ctx, flags, sz, buf, &err))) {
    1.16  		fprintf(stderr, "failed to create memory buffer: %s\n", clstrerror(err));
    1.17  		return 0;
    1.18  	}
    1.19 @@ -88,13 +93,13 @@
    1.20  	CLMemBuffer *mbuf = new CLMemBuffer;
    1.21  	mbuf->mem = mem;
    1.22  	mbuf->size = sz;
    1.23 +	mbuf->ptr = 0;
    1.24  	return mbuf;
    1.25  }
    1.26  
    1.27  void destroy_mem_buffer(CLMemBuffer *mbuf)
    1.28  {
    1.29  	if(mbuf) {
    1.30 -
    1.31  		clReleaseMemObject(mbuf->mem);
    1.32  		delete mbuf;
    1.33  	}
    1.34 @@ -104,6 +109,12 @@
    1.35  {
    1.36  	if(!mbuf) return 0;
    1.37  
    1.38 +#ifndef NDEBUG
    1.39 +	if(mbuf->ptr) {
    1.40 +		fprintf(stderr, "WARNING: map_mem_buffer called on already mapped buffer\n");
    1.41 +	}
    1.42 +#endif
    1.43 +
    1.44  	int err;
    1.45  	mbuf->ptr = clEnqueueMapBuffer(cmdq, mbuf->mem, 1, rdwr, 0, mbuf->size, 0, 0, 0, &err);
    1.46  	if(!mbuf->ptr) {
    1.47 @@ -117,6 +128,7 @@
    1.48  {
    1.49  	if(!mbuf || !mbuf->ptr) return;
    1.50  	clEnqueueUnmapMemObject(cmdq, mbuf->mem, mbuf->ptr, 0, 0, 0);
    1.51 +	mbuf->ptr = 0;
    1.52  }
    1.53  
    1.54  bool write_mem_buffer(CLMemBuffer *mbuf, size_t sz, void *src)