예제 #1
0
        public void CreateDebugReportCallbackExt()
        {
            var createInfo = new InstanceCreateInfo(
                enabledLayerNames: new[] { InstanceLayer.LunarGStandardValidation },
                enabledExtensionNames: new[] { InstanceExtension.ExtDebugReport });

            using (var instance = new Instance(createInfo))
            {
                var    callbackArgs   = new List <DebugReportCallbackInfo>();
                int    userData       = 1;
                IntPtr userDataHandle = new IntPtr(&userData);
                var    debugReportCallbackCreateInfo = new DebugReportCallbackCreateInfoExt(
                    DebugReportFlagsExt.All,
                    args =>
                {
                    callbackArgs.Add(args);
                    return(false);
                },
                    userDataHandle);

                using (instance.CreateDebugReportCallbackExt(debugReportCallbackCreateInfo))
                {
                    instance.DebugReportMessageExt(DebugReportFlagsExt.Debug, "test");
                    Assert.NotEmpty(callbackArgs);
                    Assert.Equal(1, *(int *)callbackArgs[0].UserData);
                }
                callbackArgs.Clear();
                using (instance.CreateDebugReportCallbackExt(debugReportCallbackCreateInfo, CustomAllocator))
                {
                    instance.DebugReportMessageExt(DebugReportFlagsExt.Debug, "test");
                    Assert.NotEmpty(callbackArgs);
                    Assert.Equal(1, *(int *)callbackArgs[0].UserData);
                }
            }
        }
예제 #2
0
        private void CreateInstance()
        {
            AvailableInstanceExtensions = Instance.EnumerateExtensionProperties();
            string[] selectExtensions = new[] { Constant.InstanceExtension.ExtDebugReport }
            .Where(AvailableInstanceExtensions.Contains)
            .ToArray();

            // Specify standard validation layers.
            var createInfo = new InstanceCreateInfo
            {
                EnabledLayerNames     = new[] { Constant.InstanceLayer.LunarGStandardValidation },
                EnabledExtensionNames = selectExtensions
            };

            Instance = new Instance(createInfo);

            // Attach debug callback and fail any test on any error or warning from validation layers.
            var debugReportCreateInfo = new DebugReportCallbackCreateInfoExt(
                DebugReportFlagsExt.Error |
                DebugReportFlagsExt.Warning |
                DebugReportFlagsExt.PerformanceWarning,
                args =>
            {
                if ((args.Flags & (DebugReportFlagsExt.Error |
                                   DebugReportFlagsExt.PerformanceWarning |
                                   DebugReportFlagsExt.Warning)) > 0)
                {
                    Assert.True(false, $"Validation layer error/warning:\n\n[{args.Flags}] {args.Message}");
                }
                return(false);
            }
                );

            _debugReportCallback = Instance.CreateDebugReportCallbackExt(debugReportCreateInfo);
        }
예제 #3
0
        public void CreateDebugReportCallbackExt()
        {
            var createInfo = new InstanceCreateInfo(
                enabledLayerNames: new[] { InstanceLayer.LunarGStandardValidation },
                enabledExtensionNames: new[] { InstanceExtension.ExtDebugReport });

            using (var instance = new Instance(createInfo))
            {
                var    callbackArgs   = new List <DebugReportCallbackInfo>();
                int    userData       = 1;
                IntPtr userDataHandle = new IntPtr(&userData);
                var    debugReportCallbackCreateInfo = new DebugReportCallbackCreateInfoExt(
                    DebugReportFlagsExt.All,
                    args =>
                {
                    callbackArgs.Add(args);
                    return(false);
                },
                    userDataHandle);

                // Registering the callback should generate DEBUG messages.
                using (instance.CreateDebugReportCallbackExt(debugReportCallbackCreateInfo)) { }
                using (instance.CreateDebugReportCallbackExt(debugReportCallbackCreateInfo, CustomAllocator)) { }

                Assert.True(callbackArgs.Count > 0);
                Assert.Equal(1, *(int *)callbackArgs[0].UserData);
            }
        }
예제 #4
0
        private void SetupDebugCallback(Instance instance)
        {
            data.debugCallbackDelegate = DebugCallback;
            var createInfo = new DebugReportCallbackCreateInfoExt
            {
                Flags       = DebugReportFlagsExt.Error | DebugReportFlagsExt.Warning,
                PfnCallback = Marshal.GetFunctionPointerForDelegate(data.debugCallbackDelegate)
            };

            data.debugCallback = instance.CreateDebugReportCallbackEXT(createInfo);
        }
예제 #5
0
        internal static DebugReportCallbackExt CreateDebugReportCallback(Instance inst)
        {
#if DEBUG
            // Attach debug callback.
            var debugReportCreateInfo = new DebugReportCallbackCreateInfoExt(
                DebugReportFlagsExt.All,
                args =>
            {
                Console.WriteLine($"[{args.Flags}][{args.LayerPrefix}] {args.Message}");
                return(args.Flags.HasFlag(DebugReportFlagsExt.Error));
            }
                );
            return(inst.CreateDebugReportCallbackExt(debugReportCreateInfo));
#else
            return(null);
#endif
        }
