Skip to content

Commit

Permalink
Add helper functions and comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Curtis Black <[email protected]>
  • Loading branch information
curtisblack committed Aug 17, 2023
1 parent e4efe31 commit 4ad7c1d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/include/OSL/oslconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ ustringrep_from(string_view s)



using TypeDesc_pod = long long;



/// Convenience function to convert to a TypeDesc.
inline TypeDesc
TypeDesc_from(TypeDesc_pod type)
{
return OSL::bitcast<OSL::TypeDesc>(type);
}



// N.B. SymArena is not really "configuration", but we cram it here for
// lack of a better home.

Expand Down
5 changes: 3 additions & 2 deletions src/include/OSL/rendererservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ enum class AttributeSpecBuiltinArg {
ShaderGlobalsPointer, // void* (TODO: ideally ShaderGlobals*)
ShadeIndex, // int
Derivatives, // bool
Type, // long long (TODO: ideally TypeDesc)
Type, // TypeDesc_pod
ArrayIndex, // int, Always zero for non-indexed array lookups.
ArrayLookup, //bool
ArrayLookup, // bool
ObjectName, // const char* (TODO: change to ustringhash)
AttributeName, // const char* (TODO: change to ustringhash)
};
Expand Down Expand Up @@ -451,6 +451,7 @@ class OSLEXECPUBLIC RendererServices {
TypeDesc::VECSEMANTICS vectype);

/// @brief Builds a free function to provide a value for a given attribute.
/// This occurs at shader compile time, not at execution time.
/// @param group The shader group currently requesting the attribute.
/// @param object_lookup True if an object name was specified, even if the
/// value is not known at compile time.
Expand Down
8 changes: 6 additions & 2 deletions src/testshade/rs_simplerend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,19 @@ rs_get_attribute_constant_float4(float value1, float value2, float value3,

OSL_RSOP bool
rs_get_attribute(void* _sg, const char* _object, const char* _name,
long long _type, bool derivatives, int index, void* result)
OSL::TypeDesc_pod _type, bool derivatives, int index,
void* result)
{
OSL::ShaderGlobals* sg = reinterpret_cast<OSL::ShaderGlobals*>(_sg);
const OSL::StringParam object = OSL::bitcast<OSL::ustringrep>(_object);
const OSL::StringParam name = OSL::bitcast<OSL::ustringrep>(_name);
const OSL::TypeDesc type = OSL::bitcast<OSL::TypeDesc>(_type);
const OSL::TypeDesc type = OSL::TypeDesc_from(_type);

const RenderState* rs = reinterpret_cast<RenderState*>(sg->renderstate);

// The many branches in the code below handle the case where we don't know
// the attribute name at compile time. In the case it is known, dead-code
// elimination should optimize this to only the relevant branch.
if (name == "osl:version" && type == OSL::TypeInt)
return rs_get_attribute_constant_int(OSL_VERSION, result);
if (name == "camera:resolution"
Expand Down

0 comments on commit 4ad7c1d

Please sign in to comment.