int Lucas::fft_setup (int length) { clAmdFftSetupData fftSetupData; OPENCL_V_THROW(clAmdFftInitSetupData (&fftSetupData),"Failed to clAmdFftInitSetupData."); fftSetupData.debugFlags = CLFFT_DUMP_PROGRAMS; // Dumps the FFT kernels // Setup the AMD FFT library. OPENCL_V_THROW(clAmdFftSetup (&fftSetupData),"Failed to clAmdFftSetup."); // Create FFT Plan const size_t logicalDimensions[1] = { length }; // Create default plan. OPENCL_V_THROW(clAmdFftCreateDefaultPlan(&plan, context(), CLFFT_1D, logicalDimensions),"Failed to clAmdFftCreateDefaultPlan."); // Set double precision. OPENCL_V_THROW(clAmdFftSetPlanPrecision(plan, CLFFT_DOUBLE),"Failed to clAmdFftSetPlanPrecision."); // Set layout. OPENCL_V_THROW(clAmdFftSetLayout(plan, CLFFT_COMPLEX_INTERLEAVED,CLFFT_COMPLEX_INTERLEAVED),"Failed to clAmdFftSetLayout."); // Normalize forward transformation. OPENCL_V_THROW(clAmdFftSetPlanScale(plan, CLFFT_FORWARD, 1.0f/static_cast<cl_float>(length)),"Failed to clAmdFftSetPlanScale."); // Normalize backward transformation. OPENCL_V_THROW(clAmdFftSetPlanScale(plan, CLFFT_BACKWARD, 1.0f),"Failed to clAmdFftSetPlanScale."); // In-place FFT. OPENCL_V_THROW(clAmdFftSetResultLocation(plan, CLFFT_INPLACE),"Failed to clAmdFftSetResultLocation."); // Set number of transformations per plan. OPENCL_V_THROW(clAmdFftSetPlanBatchSize(plan, 1),"Failed to clAmdFftSetPlanBatchSize."); // BakePlan OPENCL_V_THROW(clAmdFftBakePlan(plan, 1, &commandQueue(), NULL, NULL),"Failed to clAmdFftBakePlan."); }
/*! Releases access to the OpenGL object behind the OpenCL memory object \a mem. This function must be called after performing an OpenCL operation on any OpenGL memory object, and before performing OpenGL operations on the object. Returns an event object that can be used to wait for the request to finish. The request is executed on the active command queue for this context. \sa acquire() */ QCLEvent QCLContextGL::release(const QCLMemoryObject &mem) { #ifndef QT_NO_CL_OPENGL cl_event event; cl_mem id = mem.memoryId(); cl_int error = clEnqueueReleaseGLObjects (commandQueue().queueId(), 1, &id, 0, 0, &event); reportError("QCLContextGL::release:", error); if (error == CL_SUCCESS) return QCLEvent(event); else return QCLEvent(); #else Q_UNUSED(mem); return QCLEvent(); #endif }
virtual void getVelocities(std::vector<Point> &velocities) { /* * This function should only retrieve the internal velocity buffer. * It does not have to be implemented efficiently, since its working * time is not added to total measured time. */ cl_int err; const cl::Device &dev = mDevices->at(0); cl::Context context = *mContext; cl::CommandQueue commandQueue(context, dev, 0, &err); Point *vels = new Point[mPointCount]; err = commandQueue.enqueueReadBuffer(mVelocities, CL_TRUE, 0, sizeof(Point)*mPointCount, vels); velocities.clear(); std::vector<Point> tmp(vels, vels + mPointCount); velocities.assign(tmp.begin(), tmp.end()); }
/*! \overload Acquires access to the OpenGL object behind the OpenCL memory object \a mem. This function must be called before performing an OpenCL operation on any OpenGL memory object. The request will not start until all of the events in \a after have been signaled as finished. Returns an event object that can be used to wait for the request to finish. The request is executed on the active command queue for this context. \sa release() */ QCLEvent QCLContextGL::acquire (const QCLMemoryObject &mem, const QCLEventList &after) { #ifndef QT_NO_CL_OPENGL cl_event event; cl_mem id = mem.memoryId(); cl_int error = clEnqueueAcquireGLObjects (commandQueue().queueId(), 1, &id, after.size(), after.eventData(), &event); reportError("QCLContextGL::acquire(after):", error); if (error == CL_SUCCESS) return QCLEvent(event); else return QCLEvent(); #else Q_UNUSED(mem); Q_UNUSED(after); return QCLEvent(); #endif }
virtual void iteration(std::vector<Point> &points) { /* * The main function that computes next version of the point locations * and updates internal velocities. */ cl_int err; const cl::Device &dev = mDevices->at(0); cl::Context context = *mContext; cl::CommandQueue commandQueue(context, dev, 0, &err); commandQueue.enqueueWriteBuffer(mPoints, CL_TRUE, 0, sizeof(Point)*mPointCount, points.data()); cl::Kernel &kernel = mKernels->at("iteration"); commandQueue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(mPointCount), cl::NDRange(256), NULL, NULL); commandQueue.finish(); err = commandQueue.enqueueReadBuffer(mPoints, CL_TRUE, 0, sizeof(Point)*mPointCount, points.data()); commandQueue.finish(); }
void Window::paintD3D() { commandAllocator()->Reset(); commandList->Reset(commandAllocator(), Q_NULLPTR); transitionResource(backBufferRenderTarget(), commandList.Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET); green += 0.01f; if (green > 1.0f) green = 0.0f; const float clearColor[] = { 0.0f, green, 0.0f, 1.0f }; commandList->ClearRenderTargetView(backBufferRenderTargetCPUHandle(), clearColor, 0, Q_NULLPTR); transitionResource(backBufferRenderTarget(), commandList.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT); commandList->Close(); ID3D12CommandList *commandLists[] = { commandList.Get() }; commandQueue()->ExecuteCommandLists(_countof(commandLists), commandLists); update(); // schedule the next frame by posting an UpdateRequest event }
static void set_sweep( uint8_t * args ) { (void)args; OutputQueue * q = commandQueue(); chOQPut( q, TSWEEP ); }
static void set_meandr( uint8_t * args ) { (void)args; OutputQueue * q = commandQueue(); chOQPut( q, TMEANDR ); }
static void set_one_pulse( uint8_t * args ) { (void)args; OutputQueue * q = commandQueue(); chOQPut( q, TONEPULSE ); }
static void set_dac( uint8_t * args ) { (void)args; OutputQueue * q = commandQueue(); chOQPut( q, TDAC ); }
QImage QD3D12Window::readbackRGBA8888(ID3D12Resource *rt, D3D12_RESOURCE_STATES rtState, ID3D12GraphicsCommandList *commandList) { ComPtr<ID3D12Resource> readbackBuf; D3D12_RESOURCE_DESC rtDesc = rt->GetDesc(); UINT64 textureByteSize = 0; D3D12_PLACED_SUBRESOURCE_FOOTPRINT textureLayout = {}; device()->GetCopyableFootprints(&rtDesc, 0, 1, 0, &textureLayout, Q_NULLPTR, Q_NULLPTR, &textureByteSize); D3D12_HEAP_PROPERTIES heapProp = {}; heapProp.Type = D3D12_HEAP_TYPE_READBACK; D3D12_RESOURCE_DESC bufDesc = {}; bufDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; bufDesc.Width = textureByteSize; bufDesc.Height = 1; bufDesc.DepthOrArraySize = 1; bufDesc.MipLevels = 1; bufDesc.Format = DXGI_FORMAT_UNKNOWN; bufDesc.SampleDesc.Count = 1; bufDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; if (FAILED(device()->CreateCommittedResource(&heapProp, D3D12_HEAP_FLAG_NONE, &bufDesc, D3D12_RESOURCE_STATE_COPY_DEST, Q_NULLPTR, IID_PPV_ARGS(&readbackBuf)))) { qWarning("Failed to create committed resource (readback buffer)"); return QImage(); } D3D12_TEXTURE_COPY_LOCATION dstLoc; dstLoc.pResource = readbackBuf.Get(); dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; dstLoc.PlacedFootprint = textureLayout; D3D12_TEXTURE_COPY_LOCATION srcLoc; srcLoc.pResource = rt; srcLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; srcLoc.SubresourceIndex = 0; transitionResource(rt, commandList, rtState, D3D12_RESOURCE_STATE_COPY_SOURCE); commandList->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, Q_NULLPTR); transitionResource(rt, commandList, D3D12_RESOURCE_STATE_COPY_SOURCE, rtState); commandList->Close(); ID3D12CommandList *commandLists[] = { commandList }; commandQueue()->ExecuteCommandLists(_countof(commandLists), commandLists); QScopedPointer<Fence> f(createFence()); waitForGPU(f.data()); QImage img(rtDesc.Width, rtDesc.Height, QImage::Format_RGBA8888); quint8 *p = Q_NULLPTR; D3D12_RANGE readRange = { 0, 0 }; if (FAILED(readbackBuf->Map(0, &readRange, reinterpret_cast<void **>(&p)))) { qWarning("Mapping the readback buffer failed"); return QImage(); } for (UINT y = 0; y < rtDesc.Height; ++y) { quint8 *dst = img.scanLine(y); memcpy(dst, p, rtDesc.Width * 4); p += textureLayout.Footprint.RowPitch; } readbackBuf->Unmap(0, Q_NULLPTR); return img; }