Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions include/OpenColorIO/OpenColorIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -3503,8 +3503,9 @@ class OCIOEXPORT GpuShaderCreator
* 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.
* \return Shader binding 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.
* The setDescriptorSetIndex function may be used to offset the starting index value.
**/
virtual unsigned addTexture(const char * textureName,
const char * samplerName,
Expand All @@ -3522,8 +3523,9 @@ class OCIOEXPORT GpuShaderCreator
* 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.
* \return Shader binding 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.
* The setDescriptorSetIndex function may be used to offset the starting index value.
**/
virtual unsigned add3DTexture(const char * textureName,
const char * samplerName,
Expand Down Expand Up @@ -3775,7 +3777,12 @@ class OCIOEXPORT GpuShaderDesc : public GpuShaderCreator
**/
virtual std::size_t getUniformBufferSize() const noexcept = 0;

// 1D lut related methods
/**
* The getTexture methods are used to access Lut1D arrays to upload to the GPU as textures.
* Please note that the index used here is based on the total number of Lut1Ds used by
* the Processor and is different from the texture shader binding index, which may be
* obtained using the corresponding function.
*/
virtual unsigned getNumTextures() const noexcept = 0;
virtual void getTexture(unsigned index,
const char *& textureName,
Expand All @@ -3786,15 +3793,24 @@ class OCIOEXPORT GpuShaderDesc : public GpuShaderCreator
TextureDimensions & dimensions,
Interpolation & interpolation) const = 0;
virtual void getTextureValues(unsigned index, const float *& values) const = 0;
/// Get the index used to declare the texture in the shader for languages such as Vulkan.
virtual unsigned getTextureShaderBindingIndex(unsigned index) const = 0;

// 3D lut related methods
/**
* The get3DTexture methods are used to access Lut3D arrays to upload to the GPU as textures.
* Please note that the index used here is based on the total number of Lut3Ds used by
* the Processor and is different from the texture shader binding index, which may be
* obtained using the corresponding function.
*/
virtual unsigned getNum3DTextures() const noexcept = 0;
virtual void get3DTexture(unsigned index,
const char *& textureName,
const char *& samplerName,
unsigned & edgelen,
Interpolation & interpolation) const = 0;
virtual void get3DTextureValues(unsigned index, const float *& values) const = 0;
/// Get the index used to declare the texture in the shader for languages such as Vulkan.
virtual unsigned get3DTextureShaderBindingIndex(unsigned index) const = 0;

/// Get the complete OCIO shader program.
const char * getShaderText() const noexcept;
Expand Down
66 changes: 57 additions & 9 deletions src/OpenColorIO/GpuShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PrivateImpl
GpuShaderDesc::TextureType channel,
unsigned dimensions,
Interpolation interpolation,
unsigned textureShaderBindingIndex,
const float * v)
: m_textureName(textureName)
, m_samplerName(samplerName)
Expand All @@ -79,6 +80,7 @@ class PrivateImpl
, m_type(channel)
, m_dimensions(dimensions)
, m_interp(interpolation)
, m_textureShaderBindingIndex(textureShaderBindingIndex)
{
if (!textureName || !*textureName)
{
Expand Down Expand Up @@ -113,6 +115,7 @@ class PrivateImpl
GpuShaderDesc::TextureType m_type;
unsigned m_dimensions;
Interpolation m_interp;
unsigned m_textureShaderBindingIndex;

std::vector<float> m_values;

Expand Down Expand Up @@ -214,11 +217,13 @@ class PrivateImpl
<< width << " > " << get1dLutMaxWidth();
throw Exception(ss.str().c_str());
}
unsigned textureIndex = static_cast<unsigned>(m_textures.size());
unsigned textureShaderBindingIndex = static_cast<unsigned>(m_textures.size())
+ static_cast<unsigned>(m_textures3D.size());
unsigned numDimensions = static_cast<unsigned>(dimensions);
Texture t(textureName, samplerName, width, height, 1, channel, numDimensions, interpolation, values);
Texture t(textureName, samplerName, width, height, 1, channel, numDimensions, interpolation,
textureShaderBindingIndex, values);
m_textures.push_back(t);
return textureIndex;
return textureShaderBindingIndex;
}

void getTexture(unsigned index,
Expand Down Expand Up @@ -268,6 +273,20 @@ class PrivateImpl
values = &t.m_values[0];
}

unsigned getTextureShaderBindingIndex(unsigned index) const
{
if(index >= m_textures.size())
{
std::ostringstream ss;
ss << "1D LUT access error: index = " << index
<< " where size = " << m_textures.size();
throw Exception(ss.str().c_str());
}

const Texture & t = m_textures[index];
return t.m_textureShaderBindingIndex;
}

unsigned add3DTexture(const char * textureName,
const char * samplerName,
unsigned edgelen,
Expand All @@ -282,12 +301,13 @@ class PrivateImpl
throw Exception(ss.str().c_str());
}

unsigned textureIndex = static_cast<unsigned>(m_textures3D.size());
unsigned textureShaderBindingIndex = static_cast<unsigned>(m_textures.size())
+ static_cast<unsigned>(m_textures3D.size());
Texture t(textureName, samplerName, edgelen, edgelen, edgelen,
GpuShaderDesc::TEXTURE_RGB_CHANNEL, 3,
interpolation, values);
interpolation, textureShaderBindingIndex, values);
m_textures3D.push_back(t);
return textureIndex;
return textureShaderBindingIndex;
}

