Skip to content

Conversation

michaelHADSK
Copy link

This PR adds Vulkan support to OCIO.

  • Added GPU_LANGUAGE_GLSL_VK_4_6 and the corresponding functionality
  • Split up declare shader code into textures and parameters
  • Added code to add vulkan uniform buffer code around variables
  • Functions to add textures now return the index of the texture which is used as the binding index in the shader code
  • UniformData now has a bufferOffset to be able to copy the uniform data to the right place in the uniform buffer
  • There's a new function to return the size of the generated uniform buffer
  • There are new functions to to set and get the Vulkan descriptor set index and texture binding start index
  • Added a castToBool method to the GPUShaderText. Support for bools in uniform buffers is unfortunately not well defined/supported in Vulkan, that's why they are declared as int variables. Since there is no implicit cast to bool from int in GLSL, I had to add the explicit cast at some places. This is not so nice because other coders need to be aware that this is required for Vulkan, other ideas on how to deal with that are appreciated.

@mrvux
Copy link

mrvux commented Jul 27, 2025

As requested, here is my feedback on the PR (forked the branch to check the code).
It's very similar to what I did in my personal fork for dx11, with a few key differences (given the fact that vulkan GPU_LANGUAGE_GLSL_VK_4_6 got added it could go away with it, in my case it was not possible):

  1. In case of dx11/dx12, sampler states live in a separate register space than resources, so another index was required

void setDescriptorSetIndex(unsigned index, unsigned textureBindingStart = 1);

so for direct3d an additional samplerBindingStart is required.

Also note that registers in Direct3d are zero indexed

Texture2D myLut : register(t0); // (up to 127) SamplerState myLutSampler : register(s2); //up to 15

  1. Given that in my case another enum was not required and I wanted not to break existing implementations (to have the implementation use GPU_LANGUAGE_HLSL_SM_5_0).

There is another function in GpuShaderCreator called :

void setUseExplicitBindings(bool useExplicitBindings);

This is off by default and keeps explicit implementations to use the default "automatic" bindings" (eg : current implementation) , and use explicit as an Opt-In.

  1. The change, given we add samplerBindingStart in the gpu creator, would fix Direct3d12 in a nearly identical way as per Vulkan:

kw << "layout(set=" << descriptorSetIndex << ", binding = " << textureIndex << ") ";

becomes :

t << "Texture" << N << "D " << textureName : register(t" << textureIndex << ", space" << descriptorSetIndex << ");"

It would require a new enum in that case GPU_LANGUAGE_HLSL_SM_5_1

But given that it would not break the GpuCreator interface, this could be implemented at a later stage with no risk of breaking existing implementations.

@doug-walker doug-walker changed the title Vulkan support Adsk Contrib - Vulkan support Jul 27, 2025
void GpuShaderText::declareUniformFloat(const std::string & uniformName)
{
newLine() << (m_lang == GPU_LANGUAGE_MSL_2_0 ? "" : "uniform ") << floatKeyword() << " " << uniformName << ";";
std::string uniformDeclString("uniform");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor but should we add the space here and other declaration methods to avoid having declarations beginning with a white space like we see in the tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work. I agree that the white space at the beginning is not so nice, I'll try to fix it before the 2.5 release.

michaelHADSK and others added 18 commits September 19, 2025 17:55
Signed-off-by: Michael Horsch <[email protected]>
Co-authored-by: Aleksi Sapon <[email protected]>
Signed-off-by: Michael Horsch <[email protected]>
Signed-off-by: Michael Horsch <[email protected]>
Signed-off-by: Michael Horsch <[email protected]>
Signed-off-by: Michael Horsch <[email protected]>
Signed-off-by: Michael Horsch <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants