Skip to content

Commit 337f7c7

Browse files
michaelHADSKDDoSdoug-walker
authored
Adsk Contrib - Vulkan support (#2176)
* Support for Vulkan GLSL (not yet active). Signed-off-by: Michael Horsch <[email protected]> * Activated Vulkan shader generation, fixed bool handling. Signed-off-by: Michael Horsch <[email protected]> * Replaced tabs with spaces. Signed-off-by: Michael Horsch <[email protected]> * Documentation added for new methods, return values and member variables. Signed-off-by: Michael Horsch <[email protected]> * Padding and alignment for uniform buffers optimized, smaller fixes. Signed-off-by: Michael Horsch <[email protected]> * Restored ociodisplay and removed code for testing. Signed-off-by: Michael Horsch <[email protected]> * Added functions to set/get descriptor set index and texture binding start index. Signed-off-by: Michael Horsch <[email protected]> * Added exception for invalid texture binding index, smaller fixes. Signed-off-by: Michael Horsch <[email protected]> * Suggested documentation update Co-authored-by: Aleksi Sapon <[email protected]> Signed-off-by: Michael Horsch <[email protected]> * Merge conflicts fixed. Signed-off-by: Michael Horsch <[email protected]> * Fixed missing space for non-Vulkan GLSL uniforms. Signed-off-by: Michael Horsch <[email protected]> * Fixed descriptorSetIndex for textures. Signed-off-by: Michael Horsch <[email protected]> * Fixed uniform buffer array stride and size. Signed-off-by: Michael Horsch <[email protected]> * Fixes documentation, formatting. Adds test and py functions. Signed-off-by: Michael Horsch <[email protected]> * Added missing python bindings. Signed-off-by: Michael Horsch <[email protected]> * Fixed Metal unit tests. Signed-off-by: Michael Horsch <[email protected]> * Fixes for MyOSLShaderCreator. Signed-off-by: Michael Horsch <[email protected]> * Fixed spaces at beginning of uniform declarations. Signed-off-by: Michael Horsch <[email protected]> * Fixed Vulkan unit test. Signed-off-by: Michael Horsch <[email protected]> --------- Signed-off-by: Michael Horsch <[email protected]> Co-authored-by: Aleksi Sapon <[email protected]> Co-authored-by: Doug Walker <[email protected]>
1 parent 7e7f2de commit 337f7c7

File tree

23 files changed

+512
-173
lines changed

23 files changed

+512
-173
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,23 @@ class OCIOEXPORT GpuShaderCreator
33833383
/// Set a prefix to the resource name
33843384
void setResourcePrefix(const char * prefix) noexcept;
33853385

3386+
/**
3387+
* \brief Set the descriptor set index and texture binding start index to use for the shader program.
3388+
*
3389+
* \note Only supported for shading languages, such as Vulkan, that use descriptor sets and texture bindings.
3390+
*
3391+
* \param index The descriptor set index to use.
3392+
* \param textureBindingStart The texture binding start index to use. The default index starts at 1
3393+
* and is incremented by 1 for each texture. Otherwise, the texture binding starts
3394+
* at textureBindingStart and is incremented by 1 for each texture.
3395+
* The binding of a texture is equal to the texture index + textureBindingStart.
3396+
* The texture binding start index must be greater than 0, as binding 0 is reserved
3397+
* for the uniform buffer binding
3398+
* */
3399+
void setDescriptorSetIndex(unsigned index, unsigned textureBindingStart = 1);
3400+
unsigned getDescriptorSetIndex() const noexcept;
3401+
unsigned getTextureBindingStart() const noexcept;
3402+
33863403
virtual const char * getCacheID() const noexcept;
33873404

33883405
/// Start to collect the shader data.
@@ -3426,13 +3443,23 @@ class OCIOEXPORT GpuShaderCreator
34263443
virtual bool addUniform(const char * name,
34273444
const Float3Getter & getFloat3) = 0;
34283445

3446+
/// The size of the vector can be smaller than the size of the corresponding
3447+
/// array that is declared in the shader. The parameter maxSize must be used
3448+
/// to pass the size of the array declared in the shader. This is important for
3449+
/// being able to calculate the correct uniform buffer offset for subsequent uniforms
34293450
virtual bool addUniform(const char * name,
34303451
const SizeGetter & getSize,
3431-
const VectorFloatGetter & getVectorFloat) = 0;
3452+
const VectorFloatGetter & getVectorFloat,
3453+
const unsigned maxSize) = 0;
34323454

3455+
/// The size of the vector can be smaller than the size of the corresponding
3456+
/// array that is declared in the shader. The parameter maxSize must be used
3457+
/// to pass the size of the array declared in the shader. This is important for
3458+
/// being able to calculate the correct uniform buffer offset for subsequent uniforms
34333459
virtual bool addUniform(const char * name,
34343460
const SizeGetter & getSize,
3435-
const VectorIntGetter & getVectorInt) = 0;
3461+
const VectorIntGetter & getVectorInt,
3462+
const unsigned maxSize) = 0;
34363463

