Skip to content

Commit

Permalink
cleanup: Switch some deprecated TypeDesc names to modern ones (#1806)
Browse files Browse the repository at this point in the history
Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored May 5, 2024
1 parent 3ff5d5d commit b859317
Show file tree
Hide file tree
Showing 30 changed files with 336 additions and 424 deletions.
8 changes: 3 additions & 5 deletions src/include/OSL/batched_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ template<int WidthT> class BatchedTextureOutputs {
void* errormessage, Mask<WidthT> mask)
: m_result(result)
, m_resultHasDerivs(resultHasDerivs)
, m_resultType((chans == 1) ? TypeDesc::TypeFloat : TypeDesc::TypeColor)
, m_resultType((chans == 1) ? TypeFloat : TypeColor)
, m_alpha(alpha)
, m_alphaHasDerivs(alphaHasDerivs)
, m_errormessage(errormessage)
Expand All @@ -240,15 +240,13 @@ template<int WidthT> class BatchedTextureOutputs {
// The return value maybe invalid or be Masked<float, WidthT>
OSL_FORCEINLINE MaskedData<WidthT> alpha()
{
return MaskedData<WidthT>(TypeDesc::TypeFloat, m_alphaHasDerivs, m_mask,
m_alpha);
return MaskedData<WidthT>(TypeFloat, m_alphaHasDerivs, m_mask, m_alpha);
}

// The return value maybe invalid or be Masked<ustring, WidthT>
OSL_FORCEINLINE MaskedData<WidthT> errormessage()
{
return MaskedData<WidthT>(TypeDesc::TypeString, false, m_mask,
m_errormessage);
return MaskedData<WidthT>(TypeString, false, m_mask, m_errormessage);
}

private:
Expand Down
20 changes: 10 additions & 10 deletions src/include/OSL/genclosure.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ struct ClosureParam {
#define fieldsize(st, fld) sizeof(((st *)0)->fld)

#define CLOSURE_INT_PARAM(st, fld) \
{ TypeDesc::TypeInt, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
{ TypeInt, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
#define CLOSURE_FLOAT_PARAM(st, fld) \
{ TypeDesc::TypeFloat, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
{ TypeFloat, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
#define CLOSURE_COLOR_PARAM(st, fld) \
{ TypeDesc::TypeColor, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
{ TypeColor, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
#define CLOSURE_VECTOR_PARAM(st, fld) \
{ TypeDesc::TypeVector, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
{ TypeVector, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
#define CLOSURE_STRING_PARAM(st, fld) \
{ TypeDesc::TypeString, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
{ TypeString, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }
#define CLOSURE_CLOSURE_PARAM(st, fld) \
{ TypeDesc::PTR, (int)reckless_offsetof(st, fld), NULL, fieldsize(st, fld) }

Expand All @@ -49,15 +49,15 @@ struct ClosureParam {

// NOTE: this keyword args have to be always at the end of the list
#define CLOSURE_INT_KEYPARAM(st, fld, key) \
{ TypeDesc::TypeInt, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
{ TypeInt, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
#define CLOSURE_FLOAT_KEYPARAM(st, fld, key) \
{ TypeDesc::TypeFloat, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
{ TypeFloat, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
#define CLOSURE_COLOR_KEYPARAM(st, fld, key) \
{ TypeDesc::TypeColor, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
{ TypeColor, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
#define CLOSURE_VECTOR_KEYPARAM(st, fld, key) \
{ TypeDesc::TypeVector, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
{ TypeVector, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
#define CLOSURE_STRING_KEYPARAM(st, fld, key) \
{ TypeDesc::TypeString, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }
{ TypeString, (int)reckless_offsetof(st, fld), key, fieldsize(st, fld) }

#define CLOSURE_FINISH_PARAM(st) { TypeDesc(), sizeof(st), nullptr, alignof(st) }

Expand Down
2 changes: 1 addition & 1 deletion src/include/OSL/oslexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ class OSLEXECPUBLIC ShadingSystem {
// float blur = 0.001;
// ss->Parameter (*group, "blur", blur);
// Vec3 colorfilter (0.5f, 0.5f, 1.0f);
// ss->Parameter (*group, "colorfilter", TypeDesc::TypeColor,
// ss->Parameter (*group, "colorfilter", TypeColor,
// &colorfilter);
// ss->Shader ("surface", "texmap", "texturelayer");
// /* Second layer - generate the BSDF closure: */
Expand Down
48 changes: 11 additions & 37 deletions src/include/osl_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,46 +244,25 @@ class TypeSpec {
// m_simple is always UNKNOWN for structures.

/// Is it a simple scalar int?
bool is_int() const
{
return m_simple == TypeDesc::TypeInt && !is_closure();
}
bool is_int() const { return m_simple == TypeInt && !is_closure(); }

/// Is it a simple scalar float?
bool is_float() const
{
return m_simple == TypeDesc::TypeFloat && !is_closure();
}
bool is_float() const { return m_simple == TypeFloat && !is_closure(); }

/// Is it a color?
bool is_color() const
{
return m_simple == TypeDesc::TypeColor && !is_closure();
}
bool is_color() const { return m_simple == TypeColor && !is_closure(); }

/// Is it a point?
bool is_point() const
{
return m_simple == TypeDesc::TypePoint && !is_closure();
}
bool is_point() const { return m_simple == TypePoint && !is_closure(); }

/// Is it a vector?
bool is_vector() const
{
return m_simple == TypeDesc::TypeVector && !is_closure();
}
bool is_vector() const { return m_simple == TypeVector && !is_closure(); }

/// Is it a normal?
bool is_normal() const
{
return m_simple == TypeDesc::TypeNormal && !is_closure();
}
bool is_normal() const { return m_simple == TypeNormal && !is_closure(); }

/// Is it a simple string?
bool is_string() const
{
return m_simple == TypeDesc::TypeString && !is_closure();
}
bool is_string() const { return m_simple == TypeString && !is_closure(); }

/// Is it a string or an array of strings?
///
Expand Down Expand Up @@ -357,26 +336,21 @@ class TypeSpec {
bool is_vectriple() const
{
return !is_closure()
&& (m_simple == TypeDesc::TypePoint
|| m_simple == TypeDesc::TypeVector
|| m_simple == TypeDesc::TypeNormal);
&& (m_simple == TypePoint || m_simple == TypeVector
|| m_simple == TypeNormal);
}

/// Is it based on a vector-like triple (point, vector, or normal)?
/// (It's ok for it to be an array or closure.)
bool is_vectriple_based() const
{
auto elem = m_simple.elementtype();
return (elem == TypeDesc::TypePoint || elem == TypeDesc::TypeVector
|| elem == TypeDesc::TypeNormal);
return (elem == TypePoint || elem == TypeVector || elem == TypeNormal);
}

/// Is it a simple matrix (but not an array or closure)?
///
bool is_matrix() const
{
return m_simple == TypeDesc::TypeMatrix && !is_closure();
}
bool is_matrix() const { return m_simple == TypeMatrix && !is_closure(); }

/// Is it a color closure?
///
Expand Down
6 changes: 3 additions & 3 deletions src/liboslcomp/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,19 +1032,19 @@ class ASTliteral final : public ASTNode {
ASTliteral(OSLCompilerImpl* comp, int i)
: ASTNode(literal_node, comp), m_i(i)
{
m_typespec = TypeDesc::TypeInt;
m_typespec = TypeInt;
}

ASTliteral(OSLCompilerImpl* comp, float f)
: ASTNode(literal_node, comp), m_f(f)
{
m_typespec = TypeDesc::TypeFloat;
m_typespec = TypeFloat;
}

ASTliteral(OSLCompilerImpl* comp, ustring s)
: ASTNode(literal_node, comp), m_s(s)
{
m_typespec = TypeDesc::TypeString;
m_typespec = TypeString;
}

const char* nodetypename() const { return "literal"; }
Expand Down
4 changes: 2 additions & 2 deletions src/liboslcomp/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ ASTNode::codegen_int(Symbol*, bool boolify, bool invert)
if (!type.is_int() || boolify || invert) {
// If they're not using an int as the condition, then it's an
// implied comparison to zero.
Symbol* tempvar = m_compiler->make_temporary(TypeDesc::TypeInt);
Symbol* tempvar = m_compiler->make_temporary(TypeInt);
Symbol* zerovar = NULL;
if (type.is_closure())
zerovar = m_compiler->make_constant((int)0);
Expand Down Expand Up @@ -1543,7 +1543,7 @@ ASTbinary_expression::codegen(Symbol* dest)
if (m_op == Mul || m_op == Div) {
// Need to coerce the weight into a color.
// N.B. The typecheck always reorders c=k*c into c=c*k.
rsym = coerce(rsym, TypeDesc::TypeColor, true);
rsym = coerce(rsym, TypeColor, true);
}
emitcode(opword(), dest, lsym, rsym);
return dest;
Expand Down
25 changes: 10 additions & 15 deletions src/liboslcomp/oslcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,20 +632,15 @@ struct GlobalTable {
void
OSLCompilerImpl::initialize_globals()
{
static GlobalTable globals[]
= { { "P", TypeDesc::TypePoint, false },
{ "I", TypeDesc::TypeVector, false },
{ "N", TypeDesc::TypeNormal, false },
{ "Ng", TypeDesc::TypeNormal },
{ "u", TypeDesc::TypeFloat },
{ "v", TypeDesc::TypeFloat },
{ "dPdu", TypeDesc::TypeVector },
{ "dPdv", TypeDesc::TypeVector },
{ "Ps", TypeDesc::TypePoint },
{ "Ci", TypeSpec(TypeDesc::TypeColor, true), false },
{ "time", TypeDesc::TypeFloat },
{ "dtime", TypeDesc::TypeFloat },
{ "dPdtime", TypeDesc::TypeVector } };
static GlobalTable globals[] = {
{ "P", TypePoint, false }, { "I", TypeVector, false },
{ "N", TypeNormal, false }, { "Ng", TypeNormal },
{ "u", TypeFloat }, { "v", TypeFloat },
{ "dPdu", TypeVector }, { "dPdv", TypeVector },
{ "Ps", TypePoint }, { "Ci", TypeSpec(TypeColor, true), false },
{ "time", TypeFloat }, { "dtime", TypeFloat },
{ "dPdtime", TypeVector }
};

for (auto& g : globals) {
Symbol* s = new Symbol(ustring(g.name), g.type, SymTypeGlobal);
Expand Down Expand Up @@ -706,7 +701,7 @@ OSLCompilerImpl::write_oso_const_value(const ConstantSymbol* sym) const
else if (elemtype == TypeDesc::FLOAT)
for (int i = 0; i < nelements; ++i)
osofmt("{:.9g}{}", sym->floatval(i), nelements > 1 ? " " : "");
else if (equivalent(elemtype, TypeDesc::TypeVector))
else if (equivalent(elemtype, TypeVector))
for (int i = 0; i < nelements; ++i) {
Vec3 v = sym->get_vec3(i);
osofmt("{:.9g} {:.9g} {:.9g}{}", v.x, v.y, v.z,
Expand Down
16 changes: 8 additions & 8 deletions src/liboslcomp/oslgram.y
Original file line number Diff line number Diff line change
Expand Up @@ -1110,14 +1110,14 @@ inline TypeDesc
OSL::pvt::osllextype (int lex)
{
switch (lex) {
case COLORTYPE : return TypeDesc::TypeColor;
case FLOATTYPE : return TypeDesc::TypeFloat;
case INTTYPE : return TypeDesc::TypeInt;
case MATRIXTYPE : return TypeDesc::TypeMatrix;
case NORMALTYPE : return TypeDesc::TypeNormal;
case POINTTYPE : return TypeDesc::TypePoint;
case STRINGTYPE : return TypeDesc::TypeString;
case VECTORTYPE : return TypeDesc::TypeVector;
case COLORTYPE : return TypeColor;
case FLOATTYPE : return TypeFloat;
case INTTYPE : return TypeInt;
case MATRIXTYPE : return TypeMatrix;
case NORMALTYPE : return TypeNormal;
case POINTTYPE : return TypePoint;
case STRINGTYPE : return TypeString;
case VECTORTYPE : return TypeVector;
case VOIDTYPE : return TypeDesc::NONE;
default: return TypeDesc::UNKNOWN;
}
Expand Down
11 changes: 4 additions & 7 deletions src/liboslcomp/symtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,17 @@ class FunctionSymbol final : public Symbol {
/// the parent class to properly free it upon destruction.
class ConstantSymbol final : public Symbol {
public:
ConstantSymbol(ustring n, ustring val)
: Symbol(n, TypeDesc::TypeString, SymTypeConst)
ConstantSymbol(ustring n, ustring val) : Symbol(n, TypeString, SymTypeConst)
{
m_val.s = val.c_str();
set_dataptr(SymArena::Absolute, &m_val.s);
}
ConstantSymbol(ustring n, int val)
: Symbol(n, TypeDesc::TypeInt, SymTypeConst)
ConstantSymbol(ustring n, int val) : Symbol(n, TypeInt, SymTypeConst)
{
m_val.i = val;
set_dataptr(SymArena::Absolute, &m_val.i);
}
ConstantSymbol(ustring n, float val)
: Symbol(n, TypeDesc::TypeFloat, SymTypeConst)
ConstantSymbol(ustring n, float val) : Symbol(n, TypeFloat, SymTypeConst)
{
m_val.f = val;
set_dataptr(SymArena::Absolute, &m_val.f);
Expand All @@ -148,7 +145,7 @@ class ConstantSymbol final : public Symbol {
set_dataptr(SymArena::Absolute, &m_val.i);
else if (type == TypeDesc::STRING)
set_dataptr(SymArena::Absolute, &m_val.s);
else if (equivalent(type, TypeDesc::TypeVector))
else if (equivalent(type, TypeVector))
set_dataptr(SymArena::Absolute, &m_val.v);
else {
OSL_DASSERT(arena() == SymArena::Unknown);
Expand Down
Loading

0 comments on commit b859317

Please sign in to comment.