Skip to content

I only want to merge the OpenGL-CL interop #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: baw
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
*.vcxproj
App/App.vcxproj.user
*.filters
Expand Down
18 changes: 16 additions & 2 deletions CLW/CLWImage2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ CLWImage2D CLWImage2D::Create(cl_context context, cl_image_format const* imgForm
}


CLWImage2D CLWImage2D::CreateFromGLTexture(cl_context context, cl_GLint texture)
CLWImage2D CLWImage2D::CreateFromGLTexture(cl_context context, cl_GLint texture, cl_mem_flags flags)
{
cl_int status = CL_SUCCESS;

// TODO: handle that gracefully: GL_TEXTURE_2D
cl_mem deviceImg = clCreateFromGLTexture(context, CL_MEM_WRITE_ONLY, 0x0DE1, 0, texture, &status);
cl_mem deviceImg = clCreateFromGLTexture(context, flags, 0x0DE1, 0, texture, &status);

ThrowIf(status != CL_SUCCESS, status, "clCreateFromGLTexture failed");

Expand All @@ -69,6 +69,20 @@ CLWImage2D CLWImage2D::CreateFromGLTexture(cl_context context, cl_GLint texture)
return image;
}

CLWImage2D CLWImage2D::CreateFromGLRenderbuffer(cl_context context, cl_GLint buffer, cl_mem_flags flags) {
cl_int status = CL_SUCCESS;

cl_mem deviceImg = clCreateFromGLRenderbuffer(context, flags, buffer, &status);

ThrowIf(status != CL_SUCCESS, status, "clCreateFromGLRenderbuffer failed");

CLWImage2D image(deviceImg);

clReleaseMemObject(deviceImg);

return image;
}

CLWImage2D::CLWImage2D(cl_mem image)
: ReferenceCounter<cl_mem, clRetainMemObject, clReleaseMemObject>(image)
{
Expand Down
3 changes: 2 additions & 1 deletion CLW/CLWImage2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class CLWImage2D : public ReferenceCounter<cl_mem, clRetainMemObject, clReleaseM
{
public:
static CLWImage2D Create(cl_context context, cl_image_format const* imgFormat, size_t width, size_t height, size_t rowPitch);
static CLWImage2D CreateFromGLTexture(cl_context context, cl_GLint texture);
static CLWImage2D CreateFromGLTexture(cl_context context, cl_GLint texture, cl_mem_flags flags = CL_MEM_WRITE_ONLY);
static CLWImage2D CreateFromGLRenderbuffer(cl_context context, cl_GLint buffer, cl_mem_flags flags = CL_MEM_WRITE_ONLY);

CLWImage2D(){}
virtual ~CLWImage2D();
Expand Down
2 changes: 1 addition & 1 deletion RadeonRays/src/kernels/CL/build_hlbvh.cl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>

/*************************************************************************
DEFINES
Expand Down
5 changes: 5 additions & 0 deletions RadeonRays/src/kernels/CL/common.cl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ typedef struct
float4 uvwt;
} Intersection;

typedef struct
{
int shape_id;
int prim_id;
} Occlusion;

/*************************************************************************
HELPER FUNCTIONS
Expand Down
10 changes: 6 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_bvh2_bittrail.cl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>


/*************************************************************************
Expand Down Expand Up @@ -147,7 +147,7 @@ occluded_main(
// Displacement table size
int const displacement_table_size,
// Hit results: 1 for hit and -1 for miss
GLOBAL int* hits
GLOBAL Occlusion* hits
)
{
int global_id = get_global_id(0);
Expand Down Expand Up @@ -193,7 +193,8 @@ occluded_main(
// If hit store the result and bail out
if (f < t_max)
{
hits[global_id] = HIT_MARKER;
hits[global_id].shape_id = face.shape_id;
hits[global_id].prim_id = face.prim_id;
return;
}
}
Expand Down Expand Up @@ -267,7 +268,8 @@ occluded_main(
}

// Finished traversal, but no intersection found
hits[global_id] = MISS_MARKER;
hits[global_id].shape_id = MISS_MARKER;
hits[global_id].prim_id = MISS_MARKER;
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_bvh2_lds.cl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>

/*************************************************************************
TYPE DEFINITIONS
Expand Down Expand Up @@ -229,7 +229,7 @@ KERNEL void occluded_main(
// Stack memory
GLOBAL uint *stack,
// Hit results: 1 for hit and -1 for miss
GLOBAL int *hits)
GLOBAL Occlusion *hits)
{
__local uint lds_stack[GROUP_SIZE * LDS_STACK_SIZE];

Expand Down Expand Up @@ -322,7 +322,8 @@ KERNEL void occluded_main(

if (t < closest_t)
{
hits[index] = HIT_MARKER;
hits[index].shape_id = GetMeshId(node);
hits[index].prim_id = GetPrimId(node);
return;
}
}
Expand All @@ -343,7 +344,8 @@ KERNEL void occluded_main(
}

// Finished traversal, but no intersection found
hits[index] = MISS_MARKER;
hits[index].shape_id = MISS_MARKER;
hits[index].prim_id = MISS_MARKER;
}
}
}
10 changes: 6 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_bvh2_lds_fp16.cl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>

/*************************************************************************
TYPE DEFINITIONS
Expand Down Expand Up @@ -317,7 +317,7 @@ KERNEL void occluded_main(
// Stack memory
GLOBAL uint *stack,
// Hit results: 1 for hit and -1 for miss
GLOBAL int *hits)
GLOBAL Occlusion *hits)
{
__local uint lds_stack[GROUP_SIZE * LDS_STACK_SIZE];

Expand Down Expand Up @@ -436,7 +436,8 @@ KERNEL void occluded_main(

if (t < closest_t)
{
hits[index] = HIT_MARKER;
hits[index].prim_id = node.aabb23_min_or_v2_and_addr2_or_prim_id.w;
hits[index].shape_id = node.aabb01_max_or_v1_and_addr1_or_mesh_id.w;
return;
}
}
Expand All @@ -457,7 +458,8 @@ KERNEL void occluded_main(
}

// Finished traversal, but no intersection found
hits[index] = MISS_MARKER;
hits[index].shape_id = MISS_MARKER;
hits[index].prim_id = MISS_MARKER;
}
}
}
10 changes: 6 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_bvh2_short_stack.cl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>


/*************************************************************************
Expand Down Expand Up @@ -139,7 +139,7 @@ occluded_main(
// Stack memory
GLOBAL int* stack,
// Hit results: 1 for hit and -1 for miss
GLOBAL int* hits
GLOBAL Occlusion* hits
)
{
// Allocate stack in LDS
Expand Down Expand Up @@ -197,7 +197,8 @@ occluded_main(
// If hit update closest hit distance and index
if (f < t_max)
{
hits[global_id] = HIT_MARKER;
hits[global_id].shape_id = node.shape_id;
hits[global_id].prim_id = node.prim_id;
return;
}
}
Expand Down Expand Up @@ -275,7 +276,8 @@ occluded_main(
}

// Finished traversal, but no intersection found
hits[global_id] = MISS_MARKER;
hits[global_id].shape_id = MISS_MARKER;
hits[global_id].prim_id = MISS_MARKER;
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_bvh2_skiplinks.cl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>

/*************************************************************************
EXTENSIONS
**************************************************************************/
Expand Down Expand Up @@ -211,7 +212,7 @@ void occluded_main(
// Number of rays
GLOBAL int const* restrict num_rays,
// Hit data
GLOBAL int* hits
GLOBAL Occlusion* hits
)
{
int global_id = get_global_id(0);
Expand Down Expand Up @@ -256,7 +257,8 @@ void occluded_main(
// If hit store the result and bail out
if (f < t_max)
{
hits[global_id] = HIT_MARKER;
hits[global_id].shape_id = face.shape_id;
hits[global_id].prim_id = face.prim_id;
return;
}
}
Expand All @@ -273,7 +275,8 @@ void occluded_main(
}

// Finished traversal, but no intersection found
hits[global_id] = MISS_MARKER;
hits[global_id].shape_id = MISS_MARKER;
hits[global_id].prim_id = MISS_MARKER;
}
}
}
10 changes: 6 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_bvh2level_skiplinks.cl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>