34373464
/// Adds the property (used internally).
34383465
void addDynamicProperty(DynamicPropertyRcPtr & prop);
@@ -3468,14 +3495,17 @@ class OCIOEXPORT GpuShaderCreator
34683495
* \note
34693496
* The 'values' parameter contains the LUT data which must be used as-is as the dimensions and
34703497
* origin are hard-coded in the fragment shader program. So, it means one GPU texture per entry.
3498+
*
3499+
* \return Index of the texture. For shading languages using explicit texture bindings, the return
3500+
* value is the same as the texture binding index in the generated shader program.
34713501
**/
3472-
virtual void addTexture(const char * textureName,
3473-
const char * samplerName,
3474-
unsigned width, unsigned height,
3475-
TextureType channel,
3476-
TextureDimensions dimensions,
3477-
Interpolation interpolation,
3478-
const float * values) = 0;
3502+
virtual unsigned addTexture(const char * textureName,
3503+
const char * samplerName,
3504+
unsigned width, unsigned height,
3505+
TextureType channel,
3506+
TextureDimensions dimensions,
3507+
Interpolation interpolation,
3508+
const float * values) = 0;
34793509

34803510
/**
34813511
* Add a 3D texture with RGB channel type.
@@ -3484,15 +3514,19 @@ class OCIOEXPORT GpuShaderCreator
34843514
* The 'values' parameter contains the 3D LUT data which must be used as-is as the dimension
34853515
* and origin are hard-coded in the fragment shader program. So, it means one GPU 3D texture
34863516
* per entry.
3517+
*
3518+
* \return Index of the texture. For shading languages using explicit texture bindings, the return
3519+
* value is the same as the texture binding index in the generated shader program.
34873520
**/
3488-
virtual void add3DTexture(const char * textureName,
3521+
virtual unsigned add3DTexture(const char * textureName,
34893522
const char * samplerName,
34903523
unsigned edgelen,
34913524
Interpolation interpolation,
34923525
const float * values) = 0;
34933526

34943527
// Methods to specialize parts of a OCIO shader program
3495-
virtual void addToDeclareShaderCode(const char * shaderCode);
3528+
virtual void addToParameterDeclareShaderCode(const char * shaderCode);
3529+
virtual void addToTextureDeclareShaderCode(const char* shaderCode);
34963530
virtual void addToHelperShaderCode(const char * shaderCode);
34973531
virtual void addToFunctionHeaderShaderCode(const char * shaderCode);
34983532
virtual void addToFunctionShaderCode(const char * shaderCode);
@@ -3506,7 +3540,8 @@ class OCIOEXPORT GpuShaderCreator
35063540
* to change some parts. Some product integrations add the color processing
35073541
* within a client shader program, imposing constraints requiring this flexibility.
35083542
*/
3509-
virtual void createShaderText(const char * shaderDeclarations,
3543+
virtual void createShaderText(const char * shaderParameterDeclarations,
3544+
const char * shaderTextureDeclarations,
35103545
const char * shaderHelperMethods,
35113546
const char * shaderFunctionHeader,
35123547
const char * shaderFunctionBody,
@@ -3695,10 +3730,16 @@ class OCIOEXPORT GpuShaderDesc : public GpuShaderCreator
36953730
* * UNIFORM_FLOAT3: m_getFloat3.
36963731
* * UNIFORM_VECTOR_FLOAT: m_vectorFloat.
36973732
* * UNIFORM_VECTOR_INT: m_vectorInt.
3733+
*
3734+
* The m_bufferOffset is the offset in bytes from the start of the uniform buffer.
3735+
* For shading languages that use uniform buffers, the offset can be used to
3736+
* determine the location of the uniform in the buffer and fill it with the
3737+
* corresponding data.
36983738
*/
36993739
struct UniformData
37003740
{
37013741
UniformDataType m_type{ UNIFORM_UNKNOWN };
3742+
std::size_t m_bufferOffset{};
37023743
DoubleGetter m_getDouble{};
37033744
BoolGetter m_getBool{};
37043745
Float3Getter m_getFloat3{};
@@ -3717,6 +3758,16 @@ class OCIOEXPORT GpuShaderDesc : public GpuShaderCreator
37173758
/// Returns name of uniform and data as parameter.
37183759
virtual const char * getUniform(unsigned index, UniformData & data) const = 0;
37193760

3761+
/**
3762+
* For shading languages that use uniform buffers, a uniform buffer
3763+
* containing all uniforms is generated in the shader code. This method can
3764+
* be used to create a buffer of the same size in the client code that can
3765+
* be filled with the corresponding data.
3766+
*
3767+
* \return Size of the uniform buffer in bytes
3768+
**/
3769+
virtual std::size_t getUniformBufferSize() const noexcept = 0;
3770+
37203771
// 1D lut related methods
37213772
virtual unsigned getNumTextures() const noexcept = 0;
37223773
virtual void getTexture(unsigned index,

include/OpenColorIO/OpenColorTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ enum GpuLanguage
449449
GPU_LANGUAGE_GLSL_1_2, ///< OpenGL Shading Language
450450
GPU_LANGUAGE_GLSL_1_3, ///< OpenGL Shading Language
451451
GPU_LANGUAGE_GLSL_4_0, ///< OpenGL Shading Language
452+
GPU_LANGUAGE_GLSL_VK_4_6, ///< OpenGL Shading Language for Vulkan
452453
GPU_LANGUAGE_HLSL_SM_5_0, ///< DirectX High Level Shading Language
453454
LANGUAGE_OSL_1, ///< Open Shading Language
454455
GPU_LANGUAGE_GLSL_ES_1_0, ///< OpenGL ES Shading Language

0 commit comments

Comments
 (0)