diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index 8b76fb22e7..5495feefe5 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -3383,6 +3383,23 @@ class OCIOEXPORT GpuShaderCreator /// Set a prefix to the resource name void setResourcePrefix(const char * prefix) noexcept; + /** + * \brief Set the descriptor set index and texture binding start index to use for the shader program. + * + * \note Only supported for shading languages, such as Vulkan, that use descriptor sets and texture bindings. + * + * \param index The descriptor set index to use. + * \param textureBindingStart The texture binding start index to use. The default index starts at 1 + * and is incremented by 1 for each texture. Otherwise, the texture binding starts + * at textureBindingStart and is incremented by 1 for each texture. + * The binding of a texture is equal to the texture index + textureBindingStart. + * The texture binding start index must be greater than 0, as binding 0 is reserved + * for the uniform buffer binding + * */ + void setDescriptorSetIndex(unsigned index, unsigned textureBindingStart = 1); + unsigned getDescriptorSetIndex() const noexcept; + unsigned getTextureBindingStart() const noexcept; + virtual const char * getCacheID() const noexcept; /// Start to collect the shader data. @@ -3426,13 +3443,23 @@ class OCIOEXPORT GpuShaderCreator virtual bool addUniform(const char * name, const Float3Getter & getFloat3) = 0; + /// The size of the vector can be smaller than the size of the corresponding + /// array that is declared in the shader. The parameter maxSize must be used + /// to pass the size of the array declared in the shader. This is important for + /// being able to calculate the correct uniform buffer offset for subsequent uniforms virtual bool addUniform(const char * name, const SizeGetter & getSize, - const VectorFloatGetter & getVectorFloat) = 0; + const VectorFloatGetter & getVectorFloat, + const unsigned maxSize) = 0; + /// The size of the vector can be smaller than the size of the corresponding + /// array that is declared in the shader. The parameter maxSize must be used + /// to pass the size of the array declared in the shader. This is important for + /// being able to calculate the correct uniform buffer offset for subsequent uniforms virtual bool addUniform(const char * name, const SizeGetter & getSize, - const VectorIntGetter & getVectorInt) = 0; + const VectorIntGetter & getVectorInt, + const unsigned maxSize) = 0; /// Adds the property (used internally). void addDynamicProperty(DynamicPropertyRcPtr & prop); @@ -3468,14 +3495,17 @@ class OCIOEXPORT GpuShaderCreator * \note * The 'values' parameter contains the LUT data which must be used as-is as the dimensions and * origin are hard-coded in the fragment shader program. So, it means one GPU texture per entry. + * + * \return Index of the texture. For shading languages using explicit texture bindings, the return + * value is the same as the texture binding index in the generated shader program. **/ - virtual void addTexture(const char * textureName, - const char * samplerName, - unsigned width, unsigned height, - TextureType channel, - TextureDimensions dimensions, - Interpolation interpolation, - const float * values) = 0; + virtual unsigned addTexture(const char * textureName, + const char * samplerName, + unsigned width, unsigned height, + TextureType channel, + TextureDimensions dimensions, + Interpolation interpolation, + const float * values) = 0; /** * Add a 3D texture with RGB channel type. @@ -3484,15 +3514,19 @@ class OCIOEXPORT GpuShaderCreator * The 'values' parameter contains the 3D LUT data which must be used as-is as the dimension * and origin are hard-coded in the fragment shader program. So, it means one GPU 3D texture * per entry. + * + * \return Index of the texture. For shading languages using explicit texture bindings, the return + * value is the same as the texture binding index in the generated shader program. **/ - virtual void add3DTexture(const char * textureName, + virtual unsigned add3DTexture(const char * textureName, const char * samplerName, unsigned edgelen, Interpolation interpolation, const float * values) = 0; // Methods to specialize parts of a OCIO shader program - virtual void addToDeclareShaderCode(const char * shaderCode); + virtual void addToParameterDeclareShaderCode(const char * shaderCode); + virtual void addToTextureDeclareShaderCode(const char* shaderCode); virtual void addToHelperShaderCode(const char * shaderCode); virtual void addToFunctionHeaderShaderCode(const char * shaderCode); virtual void addToFunctionShaderCode(const char * shaderCode); @@ -3506,7 +3540,8 @@ class OCIOEXPORT GpuShaderCreator * to change some parts. Some product integrations add the color processing * within a client shader program, imposing constraints requiring this flexibility. */ - virtual void createShaderText(const char * shaderDeclarations, + virtual void createShaderText(const char * shaderParameterDeclarations, + const char * shaderTextureDeclarations, const char * shaderHelperMethods, const char * shaderFunctionHeader, const char * shaderFunctionBody, @@ -3695,10 +3730,16 @@ class OCIOEXPORT GpuShaderDesc : public GpuShaderCreator * * UNIFORM_FLOAT3: m_getFloat3. * * UNIFORM_VECTOR_FLOAT: m_vectorFloat. * * UNIFORM_VECTOR_INT: m_vectorInt. + * + * The m_bufferOffset is the offset in bytes from the start of the uniform buffer. + * For shading languages that use uniform buffers, the offset can be used to + * determine the location of the uniform in the buffer and fill it with the + * corresponding data. */ struct UniformData { UniformDataType m_type{ UNIFORM_UNKNOWN }; + std::size_t m_bufferOffset{}; DoubleGetter m_getDouble{}; BoolGetter m_getBool{}; Float3Getter m_getFloat3{}; @@ -3717,6 +3758,16 @@ class OCIOEXPORT GpuShaderDesc : public GpuShaderCreator /// Returns name of uniform and data as parameter. virtual const char * getUniform(unsigned index, UniformData & data) const = 0; + /** + * For shading languages that use uniform buffers, a uniform buffer + * containing all uniforms is generated in the shader code. This method can + * be used to create a buffer of the same size in the client code that can + * be filled with the corresponding data. + * + * \return Size of the uniform buffer in bytes + **/ + virtual std::size_t getUniformBufferSize() const noexcept = 0; + // 1D lut related methods virtual unsigned getNumTextures() const noexcept = 0; virtual void getTexture(unsigned index, diff --git a/include/OpenColorIO/OpenColorTypes.h b/include/OpenColorIO/OpenColorTypes.h index 21243eb363..4893c78234 100644 --- a/include/OpenColorIO/OpenColorTypes.h +++ b/include/OpenColorIO/OpenColorTypes.h @@ -449,6 +449,7 @@ enum GpuLanguage GPU_LANGUAGE_GLSL_1_2, ///< OpenGL Shading Language GPU_LANGUAGE_GLSL_1_3, ///< OpenGL Shading Language GPU_LANGUAGE_GLSL_4_0, ///< OpenGL Shading Language + GPU_LANGUAGE_GLSL_VK_4_6, ///< OpenGL Shading Language for Vulkan GPU_LANGUAGE_HLSL_SM_5_0, ///< DirectX High Level Shading Language LANGUAGE_OSL_1, ///< Open Shading Language GPU_LANGUAGE_GLSL_ES_1_0, ///< OpenGL ES Shading Language diff --git a/src/OpenColorIO/GpuShader.cpp b/src/OpenColorIO/GpuShader.cpp index 7fbc30b43a..38eda8a30e 100644 --- a/src/OpenColorIO/GpuShader.cpp +++ b/src/OpenColorIO/GpuShader.cpp @@ -35,11 +35,30 @@ static void CreateArray(const float * buf, res.resize(size); std::memcpy(&res[0], buf, size * sizeof(float)); } + +std::size_t alignOffset(std::size_t offset, std::size_t alignment) +{ + if (alignment == 0) + { + throw Exception("Alignment cannot be zero."); + } + return ((offset + alignment - 1) / alignment) * alignment; +} + } namespace GPUShaderImpl { +constexpr size_t GPU_FLOAT_SIZE = 4; +constexpr size_t GPU_FLOAT_ALIGNMENT = 4; +constexpr size_t GPU_INT_SIZE = 4; +constexpr size_t GPU_INT_ALIGNMENT = 4; +constexpr size_t GPU_VEC3_SIZE = 12; +constexpr size_t GPU_VEC3_ALIGNMENT = 16; +constexpr size_t GPU_ARRAY_ALIGNMENT = 16; +constexpr size_t GPU_ARRAY_STRIDE = 16; + class PrivateImpl { public: @@ -104,43 +123,48 @@ class PrivateImpl struct Uniform { - Uniform(const char * name, const GpuShaderCreator::DoubleGetter & getDouble) + Uniform(const char * name, const GpuShaderCreator::DoubleGetter & getDouble, std::size_t bufferOffset) : Uniform(name) { m_data.m_type = UNIFORM_DOUBLE; m_data.m_getDouble = getDouble; + m_data.m_bufferOffset = bufferOffset; } - Uniform(const char * name, const GpuShaderCreator::BoolGetter & getBool) + Uniform(const char * name, const GpuShaderCreator::BoolGetter & getBool, std::size_t bufferOffset) : Uniform(name) { m_data.m_type = UNIFORM_BOOL; m_data.m_getBool = getBool; + m_data.m_bufferOffset = bufferOffset; } - Uniform(const char * name, const GpuShaderCreator::Float3Getter & getFloat3) + Uniform(const char * name, const GpuShaderCreator::Float3Getter & getFloat3, std::size_t bufferOffset) : Uniform(name) { m_data.m_type = UNIFORM_FLOAT3; m_data.m_getFloat3 = getFloat3; + m_data.m_bufferOffset = bufferOffset; } Uniform(const char * name, const GpuShaderCreator::SizeGetter & getSize, - const GpuShaderCreator::VectorFloatGetter & getVectorFloat) + const GpuShaderCreator::VectorFloatGetter & getVectorFloat, std::size_t bufferOffset) : Uniform(name) { m_data.m_type = UNIFORM_VECTOR_FLOAT; m_data.m_vectorFloat.m_getSize = getSize; m_data.m_vectorFloat.m_getVector = getVectorFloat; + m_data.m_bufferOffset = bufferOffset; } Uniform(const char * name, const GpuShaderCreator::SizeGetter & getSize, - const GpuShaderCreator::VectorIntGetter & getVectorInt) + const GpuShaderCreator::VectorIntGetter & getVectorInt, std::size_t bufferOffset) : Uniform(name) { m_data.m_type = UNIFORM_VECTOR_INT; m_data.m_vectorInt.m_getSize = getSize; m_data.m_vectorInt.m_getVector = getVectorInt; + m_data.m_bufferOffset = bufferOffset; } const std::string m_name; @@ -161,7 +185,7 @@ class PrivateImpl typedef std::vector Uniforms; public: - PrivateImpl() : m_max1DLUTWidth(4 * 1024), m_allowTexture1D(true) {} + PrivateImpl() : m_max1DLUTWidth(4 * 1024), m_allowTexture1D(true), m_uniformBufferSize(0) {} PrivateImpl(const PrivateImpl & rhs) = delete; PrivateImpl& operator= (const PrivateImpl & rhs) = delete; @@ -175,13 +199,13 @@ class PrivateImpl inline bool getAllowTexture1D() const { return m_allowTexture1D; } inline void setAllowTexture1D(bool allowed) { m_allowTexture1D = allowed; } - void addTexture(const char * textureName, - const char * samplerName, - unsigned width, unsigned height, - GpuShaderDesc::TextureType channel, - GpuShaderDesc::TextureDimensions dimensions, - Interpolation interpolation, - const float * values) + unsigned addTexture(const char * textureName, + const char * samplerName, + unsigned width, unsigned height, + GpuShaderDesc::TextureType channel, + GpuShaderDesc::TextureDimensions dimensions, + Interpolation interpolation, + const float * values) { if(width > get1dLutMaxWidth()) { @@ -190,10 +214,11 @@ class PrivateImpl << width << " > " << get1dLutMaxWidth(); throw Exception(ss.str().c_str()); } - + unsigned textureIndex = static_cast(m_textures.size()); unsigned numDimensions = static_cast(dimensions); Texture t(textureName, samplerName, width, height, 1, channel, numDimensions, interpolation, values); m_textures.push_back(t); + return textureIndex; } void getTexture(unsigned index, @@ -243,11 +268,11 @@ class PrivateImpl values = &t.m_values[0]; } - void add3DTexture(const char * textureName, - const char * samplerName, - unsigned edgelen, - Interpolation interpolation, - const float * values) + unsigned add3DTexture(const char * textureName, + const char * samplerName, + unsigned edgelen, + Interpolation interpolation, + const float * values) { if(edgelen > get3dLutMaxLength()) { @@ -257,10 +282,12 @@ class PrivateImpl throw Exception(ss.str().c_str()); } + unsigned textureIndex = static_cast(m_textures3D.size()); Texture t(textureName, samplerName, edgelen, edgelen, edgelen, GpuShaderDesc::TEXTURE_RGB_CHANNEL, 3, interpolation, values); m_textures3D.push_back(t); + return textureIndex; } void get3DTexture(unsigned index, @@ -323,7 +350,9 @@ class PrivateImpl // Uniform is already there. return false; } - m_uniforms.emplace_back(name, getter); + m_uniformBufferSize = alignOffset(m_uniformBufferSize, GPU_FLOAT_ALIGNMENT); + m_uniforms.emplace_back(name, getter, m_uniformBufferSize); + m_uniformBufferSize += GPU_FLOAT_SIZE; return true; } @@ -334,7 +363,9 @@ class PrivateImpl // Uniform is already there. return false; } - m_uniforms.emplace_back(name, getter); + m_uniformBufferSize = alignOffset(m_uniformBufferSize, GPU_INT_ALIGNMENT); + m_uniforms.emplace_back(name, getter, m_uniformBufferSize); + m_uniformBufferSize += GPU_INT_SIZE; //bool not supported for buffered uniforms, using int instead return true; } @@ -345,35 +376,48 @@ class PrivateImpl // Uniform is already there. return false; } - m_uniforms.emplace_back(name, getter); + m_uniformBufferSize = alignOffset(m_uniformBufferSize, GPU_VEC3_ALIGNMENT); + m_uniforms.emplace_back(name, getter, m_uniformBufferSize); + m_uniformBufferSize += GPU_VEC3_SIZE; return true; } bool addUniform(const char * name, const GpuShaderCreator::SizeGetter & getSize, - const GpuShaderCreator::VectorFloatGetter & getVector) + const GpuShaderCreator::VectorFloatGetter & getVector, + const unsigned maxSize) { if (uniformNameUsed(name)) { // Uniform is already there. return false; } - m_uniforms.emplace_back(name, getSize, getVector); + m_uniformBufferSize = alignOffset(m_uniformBufferSize, GPU_ARRAY_ALIGNMENT); + m_uniforms.emplace_back(name, getSize, getVector, m_uniformBufferSize); + m_uniformBufferSize += GPU_ARRAY_STRIDE * maxSize; return true; } bool addUniform(const char * name, const GpuShaderCreator::SizeGetter & getSize, - const GpuShaderCreator::VectorIntGetter & getVectorInt) + const GpuShaderCreator::VectorIntGetter & getVectorInt, + const unsigned maxSize) { if (uniformNameUsed(name)) { // Uniform is already there. return false; } - m_uniforms.emplace_back(name, getSize, getVectorInt); + m_uniformBufferSize = alignOffset(m_uniformBufferSize, GPU_ARRAY_ALIGNMENT); + m_uniforms.emplace_back(name, getSize, getVectorInt, m_uniformBufferSize); + m_uniformBufferSize += GPU_ARRAY_STRIDE * maxSize; return true; } + + std::size_t getUniformBufferSize() const + { + return m_uniformBufferSize; + } Textures m_textures; Textures m_textures3D; Uniforms m_uniforms; @@ -392,6 +436,7 @@ class PrivateImpl } unsigned m_max1DLUTWidth; bool m_allowTexture1D; + std::size_t m_uniformBufferSize; }; } // namespace GPUShaderImpl @@ -447,18 +492,24 @@ bool GenericGpuShaderDesc::addUniform(const char * name, const Float3Getter & ge bool GenericGpuShaderDesc::addUniform(const char * name, const SizeGetter & getSize, - const VectorFloatGetter & getFloatArray) + const VectorFloatGetter & getFloatArray, + const unsigned maxSize) { - return getImplGeneric()->addUniform(name, getSize, getFloatArray); + return getImplGeneric()->addUniform(name, getSize, getFloatArray, maxSize); } bool GenericGpuShaderDesc::addUniform(const char * name, const SizeGetter & getSize, - const VectorIntGetter & getVectorInt) + const VectorIntGetter & getVectorInt, + const unsigned maxSize) { - return getImplGeneric()->addUniform(name, getSize, getVectorInt); + return getImplGeneric()->addUniform(name, getSize, getVectorInt, maxSize); } +std::size_t GenericGpuShaderDesc::getUniformBufferSize() const noexcept +{ + return getImplGeneric()->getUniformBufferSize(); +} unsigned GenericGpuShaderDesc::getTextureMaxWidth() const noexcept { @@ -485,15 +536,15 @@ unsigned GenericGpuShaderDesc::getNumTextures() const noexcept return unsigned(getImplGeneric()->m_textures.size()); } -void GenericGpuShaderDesc::addTexture(const char * textureName, - const char * samplerName, - unsigned width, unsigned height, - TextureType channel, - TextureDimensions dimensions, - Interpolation interpolation, - const float * values) +unsigned GenericGpuShaderDesc::addTexture(const char * textureName, + const char * samplerName, + unsigned width, unsigned height, + TextureType channel, + TextureDimensions dimensions, + Interpolation interpolation, + const float * values) { - getImplGeneric()->addTexture(textureName, samplerName, width, height, channel, dimensions, interpolation, values); + return getImplGeneric()->addTexture(textureName, samplerName, width, height, channel, dimensions, interpolation, values); } void GenericGpuShaderDesc::getTexture(unsigned index, @@ -517,13 +568,13 @@ unsigned GenericGpuShaderDesc::getNum3DTextures() const noexcept return unsigned(getImplGeneric()->m_textures3D.size()); } -void GenericGpuShaderDesc::add3DTexture(const char * textureName, - const char * samplerName, - unsigned edgelen, - Interpolation interpolation, - const float * values) +unsigned GenericGpuShaderDesc::add3DTexture(const char * textureName, + const char * samplerName, + unsigned edgelen, + Interpolation interpolation, + const float * values) { - getImplGeneric()->add3DTexture(textureName, samplerName, edgelen, interpolation, values); + return getImplGeneric()->add3DTexture(textureName, samplerName, edgelen, interpolation, values); } void GenericGpuShaderDesc::get3DTexture(unsigned index, diff --git a/src/OpenColorIO/GpuShader.h b/src/OpenColorIO/GpuShader.h index e9c39d56b1..8b099cc12f 100644 --- a/src/OpenColorIO/GpuShader.h +++ b/src/OpenColorIO/GpuShader.h @@ -41,15 +41,18 @@ class GenericGpuShaderDesc : public GpuShaderDesc bool addUniform(const char * name, const Float3Getter & getter) override; bool addUniform(const char * name, const SizeGetter & getSize, - const VectorFloatGetter & getVectorFloat) override; + const VectorFloatGetter & getVectorFloat, + const unsigned maxSize) override; bool addUniform(const char * name, const SizeGetter & getSize, - const VectorIntGetter & getVectorInt) override; + const VectorIntGetter & getVectorInt, + const unsigned maxSize) override; + std::size_t getUniformBufferSize() const noexcept override; // Accessors to the 1D & 2D textures built from 1D LUT // unsigned getNumTextures() const noexcept override; - void addTexture(const char * textureName, + unsigned addTexture(const char * textureName, const char * samplerName, unsigned width, unsigned height, TextureType channel, @@ -68,7 +71,7 @@ class GenericGpuShaderDesc : public GpuShaderDesc // Accessors to the 3D textures built from 3D LUT // unsigned getNum3DTextures() const noexcept override; - void add3DTexture(const char * textureName, + unsigned add3DTexture(const char * textureName, const char * samplerName, unsigned edgelen, Interpolation interpolation, diff --git a/src/OpenColorIO/GpuShaderClassWrapper.cpp b/src/OpenColorIO/GpuShaderClassWrapper.cpp index 6ca5027ee5..675bd47163 100644 --- a/src/OpenColorIO/GpuShaderClassWrapper.cpp +++ b/src/OpenColorIO/GpuShaderClassWrapper.cpp @@ -31,6 +31,7 @@ std::unique_ptr GpuShaderClassWrapper::CreateClassWrapper case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_HLSL_SM_5_0: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: diff --git a/src/OpenColorIO/GpuShaderClassWrapper.h b/src/OpenColorIO/GpuShaderClassWrapper.h index c76373db90..cbe01b3545 100644 --- a/src/OpenColorIO/GpuShaderClassWrapper.h +++ b/src/OpenColorIO/GpuShaderClassWrapper.h @@ -30,6 +30,8 @@ class GpuShaderClassWrapper virtual std::string getClassWrapperHeader(const std::string & originalHeader) = 0; virtual std::string getClassWrapperFooter(const std::string & originalFooter) = 0; + virtual bool hasClassWrapperHeader() const = 0; + virtual std::unique_ptr clone() const = 0; virtual ~GpuShaderClassWrapper() = default; @@ -51,6 +53,10 @@ class NullGpuShaderClassWrapper : public GpuShaderClassWrapper { return originalFooter; } + bool hasClassWrapperHeader() const final + { + return false; + } std::unique_ptr clone() const final; }; @@ -68,6 +74,11 @@ class OSLShaderClassWrapper : public GpuShaderClassWrapper std::string getClassWrapperHeader(const std::string & originalHeader) final; std::string getClassWrapperFooter(const std::string & originalFooter) final; + bool hasClassWrapperHeader() const final + { + return true; + } + std::unique_ptr clone() const final; private: @@ -83,6 +94,11 @@ class MetalShaderClassWrapper : public GpuShaderClassWrapper std::string getClassWrapperHeader(const std::string & originalHeader) final; std::string getClassWrapperFooter(const std::string & originalFooter) final; + bool hasClassWrapperHeader() const final + { + return true; + } + std::unique_ptr clone() const final; MetalShaderClassWrapper& operator=(const MetalShaderClassWrapper& rhs); diff --git a/src/OpenColorIO/GpuShaderDesc.cpp b/src/OpenColorIO/GpuShaderDesc.cpp index 9a35f75486..ffa9be7407 100644 --- a/src/OpenColorIO/GpuShaderDesc.cpp +++ b/src/OpenColorIO/GpuShaderDesc.cpp @@ -32,7 +32,8 @@ class GpuShaderCreator::Impl mutable std::string m_cacheID; mutable Mutex m_cacheIDMutex; - std::string m_declarations; + std::string m_parameterDeclarations; + std::string m_textureDeclarations; std::string m_helperMethods; std::string m_functionHeader; std::string m_functionBody; @@ -45,6 +46,9 @@ class GpuShaderCreator::Impl std::unique_ptr m_classWrappingInterface; + unsigned m_descriptorSetIndex = 0; + unsigned m_textureBindingStart = 1; + Impl() : m_functionName("OCIOMain") , m_resourcePrefix("ocio") @@ -69,14 +73,18 @@ class GpuShaderCreator::Impl m_numResources = rhs.m_numResources; m_cacheID = rhs.m_cacheID; - m_declarations = rhs.m_declarations; - m_helperMethods = rhs.m_helperMethods; - m_functionHeader = rhs.m_functionHeader; - m_functionBody = rhs.m_functionBody; - m_functionFooter = rhs.m_functionFooter; + m_parameterDeclarations = rhs.m_parameterDeclarations; + m_textureDeclarations = rhs.m_textureDeclarations; + m_helperMethods = rhs.m_helperMethods; + m_functionHeader = rhs.m_functionHeader; + m_functionBody = rhs.m_functionBody; + m_functionFooter = rhs.m_functionFooter; m_classWrappingInterface = rhs.m_classWrappingInterface->clone(); + m_descriptorSetIndex = rhs.m_descriptorSetIndex; + m_textureBindingStart = rhs.m_textureBindingStart; + m_shaderCode.clear(); m_shaderCodeID.clear(); } @@ -167,6 +175,26 @@ unsigned GpuShaderCreator::getNextResourceIndex() noexcept return getImpl()->m_numResources++; } +void GpuShaderCreator::setDescriptorSetIndex(unsigned index, unsigned textureBindingStart) +{ + if (textureBindingStart == 0) + { + throw Exception("Texture binding start index must be greater than 0."); + } + getImpl()->m_descriptorSetIndex = index; + getImpl()->m_textureBindingStart = textureBindingStart; +} + +unsigned GpuShaderCreator::getDescriptorSetIndex() const noexcept +{ + return getImpl()->m_descriptorSetIndex; +} + +unsigned GpuShaderCreator::getTextureBindingStart() const noexcept +{ + return getImpl()->m_textureBindingStart; +} + bool GpuShaderCreator::hasDynamicProperty(DynamicPropertyType type) const { for (const auto & dp : getImpl()->m_dynamicProperties) @@ -249,13 +277,22 @@ const char * GpuShaderCreator::getCacheID() const noexcept return getImpl()->m_cacheID.c_str(); } -void GpuShaderCreator::addToDeclareShaderCode(const char * shaderCode) +void GpuShaderCreator::addToParameterDeclareShaderCode(const char * shaderCode) { - if(getImpl()->m_declarations.empty()) + if(getImpl()->m_parameterDeclarations.empty()) { - getImpl()->m_declarations += "\n// Declaration of all variables\n\n"; + getImpl()->m_parameterDeclarations += "\n// Declaration of all variables\n\n"; } - getImpl()->m_declarations += (shaderCode && *shaderCode) ? shaderCode : ""; + getImpl()->m_parameterDeclarations += (shaderCode && *shaderCode) ? shaderCode : ""; +} + +void GpuShaderCreator::addToTextureDeclareShaderCode(const char* shaderCode) +{ + if (getImpl()->m_textureDeclarations.empty()) + { + getImpl()->m_textureDeclarations += "\n// Declaration of all textures\n\n"; + } + getImpl()->m_textureDeclarations += (shaderCode && *shaderCode) ? shaderCode : ""; } void GpuShaderCreator::addToHelperShaderCode(const char * shaderCode) @@ -282,7 +319,8 @@ void GpuShaderCreator::addToFunctionFooterShaderCode(const char * shaderCode) getImpl()->m_functionFooter += (shaderCode && *shaderCode) ? shaderCode : ""; } -void GpuShaderCreator::createShaderText(const char * shaderDeclarations, +void GpuShaderCreator::createShaderText(const char * shaderParameterDeclarations, + const char * shaderTextureDeclarations, const char * shaderHelperMethods, const char * shaderFunctionHeader, const char * shaderFunctionBody, @@ -292,11 +330,23 @@ void GpuShaderCreator::createShaderText(const char * shaderDeclarations, getImpl()->m_shaderCode.clear(); - getImpl()->m_shaderCode += (shaderDeclarations && *shaderDeclarations) ? shaderDeclarations : ""; - getImpl()->m_shaderCode += (shaderHelperMethods && *shaderHelperMethods) ? shaderHelperMethods : ""; - getImpl()->m_shaderCode += (shaderFunctionHeader && *shaderFunctionHeader) ? shaderFunctionHeader : ""; - getImpl()->m_shaderCode += (shaderFunctionBody && *shaderFunctionBody) ? shaderFunctionBody : ""; - getImpl()->m_shaderCode += (shaderFunctionFooter && *shaderFunctionFooter) ? shaderFunctionFooter : ""; + if (getImpl()->m_language == GPU_LANGUAGE_GLSL_VK_4_6 && (shaderParameterDeclarations && *shaderParameterDeclarations)) + { + getImpl()->m_shaderCode += "layout (set = "+std::to_string(getImpl()->m_descriptorSetIndex) + + ", binding = 0) uniform " + + getImpl()->m_functionName + "_Parameters\n{\n"; + } + getImpl()->m_shaderCode += (shaderParameterDeclarations && *shaderParameterDeclarations) ? shaderParameterDeclarations : ""; + if (getImpl()->m_language == GPU_LANGUAGE_GLSL_VK_4_6 && (shaderParameterDeclarations && *shaderParameterDeclarations)) + { + getImpl()->m_shaderCode += "\n};\n"; + } + + getImpl()->m_shaderCode += (shaderTextureDeclarations && *shaderTextureDeclarations) ? shaderTextureDeclarations : ""; + getImpl()->m_shaderCode += (shaderHelperMethods && *shaderHelperMethods) ? shaderHelperMethods : ""; + getImpl()->m_shaderCode += (shaderFunctionHeader && *shaderFunctionHeader) ? shaderFunctionHeader : ""; + getImpl()->m_shaderCode += (shaderFunctionBody && *shaderFunctionBody) ? shaderFunctionBody : ""; + getImpl()->m_shaderCode += (shaderFunctionFooter && *shaderFunctionFooter) ? shaderFunctionFooter : ""; getImpl()->m_shaderCodeID = CacheIDHash(getImpl()->m_shaderCode.c_str(), getImpl()->m_shaderCode.length()); @@ -309,18 +359,25 @@ void GpuShaderCreator::finalize() // For some GPU languages, the default header and footer do not fit well so, the class wrapper // encapsulates differences when needed. + const std::string originalHeader = getImpl()->m_parameterDeclarations + std::string("\n") + getImpl()->m_textureDeclarations; getImpl()->m_classWrappingInterface->prepareClassWrapper(getResourcePrefix(), getImpl()->m_functionName, - getImpl()->m_declarations); + originalHeader); - getImpl()->m_declarations - = getImpl()->m_classWrappingInterface->getClassWrapperHeader(getImpl()->m_declarations); + if (getImpl()->m_classWrappingInterface->hasClassWrapperHeader()) + { + getImpl()->m_parameterDeclarations + = getImpl()->m_classWrappingInterface->getClassWrapperHeader(originalHeader); + getImpl()->m_textureDeclarations.clear(); //clear texture declarations since they're already included in the header + } getImpl()->m_functionFooter = getImpl()->m_classWrappingInterface->getClassWrapperFooter(getImpl()->m_functionFooter); + // Build the complete shader program. - createShaderText(getImpl()->m_declarations.c_str(), + createShaderText(getImpl()->m_parameterDeclarations.c_str(), + getImpl()->m_textureDeclarations.c_str(), getImpl()->m_helperMethods.c_str(), getImpl()->m_functionHeader.c_str(), getImpl()->m_functionBody.c_str(), diff --git a/src/OpenColorIO/GpuShaderUtils.cpp b/src/OpenColorIO/GpuShaderUtils.cpp index f8cbc88907..a125fa0fd1 100644 --- a/src/OpenColorIO/GpuShaderUtils.cpp +++ b/src/OpenColorIO/GpuShaderUtils.cpp @@ -43,6 +43,7 @@ std::string getVecKeyword(GpuLanguage lang) case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: { @@ -80,7 +81,9 @@ void getTexDecl(GpuLanguage lang, const std::string & textureName, const std::string & samplerName, std::string & textureDecl, - std::string & samplerDecl) + std::string & samplerDecl, + unsigned descriptorSetIndex, + unsigned textureIndex) { switch (lang) { @@ -98,6 +101,16 @@ void getTexDecl(GpuLanguage lang, samplerDecl = kw.str(); break; } + case GPU_LANGUAGE_GLSL_VK_4_6: + { + textureDecl = ""; + + std::ostringstream kw; + kw << "layout(set=" << descriptorSetIndex << ", binding = " << textureIndex << ") "; + kw << "uniform sampler" << N << "D " << samplerName << "; "; + samplerDecl = kw.str(); + break; + } case GPU_LANGUAGE_HLSL_SM_5_0: { std::ostringstream t; @@ -172,6 +185,7 @@ std::string getTexSample(GpuLanguage lang, break; } case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: { kw << "texture(" << samplerName << ", " << coords << ")"; break; @@ -337,6 +351,7 @@ std::string GpuShaderText::constKeyword() const case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_MSL_2_0: @@ -531,6 +546,7 @@ void GpuShaderText::declareFloatArrayConst(const std::string & name, int size, c case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: { @@ -593,6 +609,7 @@ void GpuShaderText::declareIntArrayConst(const std::string & name, int size, con case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: { @@ -826,10 +843,13 @@ std::string GpuShaderText::getSamplerName(const std::string& textureName) return textureName + "Sampler"; } -void GpuShaderText::declareTex1D(const std::string & textureName) +void GpuShaderText::declareTex1D(const std::string & textureName, + unsigned descriptorSetIndex, + unsigned textureIndex, unsigned textureBindingStart) { std::string textureDecl, samplerDecl; - getTexDecl<1>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl); + getTexDecl<1>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl, + descriptorSetIndex, textureIndex + textureBindingStart); if (!textureDecl.empty()) { @@ -842,10 +862,13 @@ void GpuShaderText::declareTex1D(const std::string & textureName) } } -void GpuShaderText::declareTex2D(const std::string & textureName) +void GpuShaderText::declareTex2D(const std::string & textureName, + unsigned descriptorSetIndex, + unsigned textureIndex, unsigned textureBindingStart) { std::string textureDecl, samplerDecl; - getTexDecl<2>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl); + getTexDecl<2>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl, + descriptorSetIndex, textureIndex + textureBindingStart); if (!textureDecl.empty()) { @@ -858,10 +881,13 @@ void GpuShaderText::declareTex2D(const std::string & textureName) } } -void GpuShaderText::declareTex3D(const std::string& textureName) +void GpuShaderText::declareTex3D(const std::string& textureName, + unsigned descriptorSetIndex, + unsigned textureIndex, unsigned textureBindingStart) { std::string textureDecl, samplerDecl; - getTexDecl<3>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl); + getTexDecl<3>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl, + descriptorSetIndex, textureIndex + textureBindingStart); if (!textureDecl.empty()) { @@ -895,27 +921,58 @@ std::string GpuShaderText::sampleTex3D(const std::string& textureName, void GpuShaderText::declareUniformFloat(const std::string & uniformName) { - newLine() << (m_lang == GPU_LANGUAGE_MSL_2_0 ? "" : "uniform ") << floatKeyword() << " " << uniformName << ";"; + std::string uniformDeclString("uniform "); + if (m_lang == GPU_LANGUAGE_MSL_2_0 || m_lang == GPU_LANGUAGE_GLSL_VK_4_6) + { + uniformDeclString = ""; + } + newLine() << uniformDeclString << floatKeyword() << " " << uniformName << ";"; } void GpuShaderText::declareUniformBool(const std::string & uniformName) { - newLine() << (m_lang == GPU_LANGUAGE_MSL_2_0 ? "" : "uniform ") << "bool " << uniformName << ";"; + std::string uniformDeclString("uniform "); + std::string boolKeyword("bool"); + if (m_lang == GPU_LANGUAGE_MSL_2_0) + { + uniformDeclString = ""; + } + else if (m_lang == GPU_LANGUAGE_GLSL_VK_4_6) + { + uniformDeclString = ""; + boolKeyword = "int"; + } + newLine() << uniformDeclString << boolKeyword << " " << uniformName << ";"; } void GpuShaderText::declareUniformFloat3(const std::string & uniformName) { - newLine() << (m_lang == GPU_LANGUAGE_MSL_2_0 ? "" : "uniform ") << float3Keyword() << " " << uniformName << ";"; + std::string uniformDeclString("uniform "); + if (m_lang == GPU_LANGUAGE_MSL_2_0 || m_lang == GPU_LANGUAGE_GLSL_VK_4_6) + { + uniformDeclString = ""; + } + newLine() << uniformDeclString << float3Keyword() << " " << uniformName << ";"; } void GpuShaderText::declareUniformArrayFloat(const std::string & uniformName, unsigned int size) { - newLine() << (m_lang == GPU_LANGUAGE_MSL_2_0 ? "" : "uniform ") << floatKeyword() << " " << uniformName << "[" << size << "];"; + std::string uniformDeclString("uniform "); + if (m_lang == GPU_LANGUAGE_MSL_2_0 || m_lang == GPU_LANGUAGE_GLSL_VK_4_6) + { + uniformDeclString = ""; + } + newLine() << uniformDeclString << floatKeyword() << " " << uniformName << "[" << size << "];"; } void GpuShaderText::declareUniformArrayInt(const std::string & uniformName, unsigned int size) { - newLine() << (m_lang == GPU_LANGUAGE_MSL_2_0 ? "" : "uniform ") << intKeyword() << " " << uniformName << "[" << size << "];"; + std::string uniformDeclString("uniform "); + if (m_lang == GPU_LANGUAGE_MSL_2_0 || m_lang == GPU_LANGUAGE_GLSL_VK_4_6) + { + uniformDeclString = ""; + } + newLine() << uniformDeclString << intKeyword() << " " << uniformName << "[" << size << "];"; } // Keep the method private as only float & double types are expected @@ -933,6 +990,7 @@ std::string matrix3Mul(const T * m3x3, const std::string & vecName, GpuLanguage case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: { @@ -999,6 +1057,7 @@ std::string matrix4Mul(const T * m4x4, const std::string & vecName, GpuLanguage case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: { @@ -1061,6 +1120,7 @@ std::string GpuShaderText::lerp(const std::string & x, case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_MSL_2_0: @@ -1092,6 +1152,7 @@ std::string GpuShaderText::float3GreaterThan(const std::string & a, case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_CG: @@ -1127,6 +1188,7 @@ std::string GpuShaderText::float4GreaterThan(const std::string & a, case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_CG: @@ -1171,6 +1233,7 @@ std::string GpuShaderText::float3GreaterThanEqual(const std::string& a, case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_CG: @@ -1206,6 +1269,7 @@ std::string GpuShaderText::float4GreaterThanEqual(const std::string& a, case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_CG: @@ -1251,6 +1315,7 @@ std::string GpuShaderText::atan2(const std::string & y, case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: { @@ -1290,6 +1355,7 @@ std::string GpuShaderText::sign(const std::string & v) const case GPU_LANGUAGE_GLSL_1_2: case GPU_LANGUAGE_GLSL_1_3: case GPU_LANGUAGE_GLSL_4_0: + case GPU_LANGUAGE_GLSL_VK_4_6: case GPU_LANGUAGE_GLSL_ES_1_0: case GPU_LANGUAGE_GLSL_ES_3_0: case GPU_LANGUAGE_HLSL_SM_5_0: @@ -1312,6 +1378,15 @@ std::string GpuShaderText::sign(const std::string & v) const return kw.str(); } +std::string GpuShaderText::castToBool(const std::string& v) const +{ + if (m_lang == GPU_LANGUAGE_GLSL_VK_4_6) + { + return "bool(" + v + ")"; + } + return v; +} + std::string BuildResourceName(GpuShaderCreatorRcPtr & shaderCreator, const std::string & prefix, const std::string & base) diff --git a/src/OpenColorIO/GpuShaderUtils.h b/src/OpenColorIO/GpuShaderUtils.h index 54fe58f62f..f9ccd17ab1 100644 --- a/src/OpenColorIO/GpuShaderUtils.h +++ b/src/OpenColorIO/GpuShaderUtils.h @@ -171,11 +171,11 @@ class GpuShaderText static std::string getSamplerName(const std::string& textureName); // Declare the global texture and sampler information for a 1D texture. - void declareTex1D(const std::string& textureName); + void declareTex1D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex, unsigned textureBindingStart); // Declare the global texture and sampler information for a 2D texture. - void declareTex2D(const std::string& textureName); + void declareTex2D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex, unsigned textureBindingStart); // Declare the global texture and sampler information for a 3D texture. - void declareTex3D(const std::string& textureName); + void declareTex3D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex, unsigned textureBindingStart); // Get the texture lookup call for a 1D texture. std::string sampleTex1D(const std::string& textureName, const std::string& coords) const; @@ -231,6 +231,12 @@ class GpuShaderText // Get the string for taking the sign of a vector. std::string sign(const std::string & v) const; + + //Add a cast to bool for shading languages that don't support implicit casts from int to bool. + //It is required to use this function when doing boolean operations on a bool uniform to be + //compatible with all shading languages. + std::string castToBool(const std::string& v) const; + friend class GpuShaderLine; private: diff --git a/src/OpenColorIO/ParseUtils.cpp b/src/OpenColorIO/ParseUtils.cpp index 6e3f056f39..d028460ce5 100644 --- a/src/OpenColorIO/ParseUtils.cpp +++ b/src/OpenColorIO/ParseUtils.cpp @@ -263,6 +263,7 @@ const char * GpuLanguageToString(GpuLanguage language) case GPU_LANGUAGE_GLSL_1_2: return "glsl_1.2"; case GPU_LANGUAGE_GLSL_1_3: return "glsl_1.3"; case GPU_LANGUAGE_GLSL_4_0: return "glsl_4.0"; + case GPU_LANGUAGE_GLSL_VK_4_6: return "glsl_vk_4.6"; case GPU_LANGUAGE_GLSL_ES_1_0: return "glsl_es_1.0"; case GPU_LANGUAGE_GLSL_ES_3_0: return "glsl_es_3.0"; case GPU_LANGUAGE_HLSL_SM_5_0: return "hlsl_sm_5.0"; @@ -282,6 +283,7 @@ GpuLanguage GpuLanguageFromString(const char * s) else if(str == "glsl_1.2") return GPU_LANGUAGE_GLSL_1_2; else if(str == "glsl_1.3") return GPU_LANGUAGE_GLSL_1_3; else if(str == "glsl_4.0") return GPU_LANGUAGE_GLSL_4_0; + else if(str == "glsl_vk_4.6") return GPU_LANGUAGE_GLSL_VK_4_6; else if(str == "glsl_es_1.0") return GPU_LANGUAGE_GLSL_ES_1_0; else if(str == "glsl_es_3.0") return GPU_LANGUAGE_GLSL_ES_3_0; else if(str == "hlsl_sm_5.0") return GPU_LANGUAGE_HLSL_SM_5_0; diff --git a/src/OpenColorIO/ops/exposurecontrast/ExposureContrastOpGPU.cpp b/src/OpenColorIO/ops/exposurecontrast/ExposureContrastOpGPU.cpp index e12ecc88eb..97dd56faf3 100644 --- a/src/OpenColorIO/ops/exposurecontrast/ExposureContrastOpGPU.cpp +++ b/src/OpenColorIO/ops/exposurecontrast/ExposureContrastOpGPU.cpp @@ -30,7 +30,7 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformFloat(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } std::string AddProperty(GpuShaderCreatorRcPtr & shaderCreator, diff --git a/src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp b/src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp index be2ca6c352..0acd73c102 100644 --- a/src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp +++ b/src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp @@ -527,28 +527,28 @@ std::string _Add_Reach_table( dimensions = GpuShaderDesc::TEXTURE_2D; } - shaderCreator->addTexture( - name.c_str(), - GpuShaderText::getSamplerName(name).c_str(), - table.total_size, - 1, - GpuShaderCreator::TEXTURE_RED_CHANNEL, - dimensions, - INTERP_NEAREST, - &(table[0])); + const unsigned textureIndex = shaderCreator->addTexture( + name.c_str(), + GpuShaderText::getSamplerName(name).c_str(), + table.total_size, + 1, + GpuShaderCreator::TEXTURE_RED_CHANNEL, + dimensions, + INTERP_NEAREST, + &(table[0])); if (dimensions == GpuShaderDesc::TEXTURE_1D) { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex1D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } else { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex2D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } // Sampler function @@ -825,27 +825,27 @@ std::string _Add_Cusp_table( dimensions = GpuShaderDesc::TEXTURE_2D; } - shaderCreator->addTexture( - name.c_str(), - GpuShaderText::getSamplerName(name).c_str(), - g.gamut_cusp_table.total_size, - 1, - GpuShaderCreator::TEXTURE_RGB_CHANNEL, - dimensions, - INTERP_NEAREST, - &(g.gamut_cusp_table[0][0])); + const unsigned textureIndex = shaderCreator->addTexture( + name.c_str(), + GpuShaderText::getSamplerName(name).c_str(), + g.gamut_cusp_table.total_size, + 1, + GpuShaderCreator::TEXTURE_RGB_CHANNEL, + dimensions, + INTERP_NEAREST, + &(g.gamut_cusp_table[0][0])); if (dimensions == GpuShaderDesc::TEXTURE_1D) { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex1D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } else { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex2D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } // Sampler function diff --git a/src/OpenColorIO/ops/gradingprimary/GradingPrimaryOpGPU.cpp b/src/OpenColorIO/ops/gradingprimary/GradingPrimaryOpGPU.cpp index 8e83ba45ed..a0d2298f0c 100644 --- a/src/OpenColorIO/ops/gradingprimary/GradingPrimaryOpGPU.cpp +++ b/src/OpenColorIO/ops/gradingprimary/GradingPrimaryOpGPU.cpp @@ -42,7 +42,7 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformFloat(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -56,7 +56,7 @@ void AddBoolUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformBool(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -70,7 +70,7 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformFloat3(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -552,7 +552,7 @@ void GetGradingPrimaryGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, AddGPLogProperties(shaderCreator, st, gpData, properties, dyn); if (dyn) { - st.newLine() << "if (!" << properties.localBypass << ")"; + st.newLine() << "if (!" << st.castToBool(properties.localBypass) << ")"; st.newLine() << "{"; st.indent(); } @@ -579,7 +579,7 @@ void GetGradingPrimaryGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, AddGPLinProperties(shaderCreator, st, gpData, properties, dyn); if (dyn) { - st.newLine() << "if (!" << properties.localBypass << ")"; + st.newLine() << "if (!" << st.castToBool(properties.localBypass) << ")"; st.newLine() << "{"; st.indent(); } @@ -606,7 +606,7 @@ void GetGradingPrimaryGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, AddGPVideoProperties(shaderCreator, st, gpData, properties, dyn); if (dyn) { - st.newLine() << "if (!" << properties.localBypass << ")"; + st.newLine() << "if (!" << st.castToBool(properties.localBypass) << ")"; st.newLine() << "{"; st.indent(); } diff --git a/src/OpenColorIO/ops/gradingrgbcurve/GradingRGBCurveOpGPU.cpp b/src/OpenColorIO/ops/gradingrgbcurve/GradingRGBCurveOpGPU.cpp index 3ce01247cf..6093026420 100644 --- a/src/OpenColorIO/ops/gradingrgbcurve/GradingRGBCurveOpGPU.cpp +++ b/src/OpenColorIO/ops/gradingrgbcurve/GradingRGBCurveOpGPU.cpp @@ -86,12 +86,12 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, const std::string & name) { // Add the uniform if it does not already exist. - if (shaderCreator->addUniform(name.c_str(), getSize, getVector)) + if (shaderCreator->addUniform(name.c_str(), getSize, getVector, maxSize)) { // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformArrayFloat(name, maxSize); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -101,13 +101,13 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, const std::string & name) { // Add the uniform if it does not already exist. - if (shaderCreator->addUniform(name.c_str(), getSize, getVector)) + if (shaderCreator->addUniform(name.c_str(), getSize, getVector, 8)) { // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); // Need 2 ints for each RGBM curve. stDecl.declareUniformArrayInt(name, 8); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -121,7 +121,7 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformBool(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -257,7 +257,7 @@ void AddGCForwardShader(GpuShaderCreatorRcPtr & shaderCreator, { if (dyn) { - st.newLine() << "if (!" << props.m_localBypass << ")"; + st.newLine() << "if (!" << st.castToBool(props.m_localBypass) << ")"; st.newLine() << "{"; st.indent(); } @@ -305,7 +305,7 @@ void AddGCInverseShader(GpuShaderCreatorRcPtr & shaderCreator, { if (dyn) { - st.newLine() << "if (!" << props.m_localBypass << ")"; + st.newLine() << "if (!" << st.castToBool(props.m_localBypass) << ")"; st.newLine() << "{"; st.indent(); } diff --git a/src/OpenColorIO/ops/gradingtone/GradingToneOpGPU.cpp b/src/OpenColorIO/ops/gradingtone/GradingToneOpGPU.cpp index 3c64b5046e..9dfa1543ea 100644 --- a/src/OpenColorIO/ops/gradingtone/GradingToneOpGPU.cpp +++ b/src/OpenColorIO/ops/gradingtone/GradingToneOpGPU.cpp @@ -66,7 +66,7 @@ void AddUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformFloat(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -80,7 +80,7 @@ void AddBoolUniform(GpuShaderCreatorRcPtr & shaderCreator, // Declare uniform. GpuShaderText stDecl(shaderCreator->getLanguage()); stDecl.declareUniformBool(name); - shaderCreator->addToDeclareShaderCode(stDecl.string().c_str()); + shaderCreator->addToParameterDeclareShaderCode(stDecl.string().c_str()); } } @@ -1569,7 +1569,7 @@ void GetGradingToneGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, if (dyn) { - st.newLine() << "if (!" << properties.localBypass << ")"; + st.newLine() << "if (!" << st.castToBool(properties.localBypass) << ")"; st.newLine() << "{"; st.indent(); } diff --git a/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp b/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp index 26a5c7d712..573496d653 100644 --- a/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp +++ b/src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp @@ -199,15 +199,15 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, } // (Using CacheID here to potentially allow reuse of existing textures.) - shaderCreator->addTexture(name.c_str(), - GpuShaderText::getSamplerName(name).c_str(), - width, - height, - singleChannel ? GpuShaderCreator::TEXTURE_RED_CHANNEL - : GpuShaderCreator::TEXTURE_RGB_CHANNEL, - dimensions, - lutData->getConcreteInterpolation(), - &values[0]); + const unsigned textureIndex = shaderCreator->addTexture(name.c_str(), + GpuShaderText::getSamplerName(name).c_str(), + width, + height, + singleChannel ? GpuShaderCreator::TEXTURE_RED_CHANNEL + : GpuShaderCreator::TEXTURE_RGB_CHANNEL, + dimensions, + lutData->getConcreteInterpolation(), + &values[0]); // Add the LUT code to the OCIO shader program. @@ -219,8 +219,8 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex2D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } { @@ -303,8 +303,8 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, else { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex1D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } GpuShaderText ss(shaderCreator->getLanguage()); diff --git a/src/OpenColorIO/ops/lut3d/Lut3DOpGPU.cpp b/src/OpenColorIO/ops/lut3d/Lut3DOpGPU.cpp index 786f52961c..01423f6973 100644 --- a/src/OpenColorIO/ops/lut3d/Lut3DOpGPU.cpp +++ b/src/OpenColorIO/ops/lut3d/Lut3DOpGPU.cpp @@ -39,19 +39,18 @@ void GetLut3DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, ConstLut3DO samplerInterpolation = INTERP_NEAREST; } // (Using CacheID here to potentially allow reuse of existing textures.) - shaderCreator->add3DTexture(name.c_str(), - GpuShaderText::getSamplerName(name).c_str(), - lutData->getGridSize(), - samplerInterpolation, - &lutData->getArray()[0]); + const unsigned textureIndex = shaderCreator->add3DTexture(name.c_str(), + GpuShaderText::getSamplerName(name).c_str(), + lutData->getGridSize(), + samplerInterpolation, + &lutData->getArray()[0]); { GpuShaderText ss(shaderCreator->getLanguage()); - ss.declareTex3D(name); - shaderCreator->addToDeclareShaderCode(ss.string().c_str()); + ss.declareTex3D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart()); + shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str()); } - const float dim = (float)lutData->getGridSize(); // incr = 1/dim (amount needed to increment one index in the grid) diff --git a/src/bindings/python/PyGpuShaderCreator.cpp b/src/bindings/python/PyGpuShaderCreator.cpp index c133cb3efd..908ac1817d 100644 --- a/src/bindings/python/PyGpuShaderCreator.cpp +++ b/src/bindings/python/PyGpuShaderCreator.cpp @@ -62,6 +62,13 @@ void bindPyGpuShaderCreator(py::module & m) DOC(GpuShaderCreator, getResourcePrefix)) .def("setResourcePrefix", &GpuShaderCreator::setResourcePrefix, "prefix"_a, DOC(GpuShaderCreator, setResourcePrefix)) + .def("setDescriptorSetIndex", &GpuShaderCreator::setDescriptorSetIndex, + "index"_a, "textureBindingStart"_a, + DOC(GpuShaderCreator, setDescriptorSetIndex)) + .def("getDescriptorSetIndex", &GpuShaderCreator::getDescriptorSetIndex, + DOC(GpuShaderCreator, getDescriptorSetIndex)) + .def("getTextureBindingStart", &GpuShaderCreator::getTextureBindingStart, + DOC(GpuShaderCreator, getTextureBindingStart)) .def("getCacheID", &GpuShaderCreator::getCacheID, DOC(GpuShaderCreator, getCacheID)) .def("begin", &GpuShaderCreator::begin, "uid"_a, @@ -94,8 +101,10 @@ void bindPyGpuShaderCreator(py::module & m) }) // Methods to specialize parts of a OCIO shader program - .def("addToDeclareShaderCode", &GpuShaderCreator::addToDeclareShaderCode, "shaderCode"_a, - DOC(GpuShaderCreator, addToDeclareShaderCode)) + .def("addToParameterDeclareShaderCode", &GpuShaderCreator::addToParameterDeclareShaderCode, "shaderCode"_a, + DOC(GpuShaderCreator, addToParameterDeclareShaderCode)) + .def("addToTextureDeclareShaderCode", &GpuShaderCreator::addToTextureDeclareShaderCode, "shaderCode"_a, + DOC(GpuShaderCreator, addToTextureDeclareShaderCode)) .def("addToHelperShaderCode", &GpuShaderCreator::addToHelperShaderCode, "shaderCode"_a, DOC(GpuShaderCreator, addToHelperShaderCode)) .def("addToFunctionHeaderShaderCode", @@ -109,7 +118,8 @@ void bindPyGpuShaderCreator(py::module & m) "shaderCode"_a, DOC(GpuShaderCreator, addToFunctionFooterShaderCode)) .def("createShaderText", &GpuShaderCreator::createShaderText, - "shaderDeclarations"_a, "shaderHelperMethods"_a, "shaderFunctionHeader"_a, + "shaderParameterDeclarations"_a, "shaderTextureDeclarations"_a, + "shaderHelperMethods"_a, "shaderFunctionHeader"_a, "shaderFunctionBody"_a, "shaderFunctionFooter"_a, DOC(GpuShaderCreator, createShaderText)) .def("finalize", &GpuShaderCreator::finalize, diff --git a/src/bindings/python/PyGpuShaderDesc.cpp b/src/bindings/python/PyGpuShaderDesc.cpp index 24bb82412a..e6c9b600fc 100644 --- a/src/bindings/python/PyGpuShaderDesc.cpp +++ b/src/bindings/python/PyGpuShaderDesc.cpp @@ -107,6 +107,8 @@ void bindPyGpuShaderDesc(py::module & m) { return UniformIterator(self); }) + .def("getUniformBufferSize", &GpuShaderDesc::getUniformBufferSize, + DOC(GpuShaderDesc, getUniformBufferSize)) // 1D lut related methods .def("addTexture", [](GpuShaderDescRcPtr & self, @@ -187,6 +189,7 @@ void bindPyGpuShaderDesc(py::module & m) .def(py::init(), "data"_a) .def_readwrite("type", &GpuShaderDesc::UniformData::m_type) + .def_readwrite("bufferOffset", &GpuShaderDesc::UniformData::m_bufferOffset) .def("getDouble", [](GpuShaderDesc::UniformData & self) -> double { diff --git a/src/bindings/python/PyTypes.cpp b/src/bindings/python/PyTypes.cpp index 5b22b56195..80110f0122 100644 --- a/src/bindings/python/PyTypes.cpp +++ b/src/bindings/python/PyTypes.cpp @@ -519,6 +519,8 @@ void bindPyTypes(py::module & m) DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_1_3)) .value("GPU_LANGUAGE_GLSL_4_0", GPU_LANGUAGE_GLSL_4_0, DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_4_0)) + .value("GPU_LANGUAGE_GLSL_VK_4_6", GPU_LANGUAGE_GLSL_VK_4_6, + DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_VK_4_6)) .value("GPU_LANGUAGE_GLSL_ES_1_0", GPU_LANGUAGE_GLSL_ES_1_0, DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_ES_1_0)) .value("GPU_LANGUAGE_GLSL_ES_3_0", GPU_LANGUAGE_GLSL_ES_3_0, diff --git a/src/libutils/oglapphelpers/glsl.cpp b/src/libutils/oglapphelpers/glsl.cpp index 0154effa35..791648e66e 100644 --- a/src/libutils/oglapphelpers/glsl.cpp +++ b/src/libutils/oglapphelpers/glsl.cpp @@ -463,6 +463,8 @@ std::string OpenGLBuilder::getGLSLVersionString() return "#version 130"; case GPU_LANGUAGE_GLSL_4_0: return "#version 400 core"; + case GPU_LANGUAGE_GLSL_VK_4_6: + return "#version 460 core"; case GPU_LANGUAGE_GLSL_ES_1_0: return "#version 100"; case GPU_LANGUAGE_GLSL_ES_3_0: diff --git a/tests/cpu/GpuShader_tests.cpp b/tests/cpu/GpuShader_tests.cpp index 961fe269bf..610366a036 100644 --- a/tests/cpu/GpuShader_tests.cpp +++ b/tests/cpu/GpuShader_tests.cpp @@ -172,7 +172,7 @@ OCIO_ADD_TEST(GpuShader, generic_shader) } { - OCIO_CHECK_NO_THROW(shaderDesc->addToDeclareShaderCode("vec2 coords;\n")); + OCIO_CHECK_NO_THROW(shaderDesc->addToParameterDeclareShaderCode("vec2 coords;\n")); OCIO_CHECK_NO_THROW(shaderDesc->addToHelperShaderCode("vec2 helpers() {}\n\n")); OCIO_CHECK_NO_THROW(shaderDesc->addToFunctionHeaderShaderCode("void func() {\n")); OCIO_CHECK_NO_THROW(shaderDesc->addToFunctionShaderCode(" int i;\n")); @@ -195,6 +195,51 @@ OCIO_ADD_TEST(GpuShader, generic_shader) OCIO_CHECK_EQUAL(fragText, shaderDesc->getShaderText()); } + + { + OCIO_CHECK_NE(shaderDesc->getLanguage(), OCIO::GPU_LANGUAGE_GLSL_VK_4_6); + OCIO_CHECK_NO_THROW(shaderDesc->setLanguage(OCIO::GPU_LANGUAGE_GLSL_VK_4_6)); + OCIO_CHECK_EQUAL(shaderDesc->getLanguage(), OCIO::GPU_LANGUAGE_GLSL_VK_4_6); + + OCIO_CHECK_THROW_WHAT(shaderDesc->setDescriptorSetIndex(123, 0),OCIO::Exception, "Texture binding start index must be greater than 0."); + OCIO_CHECK_NO_THROW(shaderDesc->setDescriptorSetIndex(123, 456)); + OCIO_CHECK_EQUAL(shaderDesc->getDescriptorSetIndex(), 123); + OCIO_CHECK_EQUAL(shaderDesc->getTextureBindingStart(), 456); + + auto getSize = []() -> int { return 2; }; //simulate only 2 elements in the array + auto getArray = []() -> const float* { return nullptr; }; + const unsigned maxSize = 3; + OCIO_CHECK_NO_THROW(shaderDesc->addUniform("array", getSize, getArray, maxSize)); + OCIO_CHECK_EQUAL(shaderDesc->getUniformBufferSize(), 16 * maxSize); + + OCIO_CHECK_NO_THROW(shaderDesc->addToTextureDeclareShaderCode("layout(set=123, binding = 456) uniform sampler2D samplerName; \n")); + + OCIO_CHECK_NO_THROW(shaderDesc->finalize()); + + std::string fragText; + fragText += "layout (set = 123, binding = 0) uniform 1sd234__Parameters\n"; + fragText += "{\n"; + fragText += "\n"; + fragText += "// Declaration of all variables\n"; + fragText += "\n"; + fragText += "vec2 coords;\n"; + fragText += "\n"; + fragText += "};\n"; + fragText += "\n"; + fragText += "// Declaration of all textures\n"; + fragText += "\n"; + fragText += "layout(set=123, binding = 456) uniform sampler2D samplerName; \n"; + fragText += "\n"; + fragText += "// Declaration of all helper methods\n"; + fragText += "\n"; + fragText += "vec2 helpers() {}\n\n"; + fragText += "void func() {\n"; + fragText += " int i;\n"; + fragText += "}\n"; + + OCIO_CHECK_EQUAL(fragText, shaderDesc->getShaderText()); + + } } OCIO_ADD_TEST(GpuShader, MetalLutTest) @@ -262,6 +307,7 @@ ocioDisplay( } + // Declaration of the OCIO shader function float4 Display(float4 inPixel) @@ -351,6 +397,7 @@ ocioDisplay( } + // Declaration of the OCIO shader function float4 Display(float4 inPixel) @@ -441,7 +488,8 @@ ocioMyMethodName( } -// Declaration of all variables + +// Declaration of all textures texture1d ocio_lut1d_0; sampler ocio_lut1d_0Sampler; @@ -549,7 +597,8 @@ ocioMyMethodName( } -// Declaration of all variables + +// Declaration of all textures texture3d ocio_lut3d_0; sampler ocio_lut3d_0Sampler; @@ -651,7 +700,8 @@ ocioOCIOMain( } -// Declaration of all variables + +// Declaration of all textures texture2d ocio_lut1d_0; sampler ocio_lut1d_0Sampler; @@ -780,7 +830,8 @@ ocioOCIOMain( } -// Declaration of all variables + +// Declaration of all textures texture1d ocio_lut1d_0; sampler ocio_lut1d_0Sampler; @@ -928,6 +979,7 @@ ocioOCIOMain( float ocio_exposure_contrast_exposureVal; float ocio_exposure_contrast_gammaVal; + // Declaration of the OCIO shader function float4 OCIOMain(float4 inPixel) @@ -1029,6 +1081,7 @@ ocioOCIOMain( } + // Declaration of all helper methods @@ -1196,6 +1249,7 @@ int ocio_grading_rgbcurve_coefsOffsets[8]; float ocio_grading_rgbcurve_coefs[180]; bool ocio_grading_rgbcurve_localBypass; + // Declaration of all helper methods diff --git a/tests/osl/UnitTestMain.cpp b/tests/osl/UnitTestMain.cpp index 3a69ed3659..5e105b5715 100644 --- a/tests/osl/UnitTestMain.cpp +++ b/tests/osl/UnitTestMain.cpp @@ -56,7 +56,8 @@ class MyOSLShaderCreator final : public OCIO::GpuShaderCreator bool addUniform(const char * /*name*/, const SizeGetter & /*getSize*/, - const VectorFloatGetter & /*getVectorFloat*/) override + const VectorFloatGetter & /*getVectorFloat*/, + const unsigned /*maxSize*/) override { throw OCIO::Exception("Unsupported by OSL unit tests."); return false; @@ -64,13 +65,14 @@ class MyOSLShaderCreator final : public OCIO::GpuShaderCreator bool addUniform(const char * /*name*/, const SizeGetter & /*getSize*/, - const VectorIntGetter & /*getVectorInt*/) override + const VectorIntGetter & /*getVectorInt*/, + const unsigned /*maxSize*/) override { throw OCIO::Exception("Unsupported by OSL unit tests."); return false; } - void addTexture(const char * /*textureName*/, + unsigned addTexture(const char * /*textureName*/, const char * /*samplerName*/, unsigned /*width*/, unsigned /*height*/, @@ -80,24 +82,28 @@ class MyOSLShaderCreator final : public OCIO::GpuShaderCreator const float * /*values*/) override { throw OCIO::Exception("Unsupported by OSL unit tests."); + return 0; } - void add3DTexture(const char * /*textureName*/, + unsigned add3DTexture(const char * /*textureName*/, const char * /*samplerName*/, unsigned /*edgelen*/, OCIO::Interpolation /*interpolation*/, const float * /*values*/) override { throw OCIO::Exception("Unsupported by OSL unit tests."); + return 0; } - void createShaderText(const char * shaderDeclarations, + void createShaderText(const char * shaderParameterDeclarations, + const char * shaderTextureDeclarations, const char * shaderHelperMethods, const char * shaderFunctionHeader, const char * shaderFunctionBody, const char * shaderFunctionFooter) override { - m_shaderCode += shaderDeclarations; + m_shaderCode += shaderParameterDeclarations; + m_shaderCode += shaderTextureDeclarations; m_shaderCode += shaderHelperMethods; m_shaderCode += shaderFunctionHeader; m_shaderCode += shaderFunctionBody;