void get3DTexture(unsigned index,
Expand Down Expand Up @@ -325,6 +345,20 @@ class PrivateImpl
values = &t.m_values[0];
}

unsigned get3DTextureShaderBindingIndex(unsigned index) const
{
if(index >= m_textures3D.size())
{
std::ostringstream ss;
ss << "3D LUT access error: index = " << index
<< " where size = " << m_textures3D.size();
throw Exception(ss.str().c_str());
}

const Texture & t = m_textures3D[index];
return t.m_textureShaderBindingIndex;
}

unsigned getNumUniforms() const
{
return (unsigned)m_uniforms.size();
Expand Down Expand Up @@ -544,7 +578,9 @@ unsigned GenericGpuShaderDesc::addTexture(const char * textureName,
Interpolation interpolation,
const float * values)
{
return getImplGeneric()->addTexture(textureName, samplerName, width, height, channel, dimensions, interpolation, values);
return getImplGeneric()->addTexture(textureName, samplerName, width, height, channel,
dimensions, interpolation, values)
+ getTextureBindingStart();
}

void GenericGpuShaderDesc::getTexture(unsigned index,
Expand All @@ -555,14 +591,20 @@ void GenericGpuShaderDesc::getTexture(unsigned index,
TextureDimensions & dimensions,
Interpolation & interpolation) const
{
getImplGeneric()->getTexture(index, textureName, samplerName, width, height, channel, dimensions, interpolation);
getImplGeneric()->getTexture(index, textureName, samplerName, width, height, channel,
dimensions, interpolation);
}

void GenericGpuShaderDesc::getTextureValues(unsigned index, const float *& values) const
{
getImplGeneric()->getTextureValues(index, values);
}

unsigned GenericGpuShaderDesc::getTextureShaderBindingIndex(unsigned index) const
{
return getImplGeneric()->getTextureShaderBindingIndex(index) + getTextureBindingStart();
}

unsigned GenericGpuShaderDesc::getNum3DTextures() const noexcept
{
return unsigned(getImplGeneric()->m_textures3D.size());
Expand All @@ -574,7 +616,8 @@ unsigned GenericGpuShaderDesc::add3DTexture(const char * textureName,
Interpolation interpolation,
const float * values)
{
return getImplGeneric()->add3DTexture(textureName, samplerName, edgelen, interpolation, values);
return getImplGeneric()->add3DTexture(textureName, samplerName, edgelen, interpolation, values)
+ getTextureBindingStart();
}

void GenericGpuShaderDesc::get3DTexture(unsigned index,
Expand All @@ -591,6 +634,11 @@ void GenericGpuShaderDesc::get3DTextureValues(unsigned index, const float *& val
getImplGeneric()->get3DTextureValues(index, values);
}

unsigned GenericGpuShaderDesc::get3DTextureShaderBindingIndex(unsigned index) const
{
return getImplGeneric()->get3DTextureShaderBindingIndex(index) + getTextureBindingStart();
}

void GenericGpuShaderDesc::Deleter(GenericGpuShaderDesc* c)
{
delete c;
Expand Down
2 changes: 2 additions & 0 deletions src/OpenColorIO/GpuShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GenericGpuShaderDesc : public GpuShaderDesc
TextureDimensions & dimensions,
Interpolation & interpolation) const override;
void getTextureValues(unsigned index, const float *& values) const override;
unsigned getTextureShaderBindingIndex(unsigned index) const override;

// Accessors to the 3D textures built from 3D LUT
//
Expand All @@ -82,6 +83,7 @@ class GenericGpuShaderDesc : public GpuShaderDesc
unsigned & edgelen,
Interpolation & interpolation) const override;
void get3DTextureValues(unsigned index, const float *& value) const override;
unsigned get3DTextureShaderBindingIndex(unsigned index) const override;

private:

Expand Down
4 changes: 4 additions & 0 deletions src/OpenColorIO/GpuShaderDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ void GpuShaderCreator::setDescriptorSetIndex(unsigned index, unsigned textureBin
{
throw Exception("Texture binding start index must be greater than 0.");
}
AutoMutex lock(getImpl()->m_cacheIDMutex);
getImpl()->m_descriptorSetIndex = index;
getImpl()->m_textureBindingStart = textureBindingStart;
getImpl()->m_cacheID.clear();
}

unsigned GpuShaderCreator::getDescriptorSetIndex() const noexcept
Expand Down Expand Up @@ -270,6 +272,8 @@ const char * GpuShaderCreator::getCacheID() const noexcept
os << getImpl()->m_resourcePrefix << " ";
os << getImpl()->m_pixelName << " ";
os << getImpl()->m_numResources << " ";
os << getImpl()->m_descriptorSetIndex << " ";
os << getImpl()->m_textureBindingStart << " ";
os << getImpl()->m_shaderCodeID;
getImpl()->m_cacheID = os.str();
}
Expand Down
12 changes: 6 additions & 6 deletions src/OpenColorIO/GpuShaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,11 @@ std::string GpuShaderText::getSamplerName(const std::string& textureName)

void GpuShaderText::declareTex1D(const std::string & textureName,
unsigned descriptorSetIndex,
unsigned textureIndex, unsigned textureBindingStart)
unsigned textureIndex)
{
std::string textureDecl, samplerDecl;
getTexDecl<1>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl,
descriptorSetIndex, textureIndex + textureBindingStart);
descriptorSetIndex, textureIndex);

