bool Image11::redefine(RendererD3D *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease) { if (mWidth != width || mHeight != height || mInternalFormat != internalformat || forceRelease) { // End the association with the TextureStorage, since that data will be out of date. // Also reset mRecoveredFromStorageCount since this Image is getting completely redefined. disassociateStorage(); mRecoveredFromStorageCount = 0; mRenderer = Renderer11::makeRenderer11(renderer); mWidth = width; mHeight = height; mDepth = depth; mInternalFormat = internalformat; mTarget = target; // compute the d3d format that will be used const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat); const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(formatInfo.texFormat); mDXGIFormat = formatInfo.texFormat; mActualFormat = dxgiFormatInfo.internalFormat; mRenderable = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN); releaseStagingTexture(); mDirty = (formatInfo.dataInitializerFunction != NULL); return true; } return false; }
bool Image11::redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease) { if (mWidth != size.width || mHeight != size.height || mInternalFormat != internalformat || forceRelease) { // End the association with the TextureStorage, since that data will be out of date. // Also reset mRecoveredFromStorageCount since this Image is getting completely redefined. disassociateStorage(); mRecoveredFromStorageCount = 0; mWidth = size.width; mHeight = size.height; mDepth = size.depth; mInternalFormat = internalformat; mTarget = target; // compute the d3d format that will be used const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalformat, mRenderer->getRenderer11DeviceCaps()); mDXGIFormat = formatInfo.formatSet->texFormat; mRenderable = (formatInfo.formatSet->rtvFormat != DXGI_FORMAT_UNKNOWN); releaseStagingTexture(); mDirty = (formatInfo.dataInitializerFunction != NULL); return true; } return false; }
gl::Error Image11::copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box ®ion) { TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(storage); // If an app's behavior results in an Image11 copying its data to/from to a TextureStorage multiple times, // then we should just keep the staging texture around to prevent the copying from impacting perf. // We allow the Image11 to copy its data to/from TextureStorage once. // This accounts for an app making a late call to glGenerateMipmap. bool attemptToReleaseStagingTexture = (mRecoveredFromStorageCount < 2); if (attemptToReleaseStagingTexture) { // If another image is relying on this Storage for its data, then we must let it recover its data before we overwrite it. gl::Error error = storage11->releaseAssociatedImage(index, this); if (error.isError()) { return error; } } ID3D11Resource *stagingTexture = NULL; unsigned int stagingSubresourceIndex = 0; gl::Error error = getStagingTexture(&stagingTexture, &stagingSubresourceIndex); if (error.isError()) { return error; } error = storage11->updateSubresourceLevel(stagingTexture, stagingSubresourceIndex, index, region); if (error.isError()) { return error; } // Once the image data has been copied into the Storage, we can release it locally. if (attemptToReleaseStagingTexture) { storage11->associateImage(this, index); releaseStagingTexture(); mRecoverFromStorage = true; mAssociatedStorage = storage11; mAssociatedImageIndex = index; } return gl::Error(GL_NO_ERROR); }
gl::Error Image11::copyToStorage(const gl::Context *context, TextureStorage *storage, const gl::ImageIndex &index, const gl::Box ®ion) { TextureStorage11 *storage11 = GetAs<TextureStorage11>(storage); // If an app's behavior results in an Image11 copying its data to/from to a TextureStorage // multiple times, then we should just keep the staging texture around to prevent the copying // from impacting perf. We allow the Image11 to copy its data to/from TextureStorage once. This // accounts for an app making a late call to glGenerateMipmap. bool attemptToReleaseStagingTexture = (mRecoveredFromStorageCount < 2); if (attemptToReleaseStagingTexture) { // If another image is relying on this Storage for its data, then we must let it recover its // data before we overwrite it. ANGLE_TRY(storage11->releaseAssociatedImage(context, index, this)); } const TextureHelper11 *stagingTexture = nullptr; unsigned int stagingSubresourceIndex = 0; ANGLE_TRY(getStagingTexture(&stagingTexture, &stagingSubresourceIndex)); ANGLE_TRY(storage11->updateSubresourceLevel(context, *stagingTexture, stagingSubresourceIndex, index, region)); // Once the image data has been copied into the Storage, we can release it locally. if (attemptToReleaseStagingTexture) { storage11->associateImage(this, index); releaseStagingTexture(); mRecoverFromStorage = true; mAssociatedStorage = storage11; mAssociatedImageIndex = index; } return gl::NoError(); }
Image11::~Image11() { disassociateStorage(); releaseStagingTexture(); }