bool TriangleIterator::Advance() { if (m_currentIndex >= m_indexCount) { Unmap(); return false; } switch (m_primitiveMode) { case PrimitiveMode_TriangleFan: m_triangleIndices[1] = m_indexMapper.Get(m_currentIndex++); m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++); break; case PrimitiveMode_TriangleList: m_triangleIndices[0] = m_indexMapper.Get(m_currentIndex++); m_triangleIndices[1] = m_indexMapper.Get(m_currentIndex++); m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++); break; case PrimitiveMode_TriangleStrip: m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++); m_triangleIndices[0] = m_triangleIndices[1]; m_triangleIndices[1] = m_triangleIndices[2]; break; default: return false; } return true; }
void Line::SetLines(const std::vector<XMVECTOR> &l) { if (l.size() == lines.size()) { for (int i = 0; i < lines.size(); i++) lines[i] = { { to2(l[i]) }, { 1.0, 1.0, 1.0, 1.0 } }; // updating vertex buffer auto dc = dx->deviceContext; D3D11_MAPPED_SUBRESOURCE ms; ZeroMemory(&ms, sizeof(ms)); Debug::if_failed( dc->Map(vertexBuffer, 0, D3D11_MAP_WRITE, 0, &ms), "error mapping subresource"); memcpy(ms.pData, lines.data(), lines.size()*sizeof(ColVertex)); dc->Unmap(vertexBuffer, 0); } else { ostringstream o; o << "invalid lines count in SetLines argument\n" << "argument vector: " << l.size() << "\nlines vector: " << lines.size(); Debug::message(o.str()); } }
void SpriteBase::OnUpdate() { float ElapsedTime = App::GetApp()->GetElapsedTime(); auto Dev = App::GetApp()->GetDeviceResources(); auto pD3D11DeviceContext = Dev->GetD3DDeviceContext(); //頂点の変更 //D3D11_MAP_WRITE_DISCARDは重要。この処理により、GPUに邪魔されない D3D11_MAP mapType = D3D11_MAP_WRITE_DISCARD; D3D11_MAPPED_SUBRESOURCE mappedBuffer; //頂点のマップ if (FAILED(pD3D11DeviceContext->Map(m_SquareMesh->GetVertexBuffer().Get(), 0, mapType, 0, &mappedBuffer))) { // Map失敗 throw BaseException( L"頂点のMapに失敗しました。", L"if(FAILED(pID3D11DeviceContext->Map()))", L"WrappedSprite::UpdateVertex()" ); } //頂点の変更 VertexPositionColorTexture* vertices = (VertexPositionColorTexture*)mappedBuffer.pData; //仮想関数呼び出し UpdateVertex(ElapsedTime, vertices); //アンマップ pD3D11DeviceContext->Unmap(m_SquareMesh->GetVertexBuffer().Get(), 0); }
MappedFile::~MappedFile() { if (IsMapped()) { Unmap(); } } // MappedFile::~MappedFile
bool OpenGLBuffer::SetData( void* pData ) { void* pMappedData = Map(); memcpy( pMappedData, pData, data_size ); Unmap(); return true; }
bool SharedBufferMLGPU::GrowBuffer(size_t aBytes) { // We only pre-allocate buffers if we can use offset allocation. MOZ_ASSERT(mCanUseOffsetAllocation); // Unmap the previous buffer. This will retain mBuffer, but free up the // address space used by its mapping. Unmap(); size_t maybeSize = mDefaultSize; if (mBuffer) { // Try to first grow the previous allocation size. maybeSize = std::min(kMaxCachedBufferSize, mBuffer->GetSize() * 2); } size_t bytes = std::max(aBytes, maybeSize); mBuffer = mDevice->CreateBuffer(mType, bytes, MLGUsage::Dynamic); if (!mBuffer) { return false; } mCurrentPosition = 0; mMaxSize = mBuffer->GetSize(); return true; }
StagingTexture2DBuffer::~StagingTexture2DBuffer() { if (m_map_pointer) Unmap(); g_command_buffer_mgr->DeferDeviceMemoryDestruction(m_memory); g_command_buffer_mgr->DeferBufferDestruction(m_buffer); }
void Scene::Remove(Interactor* i) { DoRemove(i); i->parent = nil; if (i->canvas != nil) { Unmap(i); i->Orphan(); } }
StagingTexture2DLinear::~StagingTexture2DLinear() { if (m_map_pointer) Unmap(); g_command_buffer_mgr->DeferDeviceMemoryDestruction(m_memory); g_command_buffer_mgr->DeferImageDestruction(m_image); }
void SharedBufferMLGPU::PrepareForUsage() { Unmap(); if (mBytesUsedThisFrame <= mDefaultSize) { mNumSmallFrames++; } else { mNumSmallFrames = 0; } }
void Texture::setData(const uint8_t *in_pData) { auto pDeviceContext = ORenderer->getDeviceContext(); D3D11_MAPPED_SUBRESOURCE data; pDeviceContext->Map(m_pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &data); memcpy(data.pData, in_pData, m_size.x * m_size.y * 4); pDeviceContext->Unmap(m_pTexture, 0); }
void OsdCudaVertexBuffer::UpdateData(const float *src, int numVertices) { void *dst = Map(); cudaMemcpy(dst, src, _numElements * numVertices * sizeof(float), cudaMemcpyHostToDevice); Unmap(); h_data = std::vector<float>(src, src +( _numElements*numVertices)); }
void CMemStream::Close() { n_assert(IsOpen()); if (IsMapped()) Unmap(); if (SelfAlloc && pBuffer) n_free(pBuffer); pBuffer = NULL; Flags.Clear(IS_OPEN); //CStream::Close(); }
void Scene::Remove (Interactor* i) { DoRemove(i); i->parent = nil; if (i->canvas != nil) { Unmap(i); if (i->GetInteractorType() != InteriorInteractor) { i->Deactivate(); } Orphan(i); } }
bool MappedFile::Map( const char* fileName, int startPage, int nBytes ) { if (m_hMapping != INVALID_HANDLE_VALUE) { Unmap(); } m_hFile = CreateFile( fileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if (m_hFile == INVALID_HANDLE_VALUE) { rlog.err( "Could not open file for mapping: %s", fileName ); return false; } m_FileSize = ::GetFileSize( m_hFile, NULL ); // create mapping name char mapName[_MAX_PATH]; strcpy( mapName, fileName ); char* pName = mapName; while (*pName) { if (*pName == '\\' || *pName == '/') *pName = '_'; pName++; } m_hMapping = CreateFileMapping( m_hFile, NULL, PAGE_READONLY, 0, 0, mapName ); uint32_t err = GetLastError(); if (m_hMapping == NULL) { rlog.err( "Could not memory-map file: %s", fileName ); m_hMapping = INVALID_HANDLE_VALUE; return false; } m_pBuffer = (uint8_t*)MapViewOfFile( m_hMapping, FILE_MAP_READ, 0, startPage*GetPageSize(), nBytes ); if (m_pBuffer == NULL) { uint32_t errCode = GetLastError(); rlog.err( "Could not memory-map view of file: %s. Error code: %X", fileName ); return false; } CloseHandle( m_hFile ); m_hFile = INVALID_HANDLE_VALUE; m_MappedSize = nBytes; m_FirstMappedPage = startPage; return true; } // MappedFile::Map
void SimpleSquare::OnUpdate() { float ElapsedTime = App::GetApp()->GetElapsedTime(); auto Dev = App::GetApp()->GetDeviceResources(); auto pD3D11DeviceContext = Dev->GetD3DDeviceContext(); //頂点の変更 //D3D11_MAP_WRITE_DISCARDは重要。この処理により、GPUに邪魔されない D3D11_MAP mapType = D3D11_MAP_WRITE_DISCARD; D3D11_MAPPED_SUBRESOURCE mappedBuffer; //頂点のマップ if (FAILED(pD3D11DeviceContext->Map(m_SquareMesh->GetVertexBuffer().Get(), 0, mapType, 0, &mappedBuffer))) { // Map失敗 throw BaseException( L"頂点のMapに失敗しました。", L"if(FAILED(pID3D11DeviceContext->Map()))", L"SimpleSquare::OnUpdate()" ); } //頂点の変更 VertexPositionColorTexture* vertices = (VertexPositionColorTexture*)mappedBuffer.pData; //関数呼び出し UpdateVertex(ElapsedTime, vertices); //アンマップ pD3D11DeviceContext->Unmap(m_SquareMesh->GetVertexBuffer().Get(), 0); auto PtrStage = GetStage<Stage>(); //カメラの位置 Vec3 CameraEye = PtrStage->GetCamera().m_CamerEye; Vec3 CameraAt = PtrStage->GetCamera().m_CamerAt; switch (m_DrawOption) { case SquareDrawOption::Billboard: { m_Qt.facing(CameraAt - CameraEye); } break; case SquareDrawOption::Faceing: { m_Qt.facing(m_Pos - CameraEye); } break; case SquareDrawOption::FaceingY: m_Qt.facingY(m_Pos - CameraEye); break; default: m_Qt.normalize(); break; } }
void VertexBuffer::CloneTo(VertexBuffer &vb) const { if (GLEW_ARB_vertex_buffer_object) { BYTE *data = (BYTE *)Map(GL_READ_ONLY); if (data) { vb.SetData(GetSize(), data, GetUsage()); Unmap(); } } else { delete [] vb.ptr->data; vb.ptr->size = ptr->size; vb.ptr->data = new BYTE[ptr->size]; memcpy(vb.ptr->data, ptr->data, ptr->size); } }
void SharedBufferMLGPU::Reset() { // We shouldn't be mapped here, but just in case, unmap now. Unmap(); mBytesUsedThisFrame = 0; // If we allocated a large buffer for a particularly heavy layer tree, // but have not used most of the buffer again for many frames, we // discard the buffer. This is to prevent having to perform large // pointless uploads after visiting a single havy page - it also // lessens ping-ponging between large and small buffers. if (mBuffer && (mBuffer->GetSize() > mDefaultSize * 4) && mNumSmallFrames >= 10) { mBuffer = nullptr; } // Note that we do not aggressively map a new buffer. There's no reason to, // and it'd cause unnecessary uploads when painting empty frames. }
const VertexBuffer* DecorationMap::GetVB(RenderContext* rc, uint32_t& vertCount) { vertCount = 0; GenVBuffers(); if(m_vertexcount == 0) return NULL; auto d3dcontext = rc->Context(); vertCount = 0; if( m_decoDynVB == NULL || m_decoDynVB->GetCount() < m_vertexcount) { SAFE_DELETE(m_decoDynVB); m_decoDynVB = GpuResourceFactory::CreateVertexBuffer(NULL, VertexFormat::VF_T, m_vertexcount,BufferUsage::DYNAMIC); assert(m_decoDynVB); } if(!m_decoDynVB) return NULL; D3D11_MAPPED_SUBRESOURCE mappedResource; const TerrainPatchList& patchlist = this->GetParent()->GetVisiblePatches(); HRESULT hr = d3dcontext->Map(m_decoDynVB->GetBuffer(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); if(FAILED(hr)) return NULL; // update dynamic instance buffer // for each visible terrain patch. for(auto it = patchlist.begin(); it != patchlist.end(); it++) { const VBList* pos2d = &m_listOfVBList[it->patchId]; float dist = length( it->bounds.GetCenter() - rc->Cam().CamPos()); if( dist > m_lodDistance || pos2d->size() == 0) continue; // update instance buffer. uint8_t* destPtr = ( (uint8_t*)mappedResource.pData + (vertCount * m_decoDynVB->GetStride())); CopyMemory(destPtr, &pos2d->front(), m_decoDynVB->GetStride() * pos2d->size()); vertCount += (uint32_t)pos2d->size(); } d3dcontext->Unmap(m_decoDynVB->GetBuffer(), 0); return m_decoDynVB; }
/** * \brief Reads data from the buffer and copies it at the destination. */ void KT_API D3D11HardwareBuffer::ReadData( D3D11ImmediateContext* ctx, Uint32 offset, Uint32 size, void* dest ) { if( (myCPUAccessRights & kT::D3D11HardwareBuffer::CPUReadAccess) != 0 ) { memcpy( dest, Map( ctx, kT::D3D11HardwareBuffer::ReadLock, offset, size ), size ); Unmap( ctx ); } else { D3D11HardwareBuffer* copy = GetBufferCopy(ctx); memcpy( dest, copy->Map( ctx, D3D11HardwareBuffer::ReadLock, offset, size ), size ); copy->Unmap( ctx ); delete copy; } }
/** Updates the vertexbuffer with the given data */ XRESULT D3D11VertexBuffer::UpdateBufferAligned16(void* data, UINT size) { void* mappedData; UINT bsize; if (XR_SUCCESS == Map(EMapFlags::M_WRITE_DISCARD, &mappedData, &bsize)) { if (size) bsize = size; // Copy data //Toolbox::X_aligned_memcpy_sse2(mappedData, data, bsize); memcpy(mappedData, data, bsize); Unmap(); return XR_SUCCESS; } return XR_FAILED; }
/// @brief Lock vertex buffer. /// /// @param _nIndex Index of the vertex buffer. /// @param _pBuffer Vertex buffer. /// @param _nSize Size to write. /// /// @return True if it mapped successfully. bool CVertexBuffer::MapWrite(uint32 _nIndex, void *_pBuffer, uint32 _nSize) { SAM_ASSERT(_pBuffer != NULL, "Buffer is null"); SAM_ASSERT(_nIndex < m_nNbVertices, "Index is out of range"); // Lock the vertex buffer. D3D11_MAPPED_SUBRESOURCE subressource; ZeroMemory(&subressource, sizeof(D3D11_MAPPED_SUBRESOURCE)); HRESULT hResult = g_Env->pRenderWindow->GetD3DContext()->Map(m_pBuffer, _nIndex, GetDX11Map(VU_Write_Only), 0, &subressource); if(hResult != S_OK) { g_Env->pRenderWindow->LogError(hResult); return false; } memcpy(subressource.pData, _pBuffer, _nSize); Unmap(); return true; }
VOID Mesh::DataTable::Iterate(Func F, UINT Offset, U& P0, V& P1) { MapView(PageAccess::READWRITE); UINT Stride = m_pHeader->ElementSize; LPBYTE pData = (LPBYTE)m_pData + Offset; UINT j = 0; for (UINT i=0; i<m_pHeader->Count; i++, pData+=Stride) { F(i, *(T*)pData, P0, P1); if (i - j > 1048576) { Unlock(j, i - j - 65536); j = i-65536; } } Unmap(); }
int SkyBox::Render() { HRESULT hr; auto gfx = (ContextD3D11*)context_; auto pd3dImmediateContext = gfx->device_context(); context_->SetInputLayout(il_); UINT uStrides = sizeof( SkyBoxVertex ); UINT uOffsets = 0; context_->SetVertexBuffers( 0, 1, (const void**)&sky_vb_, &uStrides, &uOffsets ); context_->SetIndexBuffer(nullptr,DXGI_FORMAT_R32_UINT,0); context_->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); context_->PushVertexShader(&sky_vs_); context_->PushPixelShader(&sky_ps_); D3D11_MAPPED_SUBRESOURCE MappedResource; pd3dImmediateContext->Map( m_pcbVSPerObject, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) ; CB_VS_PER_OBJECT* pVSPerObject = ( CB_VS_PER_OBJECT* )MappedResource.pData; pmWorldViewProj = world()*dx::XMMatrixMultiply(scene_->camera()->view(),scene_->camera()->projection()); pVSPerObject->m_WorldViewProj = dx::XMMatrixTranspose(dx::XMMatrixInverse(NULL, pmWorldViewProj )); pd3dImmediateContext->Unmap( m_pcbVSPerObject, 0 ); pd3dImmediateContext->VSSetConstantBuffers( 0, 1, &m_pcbVSPerObject ); pd3dImmediateContext->PSSetSamplers( 0, 1, &sampler_state ); pd3dImmediateContext->PSSetShaderResources( 0, 1, (ID3D11ShaderResourceView*const*)&sky_trv_.data_pointer ); ID3D11DepthStencilState* pDepthStencilStateStored11 = NULL; UINT StencilRef; pd3dImmediateContext->OMGetDepthStencilState( &pDepthStencilStateStored11, &StencilRef ); pd3dImmediateContext->OMSetDepthStencilState( sky_depth_state_, 0 ); pd3dImmediateContext->Draw( 4, 0 ); pd3dImmediateContext->OMSetDepthStencilState( pDepthStencilStateStored11, StencilRef ); context_->PopVertexShader(); context_->PopPixelShader(); return S_OK; }
void overlay::set_dimensions(int start_x, int start_y, int width, int height, int window_width, int window_height) { float left = static_cast<float>(window_width) / -2.0f + static_cast<float>(start_x); float right = left + static_cast<float>(width); float top = static_cast<float>(window_height) / 2.0f - static_cast<float>(start_y); float bottom = top - static_cast<float>(height); const uint32_t count = 6; std::array<overlay::vertex_t, count> vertices; vertices[0].position = float3(left, top, 0.0f); vertices[0].texture = float2(0.0f, 0.0f); vertices[1].position = float3(right, bottom, 0.0f); vertices[1].texture = float2(1.0f, 1.0f); vertices[2].position = float3(left, bottom, 0.0f); vertices[2].texture = float2(0.0f, 1.0f); vertices[3].position = float3(left, top, 0.0f); vertices[3].texture = float2(0.0f, 0.0f); vertices[4].position = float3(right, top, 0.0f); vertices[4].texture = float2(1.0f, 0.0f); vertices[5].position = float3(right, bottom, 0.0f); vertices[5].texture = float2(1.0f, 1.0f); auto context = d3d_device::instance()->get_context(); D3D11_MAPPED_SUBRESOURCE mapped_data; context->Map(vertex_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_data); auto vertices_ptr = reinterpret_cast<overlay::vertex_t*>(mapped_data.pData); memcpy(vertices_ptr, reinterpret_cast<void*>(vertices.data()), sizeof(overlay::vertex_t) * count); context->Unmap(vertex_buffer.Get(), 0); }
/** Updates the vertexbuffer with the given data */ XRESULT D3D11VertexBuffer::UpdateBuffer(void* data, UINT size) { void* mappedData; UINT bsize; if(SizeInBytes < size) size = SizeInBytes; if (XR_SUCCESS == Map(EMapFlags::M_WRITE_DISCARD, &mappedData, &bsize)) { if (size) bsize = size; // Copy data memcpy(mappedData, data, bsize); Unmap(); return XR_SUCCESS; } return XR_FAILED; }
bool GSTextureSW::Update(const GSVector4i& r, const void* data, int pitch) { GSMap m; if(m_data != NULL && Map(m, &r)) { uint8* RESTRICT src = (uint8*)data; uint8* RESTRICT dst = m.bits; int rowbytes = r.width() << 2; for(int h = r.height(); h > 0; h--, src += pitch, dst += m.pitch) { memcpy(dst, src, rowbytes); } Unmap(); return true; } return false; }
void VulkanPushBuffer::NextBuffer(size_t minSize) { // First, unmap the current memory. Unmap(); buf_++; if (buf_ >= buffers_.size() || minSize > size_) { // Before creating the buffer, adjust to the new size_ if necessary. while (size_ < minSize) { size_ <<= 1; } bool res = AddBuffer(); assert(res); if (!res) { // Let's try not to crash at least? buf_ = 0; } } // Now, move to the next buffer and map it. offset_ = 0; Map(); }
SharedMemoryBasic::~SharedMemoryBasic() { Unmap(); Destroy(); }
//----------------------------------------------------------------------------- void CPUTMeshDX11::UnmapIndices( CPUTRenderParameters ¶ms ) { Unmap( mpIndexBuffer, mpStagingIndexBuffer, &mIndexBufferMappedType, params ); }