static void swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt) { struct swr_screen *screen = swr_screen(p_screen); struct swr_resource *spr = swr_resource(pt); struct pipe_context *pipe = screen->pipe; if (spr->display_target) { /* If resource is display target, winsys manages the buffer and will * free it on displaytarget_destroy. */ swr_fence_finish(p_screen, NULL, screen->flush_fence, 0); struct sw_winsys *winsys = screen->winsys; winsys->displaytarget_destroy(winsys, spr->display_target); } else { /* For regular resources, if the resource is being used, defer deletion * (use aligned-free) */ if (pipe && spr->status) { swr_resource_unused(pt); swr_fence_work_free(screen->flush_fence, spr->swr.pBaseAddress, true); swr_fence_work_free(screen->flush_fence, spr->secondary.pBaseAddress, true); } else { AlignedFree(spr->swr.pBaseAddress); AlignedFree(spr->secondary.pBaseAddress); } } FREE(spr); }
static void swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt) { struct swr_screen *screen = swr_screen(p_screen); struct swr_resource *spr = swr_resource(pt); struct pipe_context *pipe = screen->pipe; /* Only wait on fence if the resource is being used */ if (pipe && spr->status) { /* But, if there's no fence pending, submit one. * XXX: Remove once draw timestamps are implmented. */ if (!swr_is_fence_pending(screen->flush_fence)) swr_fence_submit(swr_context(pipe), screen->flush_fence); swr_fence_finish(p_screen, screen->flush_fence, 0); swr_resource_unused(pt); } /* * Free resource primary surface. If resource is display target, winsys * manages the buffer and will free it on displaytarget_destroy. */ if (spr->display_target) { /* display target */ struct sw_winsys *winsys = screen->winsys; winsys->displaytarget_destroy(winsys, spr->display_target); } else AlignedFree(spr->swr.pBaseAddress); AlignedFree(spr->secondary.pBaseAddress); FREE(spr); }
void Waifu2x_Process_Base::process_core_gray() { FLType *dstYd = nullptr, *srcYd = nullptr; // *refYd = nullptr // Get write/read pointer auto dstY = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 0)); auto srcY = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 0)); // Allocate memory for floating point Y data AlignedMalloc(dstYd, dst_pcount[0]); AlignedMalloc(srcYd, src_pcount[0]); // Convert src and ref from integer Y data to floating point Y data Int2Float(srcYd, srcY, src_height[0], src_width[0], src_stride[0], src_stride[0], false, d.para.full, false); // Execute kernel Kernel(dstYd, srcYd); // Convert dst from floating point Y data to integer Y data Float2Int(dstY, dstYd, dst_height[0], dst_width[0], dst_stride[0], dst_stride[0], false, d.para.full, !isFloat(_Ty)); // Free memory for floating point Y data AlignedFree(dstYd); AlignedFree(srcYd); }
HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9, UINT SDKVersion) { LPDIRECT3D9_INT pDirect3D9; if (ppDirect3D9 == 0) return DDERR_INVALIDPARAMS; if (AlignedAlloc((LPVOID *)&pDirect3D9, sizeof(DIRECT3D9_INT)) != S_OK) return DDERR_OUTOFMEMORY; if (pDirect3D9 == 0) return DDERR_OUTOFMEMORY; pDirect3D9->lpVtbl = &Direct3D9_Vtbl; pDirect3D9->dwProcessId = GetCurrentThreadId(); pDirect3D9->lRefCnt = 1; pDirect3D9->SDKVersion = SDKVersion; pDirect3D9->lpInt = pDirect3D9; pDirect3D9->unknown000007 = 1; InitializeCriticalSection(&pDirect3D9->d3d9_cs); if (FALSE == GetDisplayDeviceInfo(pDirect3D9)) { DPRINT1("Could not create Direct3D9 object"); AlignedFree(pDirect3D9); return DDERR_GENERIC; } *ppDirect3D9 = (LPDIRECT3D9)&pDirect3D9->lpVtbl; return D3D_OK; }
void TriangleMesh::ReallocVertexBuffer(int numTris, int vertexSizeBytes_) { AlignedFree(data); vertexSizeBytes = vertexSizeBytes_; data = (float*)AlignedMalloc(numTris * 3 * vertexSizeBytes, 32); numTriangles = numTris; }
/* alloc allocN and copy [p, p + copyN) to new p_ don't modify size_ */ void allocCopy(size_t allocN, const T *p, size_t copyN) { T *q = alloc(allocN); copy(q, p, copyN); AlignedFree(p_); p_ = q; allocSize_ = allocN; }
static int freehostmem(lua_State *L, ud_t *ud) { hostmem_t* hostmem = (hostmem_t*)ud->handle; int allocated = IsAllocated(ud); if(!freeuserdata(L, ud, "hostmem")) return 0; if(allocated) AlignedFree(hostmem->ptr); Free(L, hostmem); return 0; }
static void swr_destroy(struct pipe_context *pipe) { struct swr_context *ctx = swr_context(pipe); struct swr_screen *screen = swr_screen(pipe->screen); if (ctx->blitter) util_blitter_destroy(ctx->blitter); for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { if (ctx->framebuffer.cbufs[i]) { struct swr_resource *res = swr_resource(ctx->framebuffer.cbufs[i]->texture); /* NULL curr_pipe, so we don't have a reference to a deleted pipe */ res->curr_pipe = NULL; pipe_surface_reference(&ctx->framebuffer.cbufs[i], NULL); } } if (ctx->framebuffer.zsbuf) { struct swr_resource *res = swr_resource(ctx->framebuffer.zsbuf->texture); /* NULL curr_pipe, so we don't have a reference to a deleted pipe */ res->curr_pipe = NULL; pipe_surface_reference(&ctx->framebuffer.zsbuf, NULL); } for (unsigned i = 0; i < ARRAY_SIZE(ctx->sampler_views[0]); i++) { pipe_sampler_view_reference(&ctx->sampler_views[PIPE_SHADER_FRAGMENT][i], NULL); } for (unsigned i = 0; i < ARRAY_SIZE(ctx->sampler_views[0]); i++) { pipe_sampler_view_reference(&ctx->sampler_views[PIPE_SHADER_VERTEX][i], NULL); } if (ctx->pipe.stream_uploader) u_upload_destroy(ctx->pipe.stream_uploader); /* Idle core after destroying buffer resources, but before deleting * context. Destroying resources has potentially called StoreTiles.*/ ctx->api.pfnSwrWaitForIdle(ctx->swrContext); if (ctx->swrContext) ctx->api.pfnSwrDestroyContext(ctx->swrContext); delete ctx->blendJIT; swr_destroy_scratch_buffers(ctx); /* Only update screen->pipe if current context is being destroyed */ assert(screen); if (screen->pipe == pipe) screen->pipe = NULL; AlignedFree(ctx); }
MultilayerPerceptron::~MultilayerPerceptron() { for(uint32_t k = 0; k < _layers.size(); k++) { delete _layers[k]; } for(uint32_t k = 0; k < _activations.size(); k++) { AlignedFree(_activations[k]); } }
// Test that dynamic allocation works as expected. TEST(AlignedMemoryTest, DynamicAllocation) { void *p = AlignedAlloc(8, 8); EXPECT_TRUE(p); EXPECT_ALIGNED(p, 8); AlignedFree(p); p = AlignedAlloc(8, 16); EXPECT_TRUE(p); EXPECT_ALIGNED(p, 16); AlignedFree(p); p = AlignedAlloc(8, 256); EXPECT_TRUE(p); EXPECT_ALIGNED(p, 256); AlignedFree(p); p = AlignedAlloc(8, 4096); EXPECT_TRUE(p); EXPECT_ALIGNED(p, 4096); AlignedFree(p); }
static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9 iface) { LPDIRECT3D9_INT This = IDirect3D9ToImpl(iface); ULONG ref = InterlockedDecrement(&This->lRefCnt); if (ref == 0) { EnterCriticalSection(&This->d3d9_cs); /* TODO: Free resources here */ LeaveCriticalSection(&This->d3d9_cs); AlignedFree(This); } return ref; }
void Waifu2x_Process_Base::process_core_rgb() { FLType *dstYd = nullptr, *dstUd = nullptr, *dstVd = nullptr; FLType *srcYd = nullptr, *srcUd = nullptr, *srcVd = nullptr; // Get write/read pointer auto dstR = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 0)); auto dstG = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 1)); auto dstB = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 2)); auto srcR = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 0)); auto srcG = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 1)); auto srcB = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 2)); // Allocate memory for floating point YUV data AlignedMalloc(dstYd, dst_pcount[0]); if (d.chroma) AlignedMalloc(dstUd, dst_pcount[1]); if (d.chroma) AlignedMalloc(dstVd, dst_pcount[2]); AlignedMalloc(srcYd, src_pcount[0]); AlignedMalloc(srcUd, src_pcount[1]); AlignedMalloc(srcVd, src_pcount[2]); // Convert src and ref from RGB data to floating point YUV data RGB2FloatYUV(srcYd, srcUd, srcVd, srcR, srcG, srcB, src_height[0], src_width[0], src_stride[0], src_stride[0], d.para.matrix, d.para.full, false); // Execute kernel if (d.chroma) { Kernel(dstYd, dstUd, dstVd, srcYd, srcUd, srcVd); } else { Kernel(dstYd, srcYd); dstUd = srcUd; dstVd = srcVd; } // Convert dst from floating point YUV data to RGB data FloatYUV2RGB(dstR, dstG, dstB, dstYd, dstUd, dstVd, dst_height[0], dst_width[0], dst_stride[0], dst_stride[0], d.para.matrix, d.para.full, !isFloat(_Ty)); // Free memory for floating point YUV data AlignedFree(dstYd); if (d.chroma) AlignedFree(dstUd); if (d.chroma) AlignedFree(dstVd); AlignedFree(srcYd); AlignedFree(srcUd); AlignedFree(srcVd); }
void Waifu2x_Process_Base::process_core_yuv() { FLType *dstYd = nullptr, *dstUd = nullptr, *dstVd = nullptr; FLType *srcYd = nullptr, *srcUd = nullptr, *srcVd = nullptr; // Get write/read pointer auto dstY = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 0)); auto dstU = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 1)); auto dstV = reinterpret_cast<_Ty *>(vsapi->getWritePtr(dst, 2)); auto srcY = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 0)); auto srcU = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 1)); auto srcV = reinterpret_cast<const _Ty *>(vsapi->getReadPtr(src, 2)); // Allocate memory for floating point YUV data AlignedMalloc(dstYd, dst_pcount[0]); if (d.process[1]) AlignedMalloc(dstUd, dst_pcount[1]); if (d.process[2]) AlignedMalloc(dstVd, dst_pcount[2]); AlignedMalloc(srcYd, src_pcount[0]); if (d.process[1]) AlignedMalloc(srcUd, src_pcount[1]); if (d.process[2]) AlignedMalloc(srcVd, src_pcount[2]); // Convert src and ref from integer YUV data to floating point YUV data Int2Float(srcYd, srcY, src_height[0], src_width[0], src_stride[0], src_stride[0], false, d.para.full, false); if (d.process[1]) Int2Float(srcUd, srcU, src_height[1], src_width[1], src_stride[1], src_stride[1], true, d.para.full, false); if (d.process[2]) Int2Float(srcVd, srcV, src_height[2], src_width[2], src_stride[2], src_stride[2], true, d.para.full, false); // Execute kernel if (d.chroma) Kernel(dstYd, dstUd, dstVd, srcYd, srcUd, srcVd); else Kernel(dstYd, srcYd); // Convert dst from floating point YUV data to integer YUV data Float2Int(dstY, dstYd, dst_height[0], dst_width[0], dst_stride[0], dst_stride[0], false, d.para.full, !isFloat(_Ty)); if (d.process[1]) Float2Int(dstU, dstUd, dst_height[1], dst_width[1], dst_stride[1], dst_stride[1], true, d.para.full, !isFloat(_Ty)); if (d.process[2]) Float2Int(dstV, dstVd, dst_height[2], dst_width[2], dst_stride[2], dst_stride[2], true, d.para.full, !isFloat(_Ty)); // Free memory for floating point YUV data AlignedFree(dstYd); if (d.process[1]) AlignedFree(dstUd); if (d.process[2]) AlignedFree(dstVd); AlignedFree(srcYd); if (d.process[1]) AlignedFree(srcUd); if (d.process[2]) AlignedFree(srcVd); }
ULONG WINAPI IDirect3DDevice9Base_Release(LPDIRECT3DDEVICE9 iface) { LPDIRECT3DDEVICE9_INT This = IDirect3DDevice9ToImpl(iface); ULONG ref = InterlockedDecrement(&This->lRefCnt); if (ref == 0) { DWORD iAdapter; EnterCriticalSection(&This->CriticalSection); /* TODO: Free resources here */ for (iAdapter = 0; iAdapter < This->NumAdaptersInDevice; iAdapter++) { DestroyD3D9DeviceData(&This->DeviceData[iAdapter]); } This->lpVtbl->VirtualDestructor(iface); LeaveCriticalSection(&This->CriticalSection); AlignedFree(This); } return ref; }
~AutoArrayPtr() { AlignedFree(ptr); }
void TriangleMesh::ReallocVertexBuffer(int numTris) { AlignedFree(data); data = (float*)AlignedMalloc(numTris*3*3*sizeof(float), 32); numTriangles = numTris; }
GlyphPage::~GlyphPage() { AlignedFree(bitmap); }
~AlignedArray() { AlignedFree(p_); }
TriangleMesh::~TriangleMesh() { AlignedFree(data); }
BM3D_FilterData::BM3D_FilterData(bool wiener, double sigma, PCType GroupSize, PCType BlockSize, double lambda) : fp(GroupSize), bp(GroupSize), finalAMP(GroupSize), thrTable(wiener ? 0 : GroupSize), wienerSigmaSqr(wiener ? GroupSize : 0) { const unsigned int flags = FFTW_PATIENT; const fftw::r2r_kind fkind = FFTW_REDFT10; const fftw::r2r_kind bkind = FFTW_REDFT01; FLType *temp = nullptr; for (PCType i = 1; i <= GroupSize; ++i) { AlignedMalloc(temp, i * BlockSize * BlockSize); fp[i - 1].r2r_3d(i, BlockSize, BlockSize, temp, temp, fkind, fkind, fkind, flags); bp[i - 1].r2r_3d(i, BlockSize, BlockSize, temp, temp, bkind, bkind, bkind, flags); AlignedFree(temp); finalAMP[i - 1] = 2 * i * 2 * BlockSize * 2 * BlockSize; double forwardAMP = sqrt(finalAMP[i - 1]); if (wiener) { wienerSigmaSqr[i - 1] = static_cast<FLType>(sigma * forwardAMP * sigma * forwardAMP); } else { double thrBase = sigma * lambda * forwardAMP; std::vector<double> thr(4); thr[0] = thrBase; thr[1] = thrBase * sqrt(double(2)); thr[2] = thrBase * double(2); thr[3] = thrBase * sqrt(double(8)); FLType *thrp = nullptr; AlignedMalloc(thrp, i * BlockSize * BlockSize); thrTable[i - 1].reset(thrp, [](FLType *memory) { AlignedFree(memory); }); for (PCType z = 0; z < i; ++z) { for (PCType y = 0; y < BlockSize; ++y) { for (PCType x = 0; x < BlockSize; ++x, ++thrp) { int flag = 0; if (x == 0) { ++flag; } if (y == 0) { ++flag; } if (z == 0) { ++flag; } *thrp = static_cast<FLType>(thr[flag]); } } } } } }