tgjones / HlslTools

A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files
http://timjones.io/blog/archive/2016/04/25/hlsl-tools-for-visual-studio-v1.0-released
Other
561 stars 97 forks source link

Freezes up the IDE #202

Open Golgovskiy opened 3 years ago

Golgovskiy commented 3 years ago

image Slows down the editor gradually. Starts freezing after every key or mouse press anywhere. After a certain times freezes completely and crashes the editor.

GlassBeaver commented 3 years ago

experiencing the same, might be related to the latest visual studio update, 16.8.2 Community never had problems with the tool before and I've been using it for years

tgjones commented 3 years ago

Thanks for the bug report(s). I'll investigate.

GlassBeaver commented 3 years ago

Here are two exceptions that I've encountered: Aggregate exception Out of memory exception

Note that my system has 64GB of RAM so it would be very suspicious if it in fact ran out of memory.

tgjones commented 3 years ago

@GlassBeaver thanks for those. Are you in a position to send me the shader(s) you were editing when you got those two exceptions? (If yes, please email tim@timjones.io; I'll treat anything you send me confidentially.)

I haven't been able to repro either of those exceptions yet, and my guess is that it's something specific about the shader code that I'm not covering in my existing tests.

GlassBeaver commented 3 years ago

It's DeferredLightingCommon.ush in Unreal Engine 4. You can find it on their github at: https://github.com/EpicGames/UnrealEngine/blob/2bf1a5b83a7076a0fd275887b373f8ec9e99d431/Engine/Shaders/Private/DeferredLightingCommon.ush

Just need to join the Epic Games github organization, instructions are here: https://www.unrealengine.com/en-US/ue4-on-github

PepperXu commented 3 years ago

Hi I have the exact same problem when editing DeferredLightingCommon.ush. The editor free for 2-3 seconds when typing semicolon, brackets or insert line-break.

stoopdapoop commented 3 years ago

adding my voice in here to say that I'm hitting the same issue on the same file.

I don't think it can be related to 16.8.2. I'm running 16.7.2 from August I'm still encountering this issue.

Danielwbolson commented 3 years ago

To chime in, you don't need to even be working within DeferredLightingCommon.ush, just including it causes the same lag and errors. Thus working with practically any deferred-related shader is troublesome.

MakotoIchinose commented 1 year ago

Expereincing the same, also with Unreal Engine 5's large shader files like DeferredLightingCommon.ush and BasePassPixelShading.ush, and with VS2022 being 64-bit, the plugin quickly eat up 6+ GB of memory.

co0l1ce commented 11 months ago

i think this is because of cycle include header files, in ue common headers, "Common.ush" will include "Platform/Vulkan/VulkanCommon.ush" "Platform/Vulkan/VulkanCommon.ush" will include "Common.ush" again

i fixed this problem by add a list to record include file

diff --git a/src/ShaderTools.CodeAnalysis.Hlsl/Parser/HlslLexer.cs b/src/ShaderTools.CodeAnalysis.Hlsl/Parser/HlslLexer.cs
index e9dedce..9d2b7b0 100644
--- a/src/ShaderTools.CodeAnalysis.Hlsl/Parser/HlslLexer.cs
+++ b/src/ShaderTools.CodeAnalysis.Hlsl/Parser/HlslLexer.cs
@@ -39,6 +39,7 @@ public sealed partial class HlslLexer : ILexer

         private readonly SourceFile _rootFile;
         private readonly Stack<IncludeContext> _includeStack;
+        private readonly List<String> _includeFiles;
         private CharReader _charReader;

         private class IncludeContext
@@ -87,6 +88,7 @@ public HlslLexer(SourceFile file, HlslParseOptions options = null, IIncludeFileS

             FileSegments = new List<FileSegment>();
             _includeStack = new Stack<IncludeContext>();
+            _includeFiles = new List<String>();
             PushIncludeContext(file);
         }

@@ -322,6 +324,11 @@ private void ReadTrivia(List<SyntaxNode> target, bool isTrailing)
                 try
                 {
                     include = _includeFileResolver.OpenInclude(includeFilename, _includeStack.Peek().File);
+
+                    if (_includeFiles.Contains(include.FilePath)) {
+                        return false;
+                    }
+
                     if (include == null)
                     {
                         includeDirective = includeDirective.WithDiagnostic(Diagnostic.Create(HlslMessageProvider.Instance, includeDirective.SourceRange, (int) DiagnosticId.IncludeNotFound, includeFilename));
@@ -357,6 +364,7 @@ private void PushIncludeContext(SourceFile file)

             var includeContext = new IncludeContext(file);
             _includeStack.Push(includeContext);
+            _includeFiles.Add(file.FilePath);
             _charReader = includeContext.CharReader;
             FileSegments.Add(new FileSegment(file, 0));
         }
@@ -365,7 +373,8 @@ private void PopIncludeContext()
         {
             _currentFileSegmentAbsolutePosition = FileSegments.Sum(x => x.Length);

-            _includeStack.Pop();
+            var file = _includeStack.Pop();
+            _includeFiles.Remove(file.File.FilePath);
             _charReader = _includeStack.Peek().CharReader;

             FileSegments.Add(new FileSegment(_includeStack.Peek().File, _charReader.Position));
@@ -1320,4 +1329,4 @@ private void ReadIdentifierOrKeyword()
             }
         }
     }
-}
\ No newline at end of file
+}