johang88 / TR.Stride

Various stride utilities / projects (stride3d.net)
MIT License
54 stars 8 forks source link

Test vulkan/dx12 compatability #6

Open johang88 opened 3 years ago

Doprez commented 6 months ago

I attempted to test the Vulkan renderer since I want to try this on Linux at some point. Unfortunately there is an immediate error about a texture format being unsupported in AtmosphereRenderFeature.cs Line 78: System.InvalidOperationException: 'Unsupported texture format: R11G11B10_Float'

The good news is this may be an easy fix, the bad news it is a fix needed in Stride as far as I can tell. this is an example of a similar issue and PR from Basewq but related to OpenGL.

Edit: I did a small amount of research to see what would be required and I think I understand whats needed?

https://github.com/amerkoleci/Vortice.Vulkan/blob/fb580360a39ff3e8baa7b466761cc293295f3bd7/src/Vortice.Vulkan/Generated/VkFormatUtils.cs#L231 The above link is the coversion type that I believe is needed since Stride uses Vortice for the vulkan bindings and I think it should be added here with the below line but I will need to do a rebuild with the source repo tomorrow as I am getting a bit to tired to reliably test lol:

case : PixelFormat.R11G11B10_Float
    format = VkFormat.B10G11R11UfloatPack32
    pixelSize = 8;
    break;
Doprez commented 6 months ago

Also important to note that DX12 seems completely borked in current Stride so I dont know if its worth testing this for a while. (I know this was made back in 2021 but it may be worth mentioning)

johang88 commented 6 months ago

Hmm, could just change the format to something like r16g16b16_float, will use some more bandwidth but should be fine i think

Doprez commented 6 months ago

Error1

Ah, that is much simpler and does get me through that error.

Error2

There is another now in the Ocean project where it cant seem to convert the Compute stage to OpenGL.

In FastFourierTransform line 77:

System.AggregateException: 'One or more errors occurred. (Could not compile shader. See error messages.Error: Compute stage can't be converted to OpenGL. Only Vertex and Pixel shaders are supported)'

This error happens multiple times in both FastFourierTransform and WavesCascade due to the Shader.Draw(context) calls.

Error3

finally there also seems to be a bug in Stride directly with the glsl generation as it uses the wrong name. I will log this as a Stride issue later though since that seems to not be part of this project.

\tmpgcvp1b.vert:23: 'gl_InstanceID' : undeclared identifier (Did you mean gl_InstanceIndex?)
johang88 commented 6 months ago

Error2: That is strange, do the computer shaders in the atmosphere project work?

Doprez commented 6 months ago

Sadly still no it seems like error 3 gets in the way due to the failed generation below.

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (Could not compile shader. See error messages.Info: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert:23: 'gl_InstanceID' : undeclared identifier (Did you mean gl_InstanceIndex?)
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert:23: 'assign' :  cannot convert from ' temp float' to ' global highp uint'
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert:23: '' : compilation terminated 
Info: ERROR: 3 compilation errors.  No code generated.
Info: SPIR-V is not generated for failed compile or link
Error: Failed to generate SPIR-V from GLSL
Info: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag:208: 'DepthStencil_id80' : undeclared identifier 
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag:208: 'DepthStencil_id80' :  left of '[' is not of type array, matrix, or vector  
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag:208: '' : compilation terminated 
Info: ERROR: 3 compilation errors.  No code generated.
Info: ERROR: Linking fragment stage: Missing entry point: Each stage requires one entry point
Info: SPIR-V is not generated for failed compile or link
Error: Failed to generate SPIR-V from GLSL
)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Stride.Rendering.RootEffectRenderFeature.PrepareEffectPermutations(RenderDrawContext context)
   at Stride.Rendering.RenderSystem.Prepare(RenderDrawContext context)
   at Stride.Rendering.Compositing.GraphicsCompositor.DrawCore(RenderDrawContext context)
   at Stride.Rendering.RendererBase.Draw(RenderDrawContext context)
   at Stride.Engine.SceneSystem.Draw(GameTime gameTime)
   at Stride.Games.GameSystemCollection.Draw(GameTime gameTime)
   at Stride.Games.GameBase.Draw(GameTime gameTime)
   at Stride.Games.GameBase.RawTick(TimeSpan elapsedTimePerUpdate, Int32 updateCount, Single drawInterpolationFactor, Boolean drawFrame)
   at Stride.Games.GameBase.RawTickProducer()
   at Stride.Games.GameBase.Tick()
   at Stride.Games.GamePlatform.Tick()
   at Stride.Games.GamePlatform.OnRunCallback()
   at Stride.Games.GameWindowSDL.<>c__DisplayClass17_0.<Run>b__0()
   at Stride.Games.SDLMessageLoop.Run(Window form, RenderCallback renderCallback)
   at Stride.Games.GameWindowSDL.Run()
   at Stride.Games.GamePlatform.Run(GameContext gameContext)
   at Stride.Games.GameBase.Run(GameContext gameContext)
   at TR.Stride.TR_StrideApp.Main(String[] args) in C:\dev\GitControlledProjects\TR.Stride\TR.Stride.Windows\TR_StrideApp.cs:line 11

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
InvalidOperationException: Could not compile shader. See error messages.Info: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert:23: 'gl_InstanceID' : undeclared identifier (Did you mean gl_InstanceIndex?)
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert:23: 'assign' :  cannot convert from ' temp float' to ' global highp uint'
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpdvazal.vert:23: '' : compilation terminated 
Info: ERROR: 3 compilation errors.  No code generated.
Info: SPIR-V is not generated for failed compile or link
Error: Failed to generate SPIR-V from GLSL
Info: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag:208: 'DepthStencil_id80' : undeclared identifier 
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag:208: 'DepthStencil_id80' :  left of '[' is not of type array, matrix, or vector  
Info: ERROR: C:\Users\User\AppData\Local\Temp\tmpxu3ojj.frag:208: '' : compilation terminated 
Info: ERROR: 3 compilation errors.  No code generated.
Info: ERROR: Linking fragment stage: Missing entry point: Each stage requires one entry point
Info: SPIR-V is not generated for failed compile or link
Error: Failed to generate SPIR-V from GLSL
johang88 commented 6 months ago

This PR sorts out some of the compilation errors, there are some more that need changes in the shaders. I have sorted those out as well and will push a fix for it if I can get it to not crash at a later step 😅

https://github.com/stride3d/stride/pull/2217

johang88 commented 6 months ago

Looks like there is no compilation path for compute shaders :/ That's annoying and a bit weird means that a lot of stuff currently does not work on the vulkan renderer.

image

Doprez commented 6 months ago

I thought OpenGL had compute shaders, is that an HLSL thing?

johang88 commented 6 months ago

it does, it's just the stride shader compiler that does not support it. I have started looking a little at it but hard to say how much work it is to get it working.

Doprez commented 6 months ago

ah ok yep, looking at the source now I see some of the spots that need to be changed. I could definitely see this becoming a rabbit hole of changes lol.

maybe this repo will help with some validation https://github.com/septag/glslcc they seem to have gotten one more step further than Stride with having Compute shader support.

johang88 commented 6 months ago

yeah there is a lot of stuff missing in the hlsl to glsl translation layer, mainly handling of image2d (and it's variants)