You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing a ShaderDescription struct to CreateFromSpirv extension method, Debug flag from passed struct is not used, which makes me unable to view and debug DX11 shaders under RenderDoc.
When corresponding Debug value is passed to resulting structs, I'm able to see and edit shader sources - although all identifiers are mangled, it's better than nothing.
P.S.: Until it's implemented upstream, I hacked up a version of that extension class that uses the passed flag:
Click to expand code
namespaceCommon;usingSystem.Text;usingVeldrid;usingVeldrid.SPIRV;/// <summary>/// Contains extension methods for loading <see cref="Shader"/> modules from SPIR-V bytecode./// </summary>publicstaticclassRFExt{/// <summary>/// Creates a vertex and fragment shader pair from the given <see cref="ShaderDescription"/> pair containing SPIR-V/// bytecode or GLSL source code./// </summary>/// <param name="factory">The <see cref="ResourceFactory"/> used to compile the translated shader code.</param>/// <param name="vertexShaderDescription">The vertex shader's description. <see cref="ShaderDescription.ShaderBytes"/>/// should contain SPIR-V bytecode or Vulkan-style GLSL source code which can be compiled to SPIR-V.</param>/// <param name="fragmentShaderDescription">The fragment shader's description./// <see cref="ShaderDescription.ShaderBytes"/> should contain SPIR-V bytecode or Vulkan-style GLSL source code which/// can be compiled to SPIR-V.</param>/// <returns>A two-element array, containing the vertex shader (element 0) and the fragment shader (element 1).</returns>publicstaticShader[]CrossCompile(thisResourceFactoryfactory,ShaderDescriptionvertexShaderDescription,ShaderDescriptionfragmentShaderDescription){returnCrossCompile(factory,vertexShaderDescription,fragmentShaderDescription,newCrossCompileOptions());}/// <summary>/// Creates a vertex and fragment shader pair from the given <see cref="ShaderDescription"/> pair containing SPIR-V/// bytecode or GLSL source code./// </summary>/// <param name="factory">The <see cref="ResourceFactory"/> used to compile the translated shader code.</param>/// <param name="vertexShaderDescription">The vertex shader's description. <see cref="ShaderDescription.ShaderBytes"/>/// should contain SPIR-V bytecode or Vulkan-style GLSL source code which can be compiled to SPIR-V.</param>/// <param name="fragmentShaderDescription">The fragment shader's description./// <see cref="ShaderDescription.ShaderBytes"/> should contain SPIR-V bytecode or Vulkan-style GLSL source code which/// can be compiled to SPIR-V.</param>/// <param name="options">The <see cref="CrossCompileOptions"/> which will control the parameters used to translate the/// shaders from SPIR-V to the target language.</param>/// <returns>A two-element array, containing the vertex shader (element 0) and the fragment shader (element 1).</returns>publicstaticShader[]CrossCompile(thisResourceFactoryfactory,ShaderDescriptionvertexShaderDescription,ShaderDescriptionfragmentShaderDescription,CrossCompileOptionsoptions){options.NormalizeResourceNames=true;GraphicsBackendbackend=factory.BackendType;if(backend==GraphicsBackend.Vulkan){vertexShaderDescription.ShaderBytes=EnsureSpirv(backend,vertexShaderDescription);fragmentShaderDescription.ShaderBytes=EnsureSpirv(backend,fragmentShaderDescription);returnnewShader[]{factory.CreateShader(refvertexShaderDescription),factory.CreateShader(reffragmentShaderDescription)};}CrossCompileTargettarget=GetCompilationTarget(factory.BackendType);VertexFragmentCompilationResultcompilationResult=SpirvCompilation.CompileVertexFragment(vertexShaderDescription.ShaderBytes,fragmentShaderDescription.ShaderBytes,target,options);stringvertexEntryPoint=(backend==GraphicsBackend.Metal&&vertexShaderDescription.EntryPoint=="main")?"main0":vertexShaderDescription.EntryPoint;byte[]vertexBytes=GetBytes(backend,compilationResult.VertexShader);ShadervertexShader=factory.CreateShader(newShaderDescription(vertexShaderDescription.Stage,vertexBytes,vertexEntryPoint){Debug=vertexShaderDescription.Debug});stringfragmentEntryPoint=(backend==GraphicsBackend.Metal&&fragmentShaderDescription.EntryPoint=="main")?"main0":fragmentShaderDescription.EntryPoint;byte[]fragmentBytes=GetBytes(backend,compilationResult.FragmentShader);ShaderfragmentShader=factory.CreateShader(newShaderDescription(fragmentShaderDescription.Stage,fragmentBytes,fragmentEntryPoint){Debug=fragmentShaderDescription.Debug});returnnewShader[]{vertexShader,fragmentShader};}/// <summary>/// Creates a compute shader from the given <see cref="ShaderDescription"/> containing SPIR-V bytecode or GLSL source/// code./// </summary>/// <param name="factory">The <see cref="ResourceFactory"/> used to compile the translated shader code.</param>/// <param name="computeShaderDescription">The compute shader's description./// <see cref="ShaderDescription.ShaderBytes"/> should contain SPIR-V bytecode or Vulkan-style GLSL source code which/// can be compiled to SPIR-V.</param>/// <returns>The compiled compute <see cref="Shader"/>.</returns>publicstaticShaderCrossCompile(thisResourceFactoryfactory,ShaderDescriptioncomputeShaderDescription){returnCrossCompile(factory,computeShaderDescription,newCrossCompileOptions());}/// <summary>/// Creates a compute shader from the given <see cref="ShaderDescription"/> containing SPIR-V bytecode or GLSL source/// code./// </summary>/// <param name="factory">The <see cref="ResourceFactory"/> used to compile the translated shader code.</param>/// <param name="computeShaderDescription">The compute shader's description./// <see cref="ShaderDescription.ShaderBytes"/> should contain SPIR-V bytecode or Vulkan-style GLSL source code which/// can be compiled to SPIR-V.</param>/// <param name="options">The <see cref="CrossCompileOptions"/> which will control the parameters used to translate the/// shaders from SPIR-V to the target language.</param>/// <returns>The compiled compute <see cref="Shader"/>.</returns>publicstaticShaderCrossCompile(thisResourceFactoryfactory,ShaderDescriptioncomputeShaderDescription,CrossCompileOptionsoptions){GraphicsBackendbackend=factory.BackendType;if(backend==GraphicsBackend.Vulkan){computeShaderDescription.ShaderBytes=EnsureSpirv(backend,computeShaderDescription);returnfactory.CreateShader(refcomputeShaderDescription);}CrossCompileTargettarget=GetCompilationTarget(factory.BackendType);ComputeCompilationResultcompilationResult=SpirvCompilation.CompileCompute(computeShaderDescription.ShaderBytes,target,options);stringcomputeEntryPoint=(backend==GraphicsBackend.Metal&&computeShaderDescription.EntryPoint=="main")?"main0":computeShaderDescription.EntryPoint;byte[]computeBytes=GetBytes(backend,compilationResult.ComputeShader);returnfactory.CreateShader(newShaderDescription(computeShaderDescription.Stage,computeBytes,computeEntryPoint){Debug=computeShaderDescription.Debug});}privatestaticunsafebyte[]EnsureSpirv(GraphicsBackendbackend,ShaderDescriptiondescription){if(HasSpirvHeader(description.ShaderBytes)){returndescription.ShaderBytes;}else{varsrc=GetSource(backend,description.ShaderBytes);varresult=SpirvCompilation.CompileGlslToSpirv(src,null,description.Stage,newGlslCompileOptions(description.Debug));returnresult.SpirvBytes;}}privatestaticboolHasSpirvHeader(byte[]bytes){returnbytes.Length>4&&bytes[0]==0x03&&bytes[1]==0x02&&bytes[2]==0x23&&bytes[3]==0x07;}privatestaticbyte[]GetBytes(GraphicsBackendbackend,stringcode){switch(backend){caseGraphicsBackend.Direct3D11:caseGraphicsBackend.OpenGL:caseGraphicsBackend.OpenGLES:returnEncoding.ASCII.GetBytes(code);caseGraphicsBackend.Metal:returnEncoding.UTF8.GetBytes(code);default:thrownewSpirvCompilationException($"Invalid GraphicsBackend: {backend}");}}privatestaticstringGetSource(GraphicsBackendbackend,byte[]code){switch(backend){caseGraphicsBackend.Direct3D11:caseGraphicsBackend.OpenGL:caseGraphicsBackend.OpenGLES:returnEncoding.ASCII.GetString(code);caseGraphicsBackend.Metal:returnEncoding.UTF8.GetString(code);default:thrownewSpirvCompilationException($"Invalid GraphicsBackend: {backend}");}}privatestaticCrossCompileTargetGetCompilationTarget(GraphicsBackendbackend){switch(backend){caseGraphicsBackend.Direct3D11:returnCrossCompileTarget.HLSL;caseGraphicsBackend.OpenGL:returnCrossCompileTarget.GLSL;caseGraphicsBackend.Metal:returnCrossCompileTarget.MSL;caseGraphicsBackend.OpenGLES:returnCrossCompileTarget.ESSL;default:thrownewSpirvCompilationException($"Invalid GraphicsBackend: {backend}");}}}
The text was updated successfully, but these errors were encountered:
On the mangled names issue - just a speculation, but I'm guessing it could be because of GLSL->SPV compilation methods passing debug output parameter as value of target == CrossCompileTarget.GLSL || target == CrossCompileTarget.ESSL instead of Debug flag that's passed in with the struct (which explains why I can see 'normal' sources when running under OpenGL).
Maybe it should be exposed as an additional method parameter instead?
When passing a ShaderDescription struct to CreateFromSpirv extension method, Debug flag from passed struct is not used, which makes me unable to view and debug DX11 shaders under RenderDoc.
The relevant lines:
veldrid-spirv/src/Veldrid.SPIRV/ResourceFactoryExtensions.cs
Line 72 in a872acf
veldrid-spirv/src/Veldrid.SPIRV/ResourceFactoryExtensions.cs
Line 81 in a872acf
veldrid-spirv/src/Veldrid.SPIRV/ResourceFactoryExtensions.cs
Line 138 in a872acf
When corresponding Debug value is passed to resulting structs, I'm able to see and edit shader sources - although all identifiers are mangled, it's better than nothing.
P.S.: Until it's implemented upstream, I hacked up a version of that extension class that uses the passed flag:
The text was updated successfully, but these errors were encountered: