Skip to content

Commit b6ea842

Browse files
author
Yiyun Wang
committed
Fix build errors
1 parent f1da843 commit b6ea842

File tree

9 files changed

+52
-41
lines changed

9 files changed

+52
-41
lines changed

src/OpenColorIO/GpuShaderUtils.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,28 @@ std::string getMatrixValues(const T * mtx, GpuLanguage lang, bool transpose)
222222
return vals;
223223
}
224224

225+
226+
void RGBtoRGBATexture(const float* lutValues, int valueCount, std::vector<float>& float4AdaptedLutValues){
227+
if(valueCount % 3 != 0)
228+
throw Exception("Value count should be divisible by 3.");
229+
230+
valueCount = valueCount * 4 / 3;
231+
if(lutValues != nullptr)
232+
{
233+
float4AdaptedLutValues.resize(valueCount);
234+
const float *rgbLutValuesIt = lutValues;
235+
float *rgbaLutValuesIt = float4AdaptedLutValues.data();
236+
const float *end = rgbaLutValuesIt + valueCount;
237+
238+
while(rgbaLutValuesIt != end) {
239+
*rgbaLutValuesIt++ = *rgbLutValuesIt++;
240+
*rgbaLutValuesIt++ = *rgbLutValuesIt++;
241+
*rgbaLutValuesIt++ = *rgbLutValuesIt++;
242+
*rgbaLutValuesIt++ = 1.0f;
243+
}
244+
}
245+
}
246+
225247
GpuShaderText::GpuShaderLine::GpuShaderLine(GpuShaderText * text)
226248
: m_text(text)
227249
{

src/OpenColorIO/GpuShaderUtils.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -261,27 +261,7 @@ void AddLinToLogShader(GpuShaderCreatorRcPtr & shaderCreator, GpuShaderText & st
261261
void AddLogToLinShader(GpuShaderCreatorRcPtr & shaderCreator, GpuShaderText & st);
262262

263263
// Texture converter from RGB to RGBA
264-
void RGB_to_RGBA(const float* lutValues, int valueCount, std::vector<float>& float4AdaptedLutValues)
265-
{
266-
if(valueCount % 3 != 0)
267-
throw Exception("Value count should be divisible by 3.");
268-
269-
valueCount = valueCount * 4 / 3;
270-
if(lutValues != nullptr)
271-
{
272-
float4AdaptedLutValues.resize(valueCount);
273-
const float *rgbLutValuesIt = lutValues;
274-
float *rgbaLutValuesIt = float4AdaptedLutValues.data();
275-
const float *end = rgbaLutValuesIt + valueCount;
276-
277-
while(rgbaLutValuesIt != end) {
278-
*rgbaLutValuesIt++ = *rgbLutValuesIt++;
279-
*rgbaLutValuesIt++ = *rgbLutValuesIt++;
280-
*rgbaLutValuesIt++ = *rgbLutValuesIt++;
281-
*rgbaLutValuesIt++ = 1.0f;
282-
}
283-
}
284-
}
264+
void RGBtoRGBATexture(const float* lutValues, int valueCount, std::vector<float>& float4AdaptedLutValues);
285265

286266
} // namespace OCIO_NAMESPACE
287267

src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,14 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,
155155
const unsigned long length = lutData->getArray().getLength();
156156
const unsigned long width = std::min(length, defaultMaxWidth);
157157
const unsigned long height = (length / defaultMaxWidth) + 1;
158-
const unsigned long numChannels = lutData->getArray().getNumColorComponents();
158+
unsigned long numChannels = lutData->getArray().getNumColorComponents();
159159

160160
// Note: The 1D LUT needs a GPU texture for the Look-up table implementation.
161161
// However, the texture type & content may vary based on the number of channels
162162
// i.e. when all channels are identical a F32 Red GPU texture is enough.
163163

164+
const bool singleChannel = (numChannels == 1);
165+
164166
// When shader language is metal, we want to return a texture in
165167
// RGBA format instead of RGB.
166168
if (shaderCreator ->getLanguage() == GPU_LANGUAGE_MSL_2_0 && numChannels == 3)
@@ -173,7 +175,7 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,
173175
std::vector<float> values;
174176
values.reserve(width * height * numChannels);
175177

176-
GpuShaderCreator::TextureType channel;
178+
GpuShaderCreator::TextureType channel = GpuShaderCreator::TEXTURE_RED_CHANNEL;
177179
switch (numChannels)
178180
{
179181
case 1:
@@ -184,16 +186,18 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,
184186
CreatePaddedLutChannels(width, height, lutData->getArray().getValues(), values);
185187
channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
186188
break;
187-
case 4:
189+
case 4: {
188190
std::vector<float> paddedChannels;
189191
values.reserve(width * height * 3);
190192
CreatePaddedLutChannels(width, height, lutData->getArray().getValues(), paddedChannels);
191193
// Insert a place holder alpha channel with value of 1. This is to support RGBA
192194
// texture format for Metal shading language.
193-
RGB_to_RGBA(paddedChannels, width * height * 3, values)
195+
RGBtoRGBATexture(paddedChannels.data(), width * height * 3, values);
194196
channel = GpuShaderCreator::TEXTURE_RGBA_CHANNEL;
195197
break;
198+
}
196199
default:
200+
throw Exception("Invalid number of texture channels.");
197201
break;
198202
}
199203

src/OpenColorIO/ops/lut3d/Lut3DOpGPU.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ void GetLut3DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator, ConstLut3DO
3838
samplerInterpolation = INTERP_NEAREST;
3939
}
4040