if (!textureDecl.empty())
{
Expand All @@ -864,11 +864,11 @@ void GpuShaderText::declareTex1D(const std::string & textureName,

void GpuShaderText::declareTex2D(const std::string & textureName,
unsigned descriptorSetIndex,
unsigned textureIndex, unsigned textureBindingStart)
unsigned textureIndex)
{
std::string textureDecl, samplerDecl;
getTexDecl<2>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl,
descriptorSetIndex, textureIndex + textureBindingStart);
descriptorSetIndex, textureIndex);

if (!textureDecl.empty())
{
Expand All @@ -883,11 +883,11 @@ void GpuShaderText::declareTex2D(const std::string & textureName,

void GpuShaderText::declareTex3D(const std::string& textureName,
unsigned descriptorSetIndex,
unsigned textureIndex, unsigned textureBindingStart)
unsigned textureIndex)
{
std::string textureDecl, samplerDecl;
getTexDecl<3>(m_lang, textureName, getSamplerName(textureName), textureDecl, samplerDecl,
descriptorSetIndex, textureIndex + textureBindingStart);
descriptorSetIndex, textureIndex);

if (!textureDecl.empty())
{
Expand Down
6 changes: 3 additions & 3 deletions src/OpenColorIO/GpuShaderUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, unsigned descriptorSetIndex, unsigned textureIndex, unsigned textureBindingStart);
void declareTex1D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex);
// Declare the global texture and sampler information for a 2D texture.
void declareTex2D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex, unsigned textureBindingStart);
void declareTex2D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex);
// Declare the global texture and sampler information for a 3D texture.
void declareTex3D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex, unsigned textureBindingStart);
void declareTex3D(const std::string& textureName, unsigned descriptorSetIndex, unsigned textureIndex);

// Get the texture lookup call for a 1D texture.
std::string sampleTex1D(const std::string& textureName, const std::string& coords) const;
Expand Down
Loading
Loading