protected override void DestroyImpl() { // Do not release _nativeDeviceChild, as it is owned by the texture. // _renderTargetView should keep it alive anyway. //base.DestroyImpl(); _nativeDeviceChild = null; Utilities.Dispose(ref _renderTargetView); }
/// <inheritdoc/> protected internal override void OnDestroyed() { // Recycle heaps ResetSrvHeap(false); ResetSamplerHeap(false); // Available right now (NextFenceValue - 1) // TODO: Note that it won't be available right away because CommandAllocators is currently not using a PriorityQueue but a simple Queue if (nativeCommandAllocator != null) { GraphicsDevice.CommandAllocators.RecycleObject(GraphicsDevice.NextFenceValue - 1, nativeCommandAllocator); nativeCommandAllocator = null; } Utilities.Dispose(ref NativeCommandList); base.OnDestroyed(); }
internal void UpdateSubresource(GraphicsResource resource, int subResourceIndex, DataBox databox, ResourceRegion region) { var texture = resource as Texture; if (texture != null) { var width = region.Right - region.Left; var height = region.Bottom - region.Top; var depth = region.Back - region.Front; ResourceDescription resourceDescription; switch (texture.Dimension) { case TextureDimension.Texture1D: resourceDescription = ResourceDescription.Texture1D((SharpDX.DXGI.Format)texture.Format, width, 1, 1); break; case TextureDimension.Texture2D: case TextureDimension.TextureCube: resourceDescription = ResourceDescription.Texture2D((SharpDX.DXGI.Format)texture.Format, width, height, 1, 1); break; case TextureDimension.Texture3D: resourceDescription = ResourceDescription.Texture3D((SharpDX.DXGI.Format)texture.Format, width, height, (short)depth, 1); break; default: throw new ArgumentOutOfRangeException(); } // TODO D3D12 allocate in upload heap (placed resources?) var nativeUploadTexture = NativeDevice.CreateCommittedResource(new HeapProperties(CpuPageProperty.WriteBack, MemoryPool.L0), HeapFlags.None, resourceDescription, ResourceStates.GenericRead); GraphicsDevice.TemporaryResources.Enqueue(new KeyValuePair <long, DeviceChild>(GraphicsDevice.NextFenceValue, nativeUploadTexture)); nativeUploadTexture.WriteToSubresource(0, null, databox.DataPointer, databox.RowPitch, databox.SlicePitch); var parentResource = resource.ParentResource ?? resource; // Trigger copy NativeCommandList.ResourceBarrierTransition(resource.NativeResource, parentResource.NativeResourceState, ResourceStates.CopyDestination); NativeCommandList.CopyTextureRegion(new TextureCopyLocation(resource.NativeResource, subResourceIndex), region.Left, region.Top, region.Front, new TextureCopyLocation(nativeUploadTexture, 0), null); NativeCommandList.ResourceBarrierTransition(resource.NativeResource, ResourceStates.CopyDestination, parentResource.NativeResourceState); } else { var buffer = resource as Buffer; if (buffer != null) { SharpDX.Direct3D12.Resource uploadResource; int uploadOffset; var uploadSize = region.Right - region.Left; var uploadMemory = GraphicsDevice.AllocateUploadBuffer(region.Right - region.Left, out uploadResource, out uploadOffset); Utilities.CopyMemory(uploadMemory, databox.DataPointer, uploadSize); NativeCommandList.ResourceBarrierTransition(resource.NativeResource, resource.NativeResourceState, ResourceStates.CopyDestination); NativeCommandList.CopyBufferRegion(resource.NativeResource, region.Left, uploadResource, uploadOffset, uploadSize); NativeCommandList.ResourceBarrierTransition(resource.NativeResource, ResourceStates.CopyDestination, resource.NativeResourceState); } else { throw new InvalidOperationException("Unknown resource type"); } } }