MySchoolEngine / GLEngine

The goal of this repository is to build rendering focused game engine. Feel free to join me and extend this project.
https://myschoolengine.github.io/GLEngine-Documentation/
Other
21 stars 1 forks source link

Shader system for Vulkan #102

Open RohacekD opened 3 years ago

RohacekD commented 3 years ago

I would like to be able to use the same shader definitions as in OpenGL. This consists of multiple tasks.

  1. Constant buffers Vulkan doesn't like free uniforms so everything has to be in some buffer.
  2. Generate SPIR-V shaders from current definitions I need to first take XML, read all files in the same way as in OpenGL, preprocess them and then compile with Vulkan tool "glslc". (https://vulkan-tutorial.com/en/Drawing_a_triangle/Graphics_pipeline_basics/Shader_modules) Maybe somehow integrate whole glslc into my engine.
  3. Load those SPIR-V shaders into the engine.

BONUS - Some filesystem watcher would be nice. E.g. OpenGL implementation.

RohacekD commented 3 years ago

So far I worked on the 2nd task. I have a separate program, which takes definition from OpenGL version, creates intermediate (preprocessed) files and also generates a bat file to run glsc.exe on them.

C:/VulkanSDK/Bin/glslc.exe -fshader-stage=vertex basic/Vertex.glsl -o Vertex.spv
C:/VulkanSDK/Bin/glslc.exe -fshader-stage=fragment basic/Fragment.glsl -o Fragment.spv
pause
RohacekD commented 3 years ago

And it seems like a lot have changed between opengl and vulkan 😢 basic/Vertex.glsl:2: error: '#extension' : extension not supported: GL_ARB_bindless_texture basic/Vertex.glsl:4: warning: attribute deprecated in version 130; may be removed in future release basic/Vertex.glsl:4: error: 'attribute' : no longer supported in core profile; removed in version 420 basic/Vertex.glsl:4: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:5: warning: attribute deprecated in version 130; may be removed in future release basic/Vertex.glsl:5: error: 'attribute' : no longer supported in core profile; removed in version 420 basic/Vertex.glsl:5: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:6: warning: attribute deprecated in version 130; may be removed in future release basic/Vertex.glsl:6: error: 'attribute' : no longer supported in core profile; removed in version 420 basic/Vertex.glsl:6: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:7: warning: attribute deprecated in version 130; may be removed in future release basic/Vertex.glsl:7: error: 'attribute' : no longer supported in core profile; removed in version 420 basic/Vertex.glsl:7: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:8: warning: attribute deprecated in version 130; may be removed in future release basic/Vertex.glsl:8: error: 'attribute' : no longer supported in core profile; removed in version 420 basic/Vertex.glsl:8: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:12: error: 'binding' : uniform/buffer blocks require layout(binding=X) basic/Vertex.glsl:24: error: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan basic/Vertex.glsl:27: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:28: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:29: error: 'location' : SPIR-V requires location for user input/output basic/Vertex.glsl:30: error: 'location' : SPIR-V requires location for user input/output 5 warnings and 17 errors generated.

F:\workspaces\Vulkan\data\obj\shaders\compile>C:/VulkanSDK/Bin/glslc.exe -fshader-stage=fragment basic/Fragment.glsl -o Fragment.spv basic/Fragment.glsl:2: error: '#extension' : extension not supported: GL_ARB_bindless_texture basic/Fragment.glsl:5: error: 'binding' : uniform/buffer blocks require layout(binding=X) basic/Fragment.glsl:17: error: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan basic/Fragment.glsl:18: error: 'binding' : sampler/texture/image requires layout(binding=X) basic/Fragment.glsl:20: error: 'location' : SPIR-V requires location for user input/output basic/Fragment.glsl:21: error: 'location' : SPIR-V requires location for user input/output basic/Fragment.glsl:22: error: 'location' : SPIR-V requires location for user input/output basic/Fragment.glsl:24: error: 'location' : SPIR-V requires location for user input/output basic/Fragment.glsl:53: error: 'ltc' : member of block cannot be or contain a sampler, image, or atomic_uint type basic/Fragment.glsl:54: error: 'ltcMag' : member of block cannot be or contain a sampler, image, or atomic_uint type basic/Fragment.glsl:53: error: 'binding' : sampler/texture/image requires layout(binding=X) basic/Fragment.glsl:54: error: 'binding' : sampler/texture/image requires layout(binding=X) basic/Fragment.glsl:49: error: 'binding' : uniform/buffer blocks require layout(binding=X)

RohacekD commented 3 years ago

error: 'location' : SPIR-V requires location for user input/output should be fixed by now error: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan is part of 1) basic/Vertex.glsl:2: error: '#extension' : extension not supported: GL_ARB_bindless_texture should be solved through #ifdef statement in preprocessor

RohacekD commented 3 years ago

basic/Vertex.glsl:2: error: '#extension' : extension not supported: GL_ARB_bindless_texture fixed for now