static CALresult createConstantBuffer2D(MWMemRes* mr,
                                        MWCALInfo* ci,
                                        const CALdouble* dataPtr,
                                        CALformat format,
                                        CALboolean linearBuffer,
                                        CALuint width,
                                        CALuint height)
{
    CALresult err;
    CALuint flags = linearBuffer ? CAL_RESALLOC_GLOBAL_BUFFER : 0;

    err = calResAllocLocal2D(&mr->res, ci->dev, width, height, format, flags);
    if (err != CAL_RESULT_OK)
    {
        cal_warn("Failed to create 2D constant resource", err);
        releaseMWMemRes(ci->calctx, mr);
        return err;
    }

    err = writeConstantBufferDouble(mr, dataPtr, formatToNumElements(format), width, height);
    if (err != CAL_RESULT_OK)
        return err;

    err = getMemoryHandle(mr, ci);
    if (err != CAL_RESULT_OK)
        return err;

    return CAL_RESULT_OK;
}
/* Output appropriate for width * height real1 elements */
static CALresult createOutputBuffer2D(MWMemRes* mr, MWCALInfo* ci, CALuint width, CALuint height)
{
    CALresult err;
    CALuint flags = 0;
    //CALuint flags = CAL_RESALLOC_GLOBAL_BUFFER;

    err = calResAllocLocal2D(&mr->res, ci->dev, width, height, formatReal2, flags);
    if (err != CAL_RESULT_OK)
    {
        cal_warn("Failed to create output resource", err);
        releaseMWMemRes(ci->calctx, mr);
        return err;
    }

    err = zeroBuffer(mr, 2, width, height);
    if (err != CAL_RESULT_OK)
    {
        cal_warn("Failed to zero output buffer", err);
        return err;
    }

    /* Get the handle for the context */
    err = getMemoryHandle(mr, ci);
    if (err != CAL_RESULT_OK)
    {
        cal_warn("Failed to create handle for output buffer", err);
        return err;
    }

    return CAL_RESULT_OK;
}
Пример #3
0
CALresource* CalDevice::resAllocLocal2D(int width, int height,
                                        CALformat format, CALuint flags)
{
    CALresource newRes;
    if(calResAllocLocal2D(&newRes, mDevice, width, height, format, flags)
            != CAL_RESULT_OK) {
        fprintf(stderr, "ERROR: Could allocate 2D resource.\n");
        return NULL;
    }

    /* TODO: threadsafe */
    mResources.push_front(newRes);
    CALresource* pRes = &*(mResources.begin());
    mRefs[pRes] = 1;
    mOwners[pRes] = this;
    return pRes;
}