41-
if(shaderCreator->getLanguage() == GPU_LANGUAGE_MSL_2_0){
42-
43-
if(values.size() % 3 != 0) {
44-
throw Exception("3D LUT value count should be divisible by 3.");
45-
}
46-
41+
if(shaderCreator->getLanguage() == GPU_LANGUAGE_MSL_2_0){
4742
unsigned edgelen = lutData->getGridSize();
4843
std::vector<float> float4AdaptedLutValues;
49-
RGB_to_RGBA(&lutData->getArray()[0], 3*edgelen*edgelen*edgelen, float4AdaptedLutValues);
44+
RGBtoRGBATexture(&lutData->getArray()[0], 3*edgelen*edgelen*edgelen, float4AdaptedLutValues);
5045

5146
shaderCreator->add3DTexture(name.c_str(),
5247
GpuShaderText::getSamplerName(name).c_str(),

src/bindings/python/PyGpuShaderDesc.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ void bindPyGpuShaderDesc(py::module & m)
129129
case GpuShaderDesc::TEXTURE_RGB_CHANNEL:
130130
numChannels = 3;
131131
break;
132+
case GpuShaderDesc::TEXTURE_RGBA_CHANNEL:
133+
numChannels = 4;
134+
break;
132135
default:
133136
throw Exception("Error: Unsupported texture type");
134137
}
@@ -268,6 +271,9 @@ void bindPyGpuShaderDesc(py::module & m)
268271
case GpuShaderDesc::TEXTURE_RGB_CHANNEL:
269272
numChannels = 3;
270273
break;
274+
case GpuShaderDesc::TEXTURE_RGBA_CHANNEL:
275+
numChannels = 4;
276+
break;
271277
default:
272278
throw Exception("Error: Unsupported texture type");
273279
}
@@ -352,8 +358,9 @@ void bindPyGpuShaderDesc(py::module & m)
352358
const char * textureName = nullptr;
353359
const char * samplerName = nullptr;
354360
unsigned edgelen;
361+
GpuShaderDesc::TextureType channel;
355362
Interpolation interpolation;
356-
it.m_obj->get3DTexture(i, textureName, samplerName, edgelen, interpolation);
363+
it.m_obj->get3DTexture(i, textureName, samplerName, edgelen, channel, interpolation);
357364

358365
return { textureName, samplerName, edgelen, interpolation, it.m_obj, i };
359366
})
@@ -368,8 +375,9 @@ void bindPyGpuShaderDesc(py::module & m)
368375
const char * textureName = nullptr;
369376
const char * samplerName = nullptr;
370377
unsigned edgelen;
378+
GpuShaderDesc::TextureType channel;
371379
Interpolation interpolation;
372-
it.m_obj->get3DTexture(i, textureName, samplerName, edgelen, interpolation);
380+
it.m_obj->get3DTexture(i, textureName, samplerName, edgelen, channel, interpolation);
373381

374382
return { textureName, samplerName, edgelen, interpolation, it.m_obj, i };
375383
});

src/libutils/oglapphelpers/glsl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void OpenGLBuilder::allocateAllTextures(unsigned startIndex)
319319
const char * textureName = nullptr;
320320
const char * samplerName = nullptr;
321321
unsigned edgelen = 0;
322-
GpuShaderCreator:: TextureType channel = GpuShaderCreator::TextureType::TEXTURE_RGB_CHANNEL;
322+
GpuShaderCreator:: TextureType channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
323323
Interpolation interpolation = INTERP_LINEAR;
324324
m_shaderDesc->get3DTexture(idx, textureName, samplerName, edgelen, channel, interpolation);
325325

