예제 #1
0
        private static void CmdCopyBufferToImage(AmtCommandRecording recording, uint index)
        {
            Debug.Assert(recording != null, nameof(recording) + " is null");
            var stage = recording.Blit;

            Debug.Assert(stage != null, nameof(stage) + " is null");
            Debug.Assert(stage.Encoder != null, nameof(stage.Encoder) + " is null");
            Debug.Assert(stage.Grid != null, nameof(stage.Grid) + " is null");
            AmtBlitCopyBufferToImageRecord item = stage.Grid.CopyBufferToImages[index];

            Debug.Assert(item.Regions != null, nameof(item.Regions) + " is null");
            foreach (var region in item.Regions)
            {
                nuint slice = region.BaseArrayLayer;
                for (var i = 0; i < region.ImageLayerCount; ++i)
                {
                    stage.Encoder.CopyFromBuffer(
                        item.Buffer,
                        region.BufferOffset,
                        region.BufferBytesPerRow,
                        region.BufferImageAllocationSize,
                        region.ImageSize,
                        item.Image,
                        slice,
                        region.ImageMipLevel,
                        region.ImageOffset);
                    ++slice;
                }
            }
        }
예제 #2
0
        public void CopyBufferToImage(IMgBuffer srcBuffer,
                                      IMgImage dstImage, MgImageLayout dstImageLayout, MgBufferImageCopy[] pRegions)
        {
            if (srcBuffer == null)
            {
                throw new ArgumentNullException(nameof(srcBuffer));
            }

            if (dstImage == null)
            {
                throw new ArgumentNullException(nameof(dstImage));
            }

            if (pRegions == null)
            {
                throw new ArgumentNullException(nameof(pRegions));
            }

            var bSrcBuffer = (AmtBuffer)srcBuffer;
            var bDstImage  = (AmtImage)dstImage;

            var regions = new List <AmtBlitCopyBufferToImageRegionRecord>();

            for (var i = 0; i < pRegions.Length; ++i)
            {
                var currentRegion = pRegions[i];

                if (currentRegion.BufferOffset > nuint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(
                              "pRegions[" + i + "].BufferOffset must be less than " + nuint.MaxValue);
                }

                if (currentRegion.BufferRowLength > nuint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(
                              "pRegions[" + i + "].DstOffset must be less than " + nuint.MaxValue);
                }

                var extent = currentRegion.ImageExtent;

                if (extent.Width > nint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(
                              "pRegions[" + i + "].ImageExtent.Width  must be <=" + nint.MaxValue);
                }

                if (extent.Height > nint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(
                              "pRegions[" + i + "].ImageExtent.Height must be <= " + nint.MaxValue);
                }

                if (extent.Depth > nint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(
                              "pRegions[" + i + "].ImageExtent.Depth must be <= " + nint.MaxValue);
                }

                var sourceImageSize = currentRegion.BufferRowLength * currentRegion.BufferImageHeight;

                if (sourceImageSize > nuint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(
                              "sourceImageSize (pRegions[" + i
                              + "].BufferRowLength * BufferImageHeight) must be <= " + nuint.MaxValue);
                }

                regions.Add(new AmtBlitCopyBufferToImageRegionRecord
                {
                    BufferOffset              = (nuint)currentRegion.BufferOffset,
                    BufferBytesPerRow         = (nuint)currentRegion.BufferRowLength,
                    BufferImageAllocationSize = (nuint)sourceImageSize,
                    ImageSize = new MTLSize
                    {
                        Width  = (nint)extent.Width,
                        Height = (nint)extent.Height,
                        Depth  = (nint)extent.Depth,
                    },
                    BaseArrayLayer  = currentRegion.ImageSubresource.BaseArrayLayer,
                    ImageMipLevel   = currentRegion.ImageSubresource.MipLevel,
                    ImageLayerCount = currentRegion.ImageSubresource.LayerCount,
                    ImageOffset     = new MTLOrigin
                    {
                        X = currentRegion.ImageOffset.X,
                        Y = currentRegion.ImageOffset.Y,
                        Z = currentRegion.ImageOffset.Z,
                    },
                });
            }

            var item = new AmtBlitCopyBufferToImageRecord
            {
                Buffer  = bSrcBuffer.VertexBuffer,
                Image   = bDstImage.OriginalTexture,
                Regions = regions.ToArray(),
            };

            var nextIndex = mBag.CopyBufferToImages.Push(item);

            mInstructions.Add(new AmtEncodingInstruction
            {
                Category  = AmtEncoderCategory.Blit,
                Index     = nextIndex,
                Operation = CmdCopyBufferToImage,
            });
        }