Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto write shader input uniform value #127

Open
TristanCacqueray opened this issue Jun 3, 2020 · 5 comments
Open

Howto write shader input uniform value #127

TristanCacqueray opened this issue Jun 3, 2020 · 5 comments

Comments

@TristanCacqueray
Copy link
Contributor

Would it be possible to add some documentations and/or a function to update an uniform value? If I understand correctly the code in resize/Main.hs, the Julia shader Frame uniform is updated using:

          allocaBytes constantBytes $ \p -> do
            liftIO $ poke (p `plusPtr` 0) frameScale
            liftIO $ poke (p `plusPtr` 8) frameOffset
            liftIO $ poke (p `plusPtr` 16) c
            liftIO $ poke (p `plusPtr` 24) escapeRadius
            cmdPushConstants' fJuliaPipelineLayout
                              SHADER_STAGE_COMPUTE_BIT
                              0
                              constantBytes
                              p

I'm looking for replacing opengl (example here), and I am not sure what is the vulkan equivalent of Graphics.GL.Core31.glUniform2f.

Thank you!

@expipiplus1
Copy link
Owner

Yeah, that code is updating the push constant. I'd recommend looking up the appropriate section in any vulkan tutorial as the C commands will map 1-1 with the functions in this library.

I do think that some utilities to go from haskell records to the following would be an excellent fit for the utils library in this repo.

  • descriptor set
  • code to set such uniforms
  • glsl/hlsl to use

@expipiplus1
Copy link
Owner

https://vulkan-tutorial.com/Uniform_buffers/Descriptor_layout_and_buffer, this page and the next one deal with using UBOs to pass data to shaders. Perhaps another valuable addition to this repo would be going through a page like that and making note of where the haskell code and c++ differ non-trivially. It should be a small diff

  • replacing explicit pairs to create/destroy with the with functions
  • linear instead of glm

Also: if you use a UBO instead of push constants you should check out the VulkanMemoryAllocator library which makes allocating buffers a lot easier.

@dpwiz
Copy link
Collaborator

dpwiz commented Jun 4, 2020

Updating UBOs is really just pokeing things at correct offsets/alignment. The big deal is setting up all the necessary preparations and wrapping your head over what exactly happens when.

You can inspect my playground for buffer code and descriptor setup, but I expect it to be overwhelming until you plow through the tutorial mentioned. Or you may cheat and try not become confused by reading my haskell rendition of it 😅

@dpwiz
Copy link
Collaborator

dpwiz commented Jun 4, 2020

linear instead of glm

Btw, linear matrices appear to be in wrong order (row vs column major) and have to be transposed. I made a library to deal with projections and preparing tons of mat4 as fast as possible.

@TristanCacqueray
Copy link
Contributor Author

That is amazing, thank you for the details and tutorial links. That seems like valuable information for users of this library, perhaps it would be good enough to add those reference to the README, at least to help user like me who only know OpenGL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants