Esempio n. 1
0
        public void CmdDispatch(AmtCommandRecording recording, uint index)
        {
            var stage = recording.Compute;
            var item  = stage.Grid.Dispatch[index];

            stage.Encoder.DispatchThreadgroups(item.GroupSize, item.ThreadsPerGroupSize);
        }
Esempio n. 2
0
        private static void DispatchIndirect(AmtCommandRecording recording, uint index)
        {
            var stage = recording.Compute;
            var item  = stage.Grid.DispatchIndirect[index];

            stage.Encoder.DispatchThreadgroups(item.IndirectBuffer, item.Offset, item.ThreadsPerGroupSize);
        }
Esempio n. 3
0
        private static void CmdBindPipeline(AmtCommandRecording recording, uint index)
        {
            var stage = recording.Compute;
            var item  = stage.Grid.Pipelines[index];

            stage.Encoder.SetComputePipelineState(item.Compute);
        }
Esempio n. 4
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;
                }
            }
        }
Esempio n. 5
0
        private static void CmdCopyImage(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");
            AmtBlitCopyImageRecord item = stage.Grid.CopyImages[index];

            Debug.Assert(item.Regions != null, nameof(item.Regions) + " is null");

            foreach (var region in item.Regions)
            {
                nuint srcSlice = region.SourceSlice;
                nuint dstSlice = region.DestinationSlice;
                for (var i = 0; i < region.SourceLayerCount; ++i)
                {
                    stage.Encoder.CopyFromTexture(
                        item.Source,
                        srcSlice,
                        region.SourceMipLevel,
                        region.SourceOrigin,
                        region.SourceSize,
                        item.Destination,
                        dstSlice,
                        region.DestinationMipLevel,
                        region.DestinationOrigin
                        );
                    ++srcSlice;
                }

                srcSlice = region.SourceSlice;
                for (var i = 0; i < region.DestinationLayerCount; ++i)
                {
                    stage.Encoder.CopyFromTexture(
                        item.Source,
                        srcSlice,
                        region.SourceMipLevel,
                        region.SourceOrigin,
                        region.SourceSize,
                        item.Destination,
                        dstSlice,
                        region.DestinationMipLevel,
                        region.DestinationOrigin
                        );
                    ++dstSlice;
                }
            }
        }
Esempio n. 6
0
        private static void CmdCopyBuffer(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");
            AmtBlitCopyBufferRecord item = stage.Grid.CopyBuffers[index];

            Debug.Assert(item.Regions != null, nameof(item.Regions) + " is null");
            foreach (var region in item.Regions)
            {
                stage.Encoder.CopyFromBuffer(item.Src, region.SourceOffset, item.Dst, region.DestinationOffset, region.Size);
            }
        }
Esempio n. 7
0
		public void Render(AmtQueueSubmission request)
		{
			foreach (var buffer in request.CommandBuffers)
			{
				if (buffer.IsQueueReady)
				{
					// GENERATE METAL BUFFER
					var cb = mCommandQueue.CommandBuffer();
					cb.Label = "MyCommand";

					AmtCommandRecording recording = GenerateRecording(cb, buffer);

					foreach (var context in buffer.Record.Contexts)
					{
						if (context.Category == AmtEncoderCategory.Compute)
						{
							recording.Compute.Encoder = cb.ComputeCommandEncoder;
						}
						else if (context.Category == AmtEncoderCategory.Blit)
						{
							recording.Blit.Encoder = cb.BlitCommandEncoder;
						}

						for (var i = context.First; i <= context.Last; ++i)
						{
							buffer.Record.Instructions[i].Perform(recording);
						}

						if (context.Category == AmtEncoderCategory.Compute)
						{
							recording.Compute.Encoder.EndEncoding();
							recording.Compute.Encoder = null;
						}
						else if (context.Category == AmtEncoderCategory.Blit)
						{
							recording.Blit.Encoder.EndEncoding();
							recording.Blit.Encoder = null;
						}
					}

					TriggerSemaphores(request.Signals, cb);
					SignalFenceWhenCompleted(request.OrderFence, cb);

					cb.Commit();
				}
			}
		}
Esempio n. 8
0
 public void Perform(AmtCommandRecording recording)
 {
     Operation(recording, Index);
 }