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 ndex of the texture. For shading languages using explicit texture bindings,
Copy link
Contributor

Choose a reason for hiding this comment

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

typo "ndex"

* 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 ndex 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
56 changes: 50 additions & 6 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 @@ -563,6 +597,11 @@ void GenericGpuShaderDesc::getTextureValues(unsigned index, const float *& value
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 Down Expand Up @@ -591,6 +630,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
67 changes: 38 additions & 29 deletions src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ std::string _Add_Reach_table(
unsigned resourceIndex,
const ACES2::Table1D & table)
{
// Reserve name
// Reserve name.
std::ostringstream resName;
resName << shaderCreator->getResourcePrefix()
<< std::string("_")
Expand All @@ -518,7 +518,7 @@ std::string _Add_Reach_table(
std::string name(resName.str());
StringUtils::ReplaceInPlace(name, "__", "_");

// Register texture
// Determine texture dimensions.
GpuShaderDesc::TextureDimensions dimensions = GpuShaderDesc::TEXTURE_1D;
if (shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_1_0
|| shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_3_0
Expand All @@ -527,31 +527,35 @@ std::string _Add_Reach_table(
dimensions = GpuShaderDesc::TEXTURE_2D;
}

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]));

// Copy the LUT into the shaderCreator as a Texture object.
const unsigned textureShaderBindingIndex = shaderCreator->addTexture(
name.c_str(),
GpuShaderText::getSamplerName(name).c_str(),
table.total_size,
1,
GpuShaderCreator::TEXTURE_RED_CHANNEL,
dimensions,
INTERP_NEAREST,
&(table[0])
);

// Create the texture declaration.
if (dimensions == GpuShaderDesc::TEXTURE_1D)
{
GpuShaderText ss(shaderCreator->getLanguage());
ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart());
ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(),
textureShaderBindingIndex, shaderCreator->getTextureBindingStart());
shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str());
}
else
{
GpuShaderText ss(shaderCreator->getLanguage());
ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart());
ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(),
textureShaderBindingIndex, shaderCreator->getTextureBindingStart());
shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str());
}

// Sampler function
// Sampler function.
GpuShaderText ss(shaderCreator->getLanguage());

ss.newLine() << ss.floatKeyword() << " " << name << "_sample(float h)";
Expand Down Expand Up @@ -805,7 +809,7 @@ std::string _Add_Cusp_table(
unsigned resourceIndex,
const ACES2::GamutCompressParams & g)
{
// Reserve name
// Reserve name.
std::ostringstream resName;
resName << shaderCreator->getResourcePrefix()
<< std::string("_")
Expand All @@ -816,7 +820,7 @@ std::string _Add_Cusp_table(
std::string name(resName.str());
StringUtils::ReplaceInPlace(name, "__", "_");

// Register texture
// Determine texture dimensions.
GpuShaderDesc::TextureDimensions dimensions = GpuShaderDesc::TEXTURE_1D;
if (shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_1_0
|| shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_3_0
Expand All @@ -825,30 +829,35 @@ std::string _Add_Cusp_table(
dimensions = GpuShaderDesc::TEXTURE_2D;
}

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]));
// Copy the LUT into the shaderCreator as a Texture object.
const unsigned textureShaderBindingIndex = 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])
);

// Create the texture declaration.
if (dimensions == GpuShaderDesc::TEXTURE_1D)
{
GpuShaderText ss(shaderCreator->getLanguage());
ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart());
ss.declareTex1D(name, shaderCreator->getDescriptorSetIndex(),
textureShaderBindingIndex, shaderCreator->getTextureBindingStart());
shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str());
}
else
{
GpuShaderText ss(shaderCreator->getLanguage());
ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(), textureIndex, shaderCreator->getTextureBindingStart());
ss.declareTex2D(name, shaderCreator->getDescriptorSetIndex(),
textureShaderBindingIndex, shaderCreator->getTextureBindingStart());
shaderCreator->addToTextureDeclareShaderCode(ss.string().c_str());
}

// Sampler function
// Sampler function.
GpuShaderText ss(shaderCreator->getLanguage());

const std::string hues_array_name = name + "_hues_array";
Expand Down
Loading
Loading