AnsweredAssumed Answered

Violation access with cl_event from GLsync usage

Question asked by vlj on Mar 16, 2015
Latest reply on Apr 6, 2015 by vlj

Hi,

 

Using R9 290X with Catalyst 14.12 on Windows 8.1 I'm trying to use OpenCL for TressFX simulation :

YAGF/tfx-ocl.cpp at master · vlj/YAGF · GitHub

The relevant part of the code is :

 

  int err = CL_SUCCESS;

  cl_event ev = 0;

  if (syncFirstPassRenderComplete);

    ev = clCreateEventFromGLsyncKHRCustom(context, syncFirstPassRenderComplete, &err);

 

  // First pass is done so sim is done too, can safely upload

  err = clEnqueueWriteBuffer(queue, ConstantSimBuffer, CL_FALSE, 0, sizeof(struct SimulationConstants), &cbuf, 0, 0, 0);

 

  err = clEnqueueAcquireGLObjects(queue, 1, &PosBuffer, 0, 0, 0);

  err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &PosBuffer);

  err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &PreviousPos);

  err = clSetKernelArg(kernel, 2, sizeof(cl_mem), &StrandType);

  err = clSetKernelArg(kernel, 3, sizeof(cl_mem), &InitialPos);

  err = clSetKernelArg(kernel, 4, sizeof(cl_mem), &ConstantSimBuffer);

  size_t local_wg = 64;

  size_t global_wg = .5 * tfxassets.m_NumTotalHairVertices;

  err = clEnqueueNDRangeKernel(queue, kernel, 1, 0, &global_wg, &local_wg, 0, 0, 0);

 

  err = clEnqueueReleaseGLObjects(queue, 1, &PosBuffer, 0, 0, 0);

  clFinish(queue);

  if (syncFirstPassRenderComplete);

  {

    glDeleteSync(syncFirstPassRenderComplete);

    clReleaseEvent(ev);

  }

 

  return;

 

I'm attempting to use explicit sync between cl and GL using  clCreateEventFromGLsyncKHR by replacing

 

  err = clEnqueueWriteBuffer(queue, ConstantSimBuffer, CL_FALSE, 0, sizeof(struct SimulationConstants), &cbuf, 0, 0, 0);

 

by

 

  if (ev)

    err = clEnqueueWriteBuffer(queue, ConstantSimBuffer, CL_FALSE, 0, sizeof(struct SimulationConstants), &cbuf, 1, &ev, 0);

  else

    err = clEnqueueWriteBuffer(queue, ConstantSimBuffer, CL_FALSE, 0, sizeof(struct SimulationConstants), &cbuf, 0, 0, 0);

 

ie I'm adding a sync between last GL command that uses PosBuffer and before first opencl command so that some opencl upload/kernel can be executed while the second OpenGL fragment shader is in flight.

It works however after a couple of frame there is a crash in atigktxx.dll (Access violation reading location 0xFEEEFEEE.). I get no OpenCL or OpenGL error.

 

I'm not sure what's happening since I delete sync and clean cl_event after cl_finish. I tested with an event generated from an opencl call each frame and it works, I suspect the issue only happens with cl_event generated from GL sync object.

Outcomes