Beispiel #1
0
        /// <summary>
        /// Converts pEngine debug flags to Vulkan debug flags.
        /// </summary>
        /// <returns>Vulkan debug flags.</returns>
        private DebugReportFlags DebugFlags()
        {
            DebugReportFlags debug = DebugReportFlags.Debug | DebugReportFlags.Error | DebugReportFlags.Information | DebugReportFlags.PerformanceWarning | DebugReportFlags.Warning;

            if (Debug.RendererDebugLevel.HasFlag(DebugLevel.Critical))
            {
                debug |= DebugReportFlags.Error;
            }

            if (Debug.RendererDebugLevel.HasFlag(DebugLevel.Performance))
            {
                debug |= DebugReportFlags.PerformanceWarning;
            }

            if (Debug.RendererDebugLevel.HasFlag(DebugLevel.Warning))
            {
                debug |= DebugReportFlags.Warning;
            }

            if (Debug.RendererDebugLevel.HasFlag(DebugLevel.Debug))
            {
                debug |= DebugReportFlags.Debug;
            }

            if (Debug.RendererDebugLevel.HasFlag(DebugLevel.Info))
            {
                debug |= DebugReportFlags.Information;
            }

            return(debug);
        }
Beispiel #2
0
        public static Bool32 _DebugReport(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object,
                                          HostSize location, int messageCode, string layerPrefix, string message, IntPtr userData)
        {
            Console.WriteLine(message);

            return(false);
        }
Beispiel #3
0
        private static Bool32 DebugCallback(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, HostSize location, int messageCode, string pLayerPrefix, string pMessage, IntPtr pUserData)
        {
            string logMessage = $"{pLayerPrefix}: {pMessage}";

            Console.WriteLine(logMessage);
            System.Diagnostics.Debug.WriteLine(logMessage);

            return(false);
        }
Beispiel #4
0
 /// <summary>
 /// -
 /// </summary>
 public void DebugReportMessage(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, Size location, int messageCode, string layerPrefix, string message)
 {
     unsafe
     {
         try
         {
             var   commandDelegate       = this.commandCache.GetCommandDelegate <Interop.vkDebugReportMessageEXT>("vkDebugReportMessageEXT", "instance");
             char *marshalledLayerPrefix = Interop.HeapUtil.MarshalTo(layerPrefix);
             char *marshalledMessage     = Interop.HeapUtil.MarshalTo(message);
             commandDelegate(this.handle, flags, objectType, @object, location, messageCode, marshalledLayerPrefix, marshalledMessage);
         }
         finally
         {
             Interop.HeapUtil.FreeLog();
         }
     }
 }
        private static unsafe Bool32 DebugReportCallbackWrapperCallback(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, HostSize location, int messageCode, string pLayerPrefix, string pMessage, IntPtr pUserData)
        {
            if (pUserData == IntPtr.Zero)
            {
                return(false);
            }

            System.Runtime.InteropServices.GCHandle gch = System.Runtime.InteropServices.GCHandle.FromIntPtr(pUserData);
            DebugReportCallbackWrapper callback         = (DebugReportCallbackWrapper)gch.Target;

            if (callback == null)
            {
                return(false);
            }

            return(callback.callback_(flags, objectType, @object, location, messageCode, pLayerPrefix, pMessage) && callback.ValidationLayerTesting);
        }
 private static RawBool DebugReport(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, PointerSize location, int messageCode, string layerPrefix, string message, IntPtr userData)
 {
     Debug.WriteLine($"{flags}: {message} ([{messageCode}] {layerPrefix})");
     return true;
 }
Beispiel #7
0
        private static Bool32 DebugReport(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, Size location, int messageCode, string layerPrefix, string message, IntPtr userData)
        {
            Debug.WriteLine(message);

            return(false);
        }
Beispiel #8
0
 private static RawBool DebugReport(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, PointerSize location, int messageCode, string layerPrefix, string message, IntPtr userData)
 {
     Debug.WriteLine($"{flags}: {message} ([{messageCode}] {layerPrefix})");
     return(true);
 }
Beispiel #9
0
 public Bool32 DebugReport(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object,
                           HostSize location, int messageCode, string layerPrefix, string message, IntPtr userData)
 {
     return(VkHelperFunctions._DebugReport(flags, objectType, @object, location, messageCode, layerPrefix, message, userData));
 }
