Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ macro (osl_add_all_tests)
test-fmt-cxpf test-fmt-noise test-fmt-matrixcolor
test-fmt-stpf test-fmt-errorwarning test-fmt-errorwarning-repeats
texture-alpha texture-alpha-derivs
texture-blur texture-connected-options
texture-blur texture-colorspace texture-connected-options
texture-derivs texture-environment texture-errormsg
texture-environment-opts-reg
texture-firstchannel texture-interp
Expand Down
17 changes: 16 additions & 1 deletion src/include/OSL/batched_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ struct UniformTextureOptions {
#endif
float fill = 0.0f; ///< Fill value for missing channels
const float* missingcolor = nullptr; ///< Color for missing texture
#ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
int colortransformid = 0; ///< Color space id of the texture
#endif
// Options set INTERNALLY by libtexture after the options are passed
// by the user. Users should not attempt to alter these!
int private_envlayout = 0; // Layout for environment wrap
};

template<int WidthT> struct VaryingTextureOptions {
Expand Down Expand Up @@ -72,7 +78,7 @@ template<int WidthT> struct BatchedTextureOptions {

// Options set INTERNALLY by libtexture after the options are passed
// by the user. Users should not attempt to alter these!
int private_envlayout = 0; // Layout for environment wrap
// int private_envlayout = 0; // Layout for environment wrap

// Implementation detail
// keep order synchronized to the data members in this structure
Expand All @@ -96,6 +102,9 @@ template<int WidthT> struct BatchedTextureOptions {
conservative_filter,
fill,
missingcolor,
#ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
colortransformid,
#endif
private_envlayout,
count
};
Expand Down Expand Up @@ -220,6 +229,12 @@ static_assert(
offsetof(OIIO::TextureOptBatch, missingcolor)
== uniform_offset + offsetof(UniformTextureOptions, missingcolor),
"BatchedTextureOptions members offset different than OIIO::TextureOptBatch");
# ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
static_assert(
offsetof(OIIO::TextureOptBatch, colortransformid)
== uniform_offset + offsetof(UniformTextureOptions, colortransformid),
"BatchedTextureOptions members offset different than OIIO::TextureOptBatch");
# endif

OSL_PRAGMA_WARNING_POP
} // namespace validate_offsets
Expand Down
3 changes: 2 additions & 1 deletion src/include/OSL/strdecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ STRDECL("CIE", CIE)
STRDECL("AdobeRGB", AdobeRGB)
STRDECL("ACES2065-1", ACES2065_1)
STRDECL("ACEScg", ACEScg)
STRDECL("colorspace", colorspace)
STRDECL("colorsystem", colorsystem)
STRDECL("arraylength", arraylength)
STRDECL("unknown", unknown)
STRDECL("ERROR: Unknown color space transformation \"%s\" -> \"%s\"\n",
ErrorColorTransform)
STRDECL("world", world)
STRDECL("world", world)
24 changes: 24 additions & 0 deletions src/liboslexec/batched_llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4316,6 +4316,9 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
llvm::Value* anisotropic = rop.ll.constant(32);
llvm::Value* conservative_filter = rop.ll.constant(1);
llvm::Value* fill = rop.ll.constant(0.0f);
#ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
llvm::Value* colortransformid = rop.ll.constant(0);
#endif

bool is_swrap_uniform = true;
bool is_twrap_uniform = true;
Expand Down Expand Up @@ -4606,6 +4609,18 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
continue;
}

if (name == Strings::colorspace && valtype == TypeDesc::STRING) {
if (Val.is_constant()) {
// Just ignore this option for now.
// FIXME: need full implementation
continue;
} else {
rop.shadingcontext()->errorfmt(
"texture{} optional argument \"{}\" must be constant after optimization ({}:{})",
tex3d ? "3d" : "", name, op.sourcefile(), op.sourceline());
continue;
}
}
if (name == Strings::time
&& (valtype == TypeDesc::FLOAT || valtype == TypeDesc::INT)) {
// NOTE: currently no supported 3d texture format makes use of time.
Expand Down Expand Up @@ -4693,6 +4708,14 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
static_cast<int>(
LLVMMemberIndex::missingcolor)));

#ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
// FIXME: We currently ignore the color space, so just make it 0
rop.ll.op_unmasked_store(
colortransformid,
rop.ll.GEP(bto_type, bto, 0,
static_cast<int>(LLVMMemberIndex::colortransformid)));
#endif

// blur's and width's are always communicated as wide, we we will handle them here
rop.ll.op_unmasked_store(sblur, rop.ll.GEP(bto_type, bto, 0,
static_cast<int>(
Expand Down Expand Up @@ -4936,6 +4959,7 @@ llvm_batched_texture_varying_options(BatchedBackendLLVM& rop, int opnum,
continue;
}

SKIP_PARAM_WIDE_STRING(colorspace)
SKIP_PARAM_WIDE_FLOAT(time)

rop.shadingcontext()->errorfmt(
Expand Down
5 changes: 4 additions & 1 deletion src/liboslexec/batched_llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ BatchedBackendLLVM::llvm_type_batched_texture_options()
sg_types.push_back(ll.type_int()); // conservative_filter
sg_types.push_back(ll.type_float()); // fill
sg_types.push_back(ll.type_ptr(ll.type_float())); // missingcolor
sg_types.push_back(ll.type_int()); // colortransformid

// Private internal data
sg_types.push_back(ll.type_int()); // envlayout
Expand Down Expand Up @@ -2748,7 +2749,9 @@ BatchedBackendLLVM::build_offsets_of_BatchedTextureOptions(
offset_by_index.push_back(uniform_offset
+ offsetof(UniformTextureOptions, missingcolor));
offset_by_index.push_back(
offsetof(BatchedTextureOptions<WidthT>, private_envlayout));
uniform_offset + offsetof(UniformTextureOptions, colortransformid));
offset_by_index.push_back(
uniform_offset + offsetof(UniformTextureOptions, private_envlayout));
}


Expand Down
13 changes: 13 additions & 0 deletions src/liboslexec/llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,19 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
rop.ll.constant(nchans), val);
continue;
}
if (name == Strings::colorspace && valtype == TypeDesc::STRING) {
if (Val.is_constant()) {
// Just ignore this option for now.
// FIXME: need full implementation
continue;
} else {
rop.shadingcontext()->errorfmt(
"texture{} optional argument \"{}\" must be constant after optimization ({}:{})",
tex3d ? "3d" : "", name, op.sourcefile(), op.sourceline());
continue;
}
}


// PARAM_FLOAT(time)
if (name == Strings::time
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions testsuite/texture-colorspace/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Compiled test.osl -> test.oso

Output Cout to out.exr
color space - none specified: 0.5 0.5 0.5
color space - sRGB: 0.5 0.5 0.5
9 changes: 9 additions & 0 deletions testsuite/texture-colorspace/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python

# Copyright Contributors to the Open Shading Language project.
# SPDX-License-Identifier: BSD-3-Clause
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

command += oiiotool ("-pattern constant:color=0.5,0.5,0.5 64x64 3 -d half -otex grey.exr")
command += testshade("-g 1 1 --center -od half -o Cout out.exr test")
outputs = [ "out.txt" ]
13 changes: 13 additions & 0 deletions testsuite/texture-colorspace/test.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

shader
test (string filename = "grey.exr",
output color Cout = 0)
{
Cout = (color)texture (filename, u, v);
printf("color space - none specified: %g\n", Cout);
Cout = (color)texture (filename, u, v, "colorspace", "sRGB");
printf("color space - sRGB: %g\n", Cout);
}
Loading