LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.1k stars 139 forks source link

ShaderReflection without shader initialization #63

Closed duckdoom4 closed 1 year ago

duckdoom4 commented 3 years ago

So I'm trying to generate Shader/Material/Resources using shader reflection. I already did this before and had an hlsl solution.

Looking through the code I found out you can actually use ShaderProgram::Reflect() to do exactly that, but now I have a minor problem.

I need to create and initialize a shader whenever I want to use shader reflection to create the actual shader.

From looking through the code I can see that you only need the shader byte code which is generated using the shader compiler.

Unfortunately I don't see any way to just compile the shader and use the byte code to reflect.

Am I missing something? If not could you make this possible by splitting the compiler and reflection from the shader resource?

LukasBanana commented 3 years ago

If you have the compile the shader with LLGL just create a ShaderProgram to get the reflection, then create another one with that reflection information, and delete the old instance. Otherwise you have to compile the shaders outside of LLGL with FXC or DXC for instance to obtain the byte code. In some backends like OpenGL you need to compile and link the shaders before you can do any reflection on those shader objects. In those cases you would also simply create multiple shader objects and delete the ones that are used for intermediate results only.

duckdoom4 commented 3 years ago

Thanks for the quick reply. I did look at the OpenGL implementation but clearly not close enough. Now it's clear to me why you chose this design and it also means that if I wish to support OpenGL I need to create an intermediate shader anyway. I'll have to accept this "waste" of resources. I should move this process to pre-compile time anyway. (As in don't do this at runtime at application startup which I do currently)

Now that I have you here anyway, are you planning on adding support for the ray tracing library in D3D12 and vulkan?

LukasBanana commented 3 years ago

Now that I have you here anyway, are you planning on adding support for the ray tracing library in D3D12 and vulkan?

I'm only doing occasional bug fixing on this repository, but no active development. I still review and accept pull requests though.