Beispiel #10
0
 /// <summary>
 /// Vulkan debug callback.
 /// </summary>
 private Bool32 DebugCallback(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, HostSize location, int messageCode, string pLayerPrefix, string pMessage, IntPtr pUserData)
 {
     Console.WriteLine(pMessage);
     return(false);
 }
Beispiel #11
0
        static void Main(string[] args)
        {
            var availableExtensions = Instance.EnumerateExtensionProperties(null);

            var availableLayers = Instance.EnumerateLayerProperties();

            var debugCallback           = new DebugReportCallbackDelegate(DebugCallback);
            DebugReportFlags debugFlags = DebugReportFlags.Error | DebugReportFlags.Warning | DebugReportFlags.PerformanceWarning | DebugReportFlags.Information;

            var instance = Instance.Create("VK_LAYER_LUNARG_standard_validation", ExtExtensions.DebugReport,
                                           debugReportCallbackCreateInfoExt: new DebugReportCallbackCreateInfo
            {
                Callback = debugCallback,
                Flags    = debugFlags
            });

            var callbackHandle = instance.CreateDebugReportCallback(debugCallback, debugFlags);

            var physicalDevice = instance.EnumeratePhysicalDevices().First();

            var physicalDeviceProperties = physicalDevice.GetProperties();

            var features = physicalDevice.GetFeatures();

            uint hostVisibleMemory = physicalDevice.GetMemoryProperties().MemoryTypes.Select((x, index) => (Type: x, Index: (uint)index)).First(x => x.Type.PropertyFlags.HasFlag(MemoryPropertyFlags.HostVisible | MemoryPropertyFlags.HostCoherent)).Index;

            var device = physicalDevice.CreateDevice(
                new DeviceQueueCreateInfo
            {
                QueueFamilyIndex = 0,
                QueuePriorities  = new float[] { 0 }
            },
                null,
                null
                );

            const int valueCount = 256;
            const int bufferSize = valueCount * sizeof(int);

            var sharedMemory = device.AllocateMemory(1 << 20, hostVisibleMemory);

            var inBuffer = device.CreateBuffer(bufferSize, BufferUsageFlags.TransferSource | BufferUsageFlags.StorageBuffer, SharingMode.Exclusive, 0);

            inBuffer.BindMemory(sharedMemory, 0);

            int outBufferOffset = (int)inBuffer.GetMemoryRequirements().Size;

            var outBuffer = device.CreateBuffer(bufferSize, BufferUsageFlags.TransferDestination | BufferUsageFlags.StorageBuffer, SharingMode.Exclusive, 0);

            outBuffer.BindMemory(sharedMemory, outBufferOffset);

            IntPtr inBufferPtr = sharedMemory.Map(0, bufferSize, MemoryMapFlags.None);

            Marshal.Copy(Enumerable.Range(0, valueCount).Select(x => x).ToArray(), 0, inBufferPtr, valueCount);

            sharedMemory.Unmap();

            var commandPool = device.CreateCommandPool(0, CommandPoolCreateFlags.Transient);

            var descriptorPool = device.CreateDescriptorPool(16, new DescriptorPoolSize(DescriptorType.StorageBuffer, 16));

            //TransferByCommand(device, bufferSize, inBuffer, outBuffer, commandPool);

            TransferByCompute(device, bufferSize, inBuffer, outBuffer, commandPool, descriptorPool);

            IntPtr outBufferPtr = sharedMemory.Map(outBufferOffset, bufferSize, MemoryMapFlags.None);

            var values = new List <int>();

            for (int index = 0; index < valueCount; index++)
            {
                values.Add(Marshal.ReadInt32(outBufferPtr, index * sizeof(int)));
            }

            sharedMemory.Unmap();

            Console.WriteLine(string.Join(", ", values));

            descriptorPool.Destroy();

            commandPool.Destroy();

            outBuffer.Destroy();

            inBuffer.Destroy();

            sharedMemory.Free();

            device.Destroy();

            callbackHandle.Destroy();

            instance.Destroy();

            Console.WriteLine("Done");

            Console.ReadLine();
        }
        private Bool32 DebugReport(DebugReportFlags flags, DebugReportObjectType objectType, ulong @object, Size location, int messageCode, string layerPrefix, string message, IntPtr userData)
        {
            System.Diagnostics.Debug.WriteLine($"{flags}: {message}");

            return(true);
        }