Пример #1
0
  void memory_t<COI>::copyTo(memory_v *dest,
                             const uintptr_t bytes,
                             const uintptr_t destOffset,
                             const uintptr_t srcOffset){
    coiStream &stream = *((coiStream*) dev->currentStream);

    const uintptr_t bytes_ = (bytes == 0) ? size : bytes;

    OCCA_CHECK((bytes_ + destOffset) <= dest->size);
    OCCA_CHECK((bytes_ + srcOffset)  <=       size);

    OCCA_COI_CHECK("Memory: Blocking on Memory Transfer",
                   COIEventWait(1, &(stream.lastEvent),
                                -1, true, NULL, NULL) );

    OCCA_COI_CHECK("Memory: Copy From",
                   COIBufferCopy(*((coiMemory*) dest->handle),
                                 *((coiMemory*) handle),
                                 destOffset,
                                 srcOffset,
                                 bytes_,
                                 COI_COPY_UNSPECIFIED,
                                 false, NULL,
                                 &(stream.lastEvent)));

    OCCA_COI_CHECK("Memory: Blocking on Memory Transfer",
                   COIEventWait(1, &(stream.lastEvent),
                                -1, true, NULL, NULL) );
  }
Пример #2
0
  void memory_t<COI>::copyFrom(const void *source,
                               const uintptr_t bytes,
                               const uintptr_t offset){
    coiStream &stream = *((coiStream*) dev->currentStream);

    const uintptr_t bytes_ = (bytes == 0) ? size : bytes;

    OCCA_CHECK((bytes_ + offset) <= size);

    OCCA_COI_CHECK("Memory: Blocking on Memory Transfer",
                   COIEventWait(1, &(stream.lastEvent),
                                -1, true, NULL, NULL) );

    OCCA_COI_CHECK("Memory: Copy From",
                   COIBufferWrite(*((coiMemory*) handle),
                                  offset,
                                  source,
                                  bytes_,
                                  COI_COPY_UNSPECIFIED,
                                  false, NULL,
                                  &(stream.lastEvent)));

    OCCA_COI_CHECK("Memory: Blocking on Memory Transfer",
                   COIEventWait(1, &(stream.lastEvent),
                                -1, true, NULL, NULL) );
  }
Пример #3
0
  void device_t<COI>::finish(){
    coiStream &stream = *((coiStream*) dev->currentStream);

    OCCA_COI_CHECK("Device: Waiting for Event",
                   COIEventWait(1, &(stream.lastEvent),
                                -1, true, NULL, NULL) );
  }
Пример #4
0
  bool pick(const float x, const float y, const Vec3fa& vx, const Vec3fa& vy, const Vec3fa& vz, const Vec3fa& p, Vec3fa& hitPos)
  {
    PickDataSend send;
    send.x = x; send.y = y;
    send.vx = vx; send.vy = vy; send.vz = vz; send.p = p;

    COIEVENT event;
    memset(&event,0,sizeof(event));

    PickDataReceive receive;
    COIRESULT result = COIPipelineRunFunction (pipeline, runPick, 0, NULL, NULL, 0, NULL, &send, sizeof(send), &receive, sizeof(receive), &event);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));

    result = COIEventWait(1,&event,-1,1,NULL,NULL);
    if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result)));

    hitPos = receive.pos;
    return receive.hit;
  }
Пример #5
0
  void send_hairset (OBJScene::HairSet* hairset)
  {
    COIRESULT result;
    struct {
      COIBUFFER position;    //!< vertex position array
      COIBUFFER hairs;      //!< hair array
    } buffers;

    size_t positionBytes = max(size_t(16),hairset->v.size()*sizeof(Vec3fa));
    void* positionPtr = hairset->v.size() ? &hairset->v.front() : NULL;
    result = COIBufferCreate(positionBytes,COI_BUFFER_STREAMING_TO_SINK,0,positionPtr,1,&process,&buffers.position);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    size_t hairsBytes = max(size_t(16),hairset->hairs.size()*sizeof(OBJScene::Hair));
    void* hairsPtr = hairset->hairs.size() ? &hairset->hairs.front() : NULL;
    result = COIBufferCreate(hairsBytes,COI_BUFFER_STREAMING_TO_SINK,0,hairsPtr,1,&process,&buffers.hairs);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    CreateHairSetData parms;

    parms.numVertices = hairset->v.size();
    parms.numHairs    = hairset->hairs.size();
    COI_ACCESS_FLAGS flags[2] = { COI_SINK_READ, COI_SINK_READ};

    COIEVENT event;
    memset(&event,0,sizeof(event));

    /* run set scene runfunction */
    result = COIPipelineRunFunction (pipeline, runCreateHairSet, 2, &buffers.position, flags, 0, NULL, &parms, sizeof(parms), NULL, 0, &event);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
 
    result = COIEventWait(1,&event,-1,1,NULL,NULL);
    if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result)));

    /* destroy buffers again */
    result = COIBufferDestroy(buffers.position);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
    result = COIBufferDestroy(buffers.hairs);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
  }
Пример #6
0
  void render(const float time, const Vec3fa& vx, const Vec3fa& vy, const Vec3fa& vz, const Vec3fa& p)
  {
    /* set parameters for rendering */
    RenderData parms;
    parms.time = time;
    parms.vx = vx;
    parms.vy = vy;
    parms.vz = vz;
    parms.p  = p;
    parms.width = g_width;
    parms.height = g_height;
    COI_ACCESS_FLAGS flags = COI_SINK_WRITE_ENTIRE;

    COIEVENT event;
    memset(&event,0,sizeof(event));

    /* run init runfunction */
    COIRESULT result = COIPipelineRunFunction (pipeline, runRender, 1, &frameBuffer, &flags, 0, NULL, &parms, sizeof(parms), NULL, 0, &event);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));

    result = COIEventWait(1,&event,-1,1,NULL,NULL);
    if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result)));
  }
Пример #7
0
  /* set scene to use */
  void set_scene (OBJScene* scene)
  {
    COIRESULT result;
    COIBUFFER buffers[5];
    COI_ACCESS_FLAGS flags[5] = { COI_SINK_READ, COI_SINK_READ, COI_SINK_READ, COI_SINK_READ, COI_SINK_READ };

    /* send materials */
    size_t materialBytes = max(size_t(16),scene->materials.size()*sizeof(OBJScene::Material));
    void* materialPtr = scene->materials.size() ? &scene->materials.front() : NULL;
    result = COIBufferCreate(materialBytes,COI_BUFFER_STREAMING_TO_SINK,0,materialPtr,1,&process,&buffers[0]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send ambient lights */
    COIBUFFER ambientLightsBuffer;
    size_t ambientLightsBytes = max(size_t(16),scene->ambientLights.size()*sizeof(OBJScene::AmbientLight));
    void* ambientLightsPtr = scene->ambientLights.size() ? &scene->ambientLights.front() : NULL;
    result = COIBufferCreate(ambientLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,ambientLightsPtr,1,&process,&buffers[1]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send point lights */
    COIBUFFER pointLightsBuffer;
    size_t pointLightsBytes = max(size_t(16),scene->pointLights.size()*sizeof(OBJScene::PointLight));
    void* pointLightsPtr = scene->pointLights.size() ? &scene->pointLights.front() : NULL;
    result = COIBufferCreate(pointLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,pointLightsPtr,1,&process,&buffers[2]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send directional lights */
    COIBUFFER directionalLightsBuffer;
    size_t directionalLightsBytes = max(size_t(16),scene->directionalLights.size()*sizeof(OBJScene::DirectionalLight));
    void* directionalLightsPtr = scene->directionalLights.size() ? &scene->directionalLights.front() : NULL;
    result = COIBufferCreate(directionalLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,directionalLightsPtr,1,&process,&buffers[3]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    /* send distant lights */
    COIBUFFER distantLightsBuffer;
    size_t distantLightsBytes = max(size_t(16),scene->distantLights.size()*sizeof(OBJScene::DistantLight));
    void* distantLightsPtr = scene->distantLights.size() ? &scene->distantLights.front() : NULL;
    result = COIBufferCreate(distantLightsBytes,COI_BUFFER_STREAMING_TO_SINK,0,distantLightsPtr,1,&process,&buffers[4]);
    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));
    
    CreateSceneData parms;
    parms.numMaterials = scene->materials.size();
    parms.numMeshes    = scene->meshes.size();
    parms.numHairSets  = scene->hairsets.size();
    parms.numAmbientLights = scene->ambientLights.size();
    parms.numPointLights = scene->pointLights.size();
    parms.numDirectionalLights = scene->directionalLights.size();
    parms.numDistantLights = scene->distantLights.size();

#if 0
    DBG_PRINT(  scene->ambientLights.size() );
    DBG_PRINT(  scene->pointLights.size() );
    DBG_PRINT(  scene->directionalLights.size() );
    DBG_PRINT(  scene->distantLights.size() );

#endif
    COIEVENT event;
    memset(&event,0,sizeof(event));

    /* run set scene runfunction */
    result = COIPipelineRunFunction (pipeline, runCreateScene, 5, buffers, flags, 0, NULL, &parms, sizeof(parms), NULL, 0, &event);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));

    result = COIEventWait(1,&event,-1,1,NULL,NULL);
    if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result)));

    /* destroy buffers again */
    // result = COIBufferDestroy(materialBuffer);
    // if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));

    /* send all meshes */
    for (size_t i=0; i<scene->meshes.size(); i++) 
      send_mesh(scene->meshes[i]);

    /* send all hairsets */
    for (size_t i=0; i<scene->hairsets.size(); i++) 
      send_hairset(scene->hairsets[i]);
  }
Пример #8
0
  void send_mesh (OBJScene::Mesh* mesh)
  {
    COIRESULT result;
    struct {
      COIBUFFER position;      //!< vertex position array
      COIBUFFER normal;        //!< vertex normal array
      COIBUFFER texcoord;      //!< vertex texcoord array
      COIBUFFER triangle;      //!< list of triangles
    } buffers;

    assert( mesh->v.size() );
    assert( mesh->triangles.size() );

    if (mesh->vn.size() == 0)
      for (size_t i=0;i<4;i++)
	mesh->vn.push_back(Vec3f(0.0f,0.0f,0.0f));

    if (mesh->vt.size() == 0)
      for (size_t i=0;i<2;i++)
	mesh->vt.push_back(Vec2f(0.0f,0.0f));
    
    assert( mesh->vn.size() );
    assert( mesh->vt.size() );
    
    size_t positionBytes = max(size_t(16),mesh->v.size()*sizeof(Vec3fa));

    void* positionPtr = mesh->v.size() ? &mesh->v.front() : NULL;
    //result = COIBufferCreate(positionBytes,COI_BUFFER_STREAMING_TO_SINK,0,positionPtr,1,&process,&buffers.position);
    result = COIBufferCreateFromMemory(positionBytes,COI_BUFFER_NORMAL,0,positionPtr,1,&process,&buffers.position);

    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    size_t normalBytes = max(size_t(16),mesh->vn.size()*sizeof(Vec3fa));
    void* normalPtr = mesh->vn.size() ? &mesh->vn.front() : NULL;
    //result = COIBufferCreate(normalBytes,COI_BUFFER_STREAMING_TO_SINK,0,normalPtr,1,&process,&buffers.normal);
    result = COIBufferCreateFromMemory(normalBytes,COI_BUFFER_NORMAL,0,normalPtr,1,&process,&buffers.normal);

    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    size_t texcoordBytes = max(size_t(16),mesh->vt.size()*sizeof(Vec2f));
    void* texcoordPtr = mesh->vt.size() ? &mesh->vt.front() : NULL;
    //result = COIBufferCreate(texcoordBytes,COI_BUFFER_STREAMING_TO_SINK,0,texcoordPtr,1,&process,&buffers.texcoord);
    result = COIBufferCreateFromMemory(texcoordBytes,COI_BUFFER_NORMAL,0,texcoordPtr,1,&process,&buffers.texcoord);

    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    size_t triangleBytes = max(size_t(16),mesh->triangles.size()*sizeof(OBJScene::Triangle));
    void* trianglePtr = mesh->triangles.size() ? &mesh->triangles.front() : NULL;
    //result = COIBufferCreate(triangleBytes,COI_BUFFER_STREAMING_TO_SINK,0,trianglePtr,1,&process,&buffers.triangle);
    result = COIBufferCreateFromMemory(triangleBytes,COI_BUFFER_NORMAL,0,trianglePtr,1,&process,&buffers.triangle);

    if (result != COI_SUCCESS) throw std::runtime_error("COIBufferCreate failed: " + std::string(COIResultGetName(result)));

    CreateMeshData parms;
    parms.numVertices = mesh->v.size();
    parms.numTriangles = mesh->triangles.size();
    parms.dir = normalize(Vec3f(drand48(),drand48(),drand48())-Vec3f(0.5f));
    parms.offset = 5.0f*drand48();
    COI_ACCESS_FLAGS flags[4] = { COI_SINK_READ, COI_SINK_READ, COI_SINK_READ, COI_SINK_READ };

    COIEVENT event;
    memset(&event,0,sizeof(event));

    /* run set scene runfunction */
    result = COIPipelineRunFunction (pipeline, runCreateMesh, 4, &buffers.position, flags, 0, NULL, &parms, sizeof(parms), NULL, 0, &event);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
 
    result = COIEventWait(1,&event,-1,1,NULL,NULL);
    if (result != COI_SUCCESS) throw std::runtime_error("COIEventWait failed: "+std::string(COIResultGetName(result)));

    /* destroy buffers again */
    result = COIBufferDestroy(buffers.position);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
    result = COIBufferDestroy(buffers.normal);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
    result = COIBufferDestroy(buffers.texcoord);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
    result = COIBufferDestroy(buffers.triangle);
    if (result != COI_SUCCESS) throw std::runtime_error("COIPipelineRunFunction failed: "+std::string(COIResultGetName(result)));
  }