src/libutils/oglapphelpers/metalapp.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ vertex VertexOut ColorCorrectionVS(unsigned int vId [[ vertex_id ]])
264264
const char* textureName;
265265
const char* samplerName;
266266
unsigned int edgeLen;
267-
TextureType channel;
267+
GpuShaderDesc::TextureType channel;
268268
Interpolation interpolation;
269269

270270
shaderDesc->get3DTexture(i, textureName, samplerName, edgeLen, channel, interpolation);

src/libutils/oglapphelpers/msl.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void RGB_to_RGBA(const float* lutValues, int valueCount, std::vector<float>& flo
210210
const char * textureName = nullptr;
211211
const char * samplerName = nullptr;
212212
unsigned edgelen = 0;
213-
TextureType channel = TextureType::TEXTURE_RGBA_CHANNEL;
213+
GpuShaderDesc::TextureType channel = GpuShaderDesc::TEXTURE_RGBA_CHANNEL;
214214
Interpolation interpolation = INTERP_LINEAR;
215215
m_shaderDesc->get3DTexture(idx, textureName, samplerName, edgelen, channel, interpolation);
216216

tests/cpu/GpuShader_tests.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ OCIO_ADD_TEST(GpuShader, generic_shader)
122122

123123
OCIO_CHECK_EQUAL(shaderDesc->getNum3DTextures(), 0U);
124124
OCIO_CHECK_NO_THROW(shaderDesc->add3DTexture("lut1", "lut1Sampler", edgelen,
125-
TextureType::TEXTURE_RGB_CHANNEL,
125+
OCIO::GpuShaderDesc::TEXTURE_RGB_CHANNEL,
126126
OCIO::INTERP_TETRAHEDRAL,
127127
&values[0]));
128128

@@ -131,18 +131,18 @@ OCIO_ADD_TEST(GpuShader, generic_shader)
131131
const char * textureName = nullptr;
132132
const char * samplerName = nullptr;
133133
unsigned e = 0;
134-
TextureType channel;
134+
OCIO::GpuShaderDesc::TextureType channel;
135135
OCIO::Interpolation i = OCIO::INTERP_UNKNOWN;
136136

137137
OCIO_CHECK_NO_THROW(shaderDesc->get3DTexture(0, textureName, samplerName, e, channel, i));
138138

139139
OCIO_CHECK_EQUAL(std::string(textureName), "lut1");
140140
OCIO_CHECK_EQUAL(std::string(samplerName), "lut1Sampler");
141141
OCIO_CHECK_EQUAL(edgelen, e);
142-
OCIO_CHECK_EQUAL(TextureType::TEXTURE_RGB_CHANNEL, channel);
142+
OCIO_CHECK_EQUAL(OCIO::GpuShaderDesc::TEXTURE_RGB_CHANNEL, channel);
143143
OCIO_CHECK_EQUAL(OCIO::INTERP_TETRAHEDRAL, i);
144144

145-
OCIO_CHECK_THROW_WHAT(shaderDesc->get3DTexture(1, textureName, samplerName, channel, e, i),
145+
OCIO_CHECK_THROW_WHAT(shaderDesc->get3DTexture(1, textureName, samplerName, e, channel, i),
146146
OCIO::Exception,
147147
"3D LUT access error");
148148

@@ -161,6 +161,7 @@ OCIO_ADD_TEST(GpuShader, generic_shader)
161161
// Supports several 3D LUTs
162162

163163
OCIO_CHECK_NO_THROW(shaderDesc->add3DTexture("lut1", "lut1Sampler", edgelen,
164+
OCIO::GpuShaderDesc::TEXTURE_RGB_CHANNEL,
164165
OCIO::INTERP_TETRAHEDRAL,
165166
&values[0]));
166167

@@ -169,6 +170,7 @@ OCIO_ADD_TEST(GpuShader, generic_shader)
169170
// Check the 3D LUT limit
170171

171172
OCIO_CHECK_THROW(shaderDesc->add3DTexture("lut1", "lut1Sampler", 130,
173+
OCIO::GpuShaderDesc::TEXTURE_RGB_CHANNEL,
172174
OCIO::INTERP_TETRAHEDRAL,
173175
&values[0]),
174176
OCIO::Exception);

0 commit comments

Comments
 (0)