예제 #6
0
        private DebugReportCallbackExt CreateDebugReportCallback(bool debug)
        {
            if (!debug)
            {
                return(null);
            }

            // Attach debug callback.
            var debugReportCreateInfo = new DebugReportCallbackCreateInfoExt(
                DebugReportFlagsExt.All,
                args => {
                Debug.WriteLine($"[{args.Flags}][{args.LayerPrefix}] {args.Message}");
                return(args.Flags.HasFlag(DebugReportFlagsExt.Error));
            }
                );

            return(Instance.CreateDebugReportCallbackExt(debugReportCreateInfo));
        }
예제 #7
0
        public void EnableDebug(DebugReportCallback d, DebugReportFlagsExt flags = DebugReportFlagsExt.Debug | DebugReportFlagsExt.Error | DebugReportFlagsExt.Information | DebugReportFlagsExt.PerformanceWarning | DebugReportFlagsExt.Warning)
        {
            if (vkCreateDebugReportCallbackEXT == null)
            {
                throw new InvalidOperationException("vkCreateDebugReportCallbackEXT is not available, possibly you might be missing VK_EXT_debug_report extension. Try to enable it when creating the Instance.");
            }

            var debugCreateInfo = new DebugReportCallbackCreateInfoExt()
            {
                Flags       = flags,
                PfnCallback = Marshal.GetFunctionPointerForDelegate(d)
            };

            if (debugCallback != null)
            {
                DestroyDebugReportCallbackEXT(debugCallback);
            }
            debugCallback = CreateDebugReportCallbackEXT(debugCreateInfo);
        }
예제 #8
0
        private DebugReportCallbackExt CreateDebugReportCallback(bool debug)
        {
            //Currently MoltenVK (used for MacOS) doesn't support the debug layer.
            if (!debug || Host.Platform == Platform.MacOS)
            {
                return(null);
            }

            // Attach debug callback.
            var debugReportCreateInfo = new DebugReportCallbackCreateInfoExt(
                DebugReportFlagsExt.All,
                args =>
            {
                Debug.WriteLine($"[{args.Flags}][{args.LayerPrefix}] {args.Message}");
                return(args.Flags.HasFlag(DebugReportFlagsExt.Error));
            }
                );

            return(Instance.CreateDebugReportCallbackExt(debugReportCreateInfo));
        }
예제 #9
0
        public void DebugReportMessageExt()
        {
            const string message = "message õäöü";
            const DebugReportObjectTypeExt objectType = DebugReportObjectTypeExt.DebugReportCallback;
            const long   @object     = long.MaxValue;
            var          location    = new IntPtr(int.MaxValue);
            const int    messageCode = 1;
            const string layerPrefix = "prefix õäöü";

            bool visitedCallback = false;

            var instanceCreateInfo = new InstanceCreateInfo(
                enabledExtensionNames: new[] { InstanceExtension.ExtDebugReport });

            using (var instance = new Instance(instanceCreateInfo))
            {
                var debugReportCallbackCreateInfo = new DebugReportCallbackCreateInfoExt(
                    DebugReportFlagsExt.Error,
                    args =>
                {
                    Assert.Equal(objectType, args.ObjectType);
                    Assert.Equal(@object, args.Object);
                    Assert.Equal(location, args.Location);
                    Assert.Equal(messageCode, args.MessageCode);
                    Assert.Equal(layerPrefix, args.LayerPrefix);
                    Assert.Equal(message, args.Message);
                    visitedCallback = true;
                    return(false);
                });
                using (instance.CreateDebugReportCallbackExt(debugReportCallbackCreateInfo))
                {
                    instance.DebugReportMessageExt(DebugReportFlagsExt.Error, message, objectType,
                                                   @object, location, messageCode, layerPrefix);
                }
            }

            Assert.True(visitedCallback);
        }
예제 #10
0
        public bool InitVulkan(string appName, VER appVer, bool bDebug)
        {
            Glfw.Init();

            mInstance = new Instance(appName, EngineName,
                                     appVer, mEngineVer, mAPIVer, bDebug);

            if (!mInstance.IsValid())
            {
                Misc.SafeInvoke(eErrorSpam, "Couldn't create Vulkan instance.");
                return(false);
            }

            if (bDebug)
            {
                //set up debug callback to talk to validation stuff
                DebugReportCallbackCreateInfoExt drcbci = new DebugReportCallbackCreateInfoExt(
                    DebugReportFlagsExt.All, DebugReportCallback, IntPtr.Zero);
                mDebugCB = mInstance.AttachDebugCallback(drcbci);
            }

            return(true);
        }
예제 #11
0
 internal DebugReportCallbackExt AttachDebugCallback(DebugReportCallbackCreateInfoExt drcbci)
 {
     return(mInstance.CreateDebugReportCallbackExt(drcbci));
 }