/*************************************************************************
EXTENSIONS
Expand Down Expand Up @@ -320,7 +320,7 @@ KERNEL void occluded_main(
// Number of rays in ray buffer
GLOBAL int const* restrict num_rays,
// Hits
GLOBAL int* hits
GLOBAL Occlusion* hits
)
{
int global_id = get_global_id(0);
Expand Down Expand Up @@ -374,7 +374,8 @@ KERNEL void occluded_main(
// If hit update closest hit distance and index
if (f < t_max)
{
hits[global_id] = HIT_MARKER;
hits[global_id].shape_id = face.shape_id;
hits[global_id].prim_id = face.prim_id;
return;
}

Expand Down Expand Up @@ -443,7 +444,8 @@ KERNEL void occluded_main(
}
}

hits[global_id] = MISS_MARKER;
hits[global_id].shape_id = MISS_MARKER;
hits[global_id].prim_id = MISS_MARKER;
}
}
}
10 changes: 6 additions & 4 deletions RadeonRays/src/kernels/CL/intersect_hlbvh_stack.cl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ THE SOFTWARE.
/*************************************************************************
INCLUDES
**************************************************************************/
#include <../RadeonRays/src/kernels/CL/common.cl>
#include <common.cl>

/*************************************************************************
EXTENSIONS
Expand Down Expand Up @@ -94,7 +94,7 @@ occluded_main(
// Stack memory
GLOBAL int* stack,
// Hit results: 1 for hit and -1 for miss
GLOBAL int* hits
GLOBAL Occlusion* hits
)
{
int global_id = get_global_id(0);
Expand Down Expand Up @@ -151,7 +151,8 @@ occluded_main(
// If hit update closest hit distance and index
if (f < t_max)
{
hits[global_id] = HIT_MARKER;
hits[global_id].shape_id = face.shape_id;
hits[global_id].prim_id = face.prim_id;
return;
}
}
Expand Down Expand Up @@ -229,7 +230,8 @@ occluded_main(
}

// Finished traversal, but no intersection found
hits[global_id] = MISS_MARKER;
hits[global_id].shape_id = MISS_MARKER;
hits[global_id].prim_id = MISS_MARKER;
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions Tools/scripts/stringify.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ def printfile(filename, dir):
fh = open(dir + "/" + filename)
for line in fh.readlines():
a = line.strip('\r\n')
inl = re.search("#include\s*<.*/(.+)>", a)
inl = re.search("#include\s*<(.+)>", a)
if inl:
printfile( inl.group(1), dir)
a = inl.group(1)
fn = a.split('/')[-1]
a = a.replace( fn, "" )
printfile( fn, dir + "/" + a)
else:
print( '"' + a.replace("\\","\\\\").replace("\"", "\\\"") + ' \\n"\\' )

Expand Down