Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpoint to phase 2 of the great ustringhash conversion #1612

Merged
merged 2 commits into from
Nov 4, 2022

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Oct 20, 2022

Reminder: phase 1 changed the RendererServices APIs to be based completely on ustringhash for public method calls, not ustring.

This PR starts along the path of phase 2.

In oslconfig.h, I define a new type ustringrep which is the in-memory/in-shader CPU-side representation of a ustring. Currently, it's still equivalent to a ustring.

I also define a type called ustring_pod, which is the "plain old data" representation inside a ustringrep (i.e., a const char* when it's a ustring, and a uint64_t when it's a ustringhash). For reasons not important, it's exceedingly hard to pass a true ustring/ustringhash as parameters to or from LLVM-jitted code without running afoul of LLVM's type checking, so it's just easier to pass the underlying data type.

So the main work of phase 2 is to change everything related to shader data from a ustring into a ustringrep, and things passed as const char* into passing a ustring_pod. In some sense, it's just renaming and type conversion plumbing. When that's done, phase 3 is to throw the switch and change the definition of ustringrep to ustringhash (and of course fix everything that's broken).

This PR does not complete phase 2, but takes a big bite out of it. It's an arbitrary bite, not much rhyme or reason to which specific parts I did so far. Just working on it piece by piece and felt that this was a place where much has been done, everything still works, and it's a reviewable chunk without getting too much out of control.

Areas I worked on are related to range_check, raytype, getattribute, bind_interpolated_param, uninit_check, naninf_check, getmessage/setmessage, some texture setup, pointcloud.

Signed-off-by: Larry Gritz lg@larrygritz.com

@@ -1294,8 +1294,13 @@ BackendLLVM::initialize_llvm_group()
TypeSpec rettype = OSLCompilerImpl::type_from_code(types, &advance);
types += advance;
std::vector<llvm::Type*> params;
// bool debug = OIIO::Strutil::contains(funcname, "range");
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to leave these commented out lines here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, that's a mistake, will remove

{
const ustring& name(USTR(name_));
const ustring& sourcefile(USTR(sourcefile_));
ustringhash name = ustringhash_from(USTR(name_));
Copy link
Contributor

Choose a reason for hiding this comment

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

Does USTR(...) casting need to be involved anymore? I thought a benefit of these changes is to not need that very pointer/reinterpret_cast'ish and just use the ustring_rep or ustring_pod?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think in most cases, that's where we'll eventually get to, yes.

USTR(ustring_pod s) noexcept
{
return OSL::bitcast<ustringrep>(s);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should USTR(...) be removed and just use USTREP because their implementations are identical. If not, maybe a comment here about the transition plan.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I'm leaning that way as I touch things. Mostly I was trying USTREP on for size because USTR was making me continually wonder whether it was a ustring or a ustringrep.
Will transition this over time.

@AlexMWells
Copy link
Contributor

AlexMWells commented Oct 20, 2022

Consider changing name of ustring_pod to ustring_param as that makes it more clear where its going to be used.

@AlexMWells
Copy link
Contributor

When all this is totally done (past stage 3 with the switch thrown), would the idea be to remove ustringrep and just have ustringhash?

@@ -181,6 +214,18 @@ ustringrep_from(ustring u)
#endif
}

/// Convenience function to convert to a ustringrep.
inline ustringrep
ustringrep_from(string_view s)
Copy link
Contributor

Choose a reason for hiding this comment

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

should additional overloads of
ustringrep ustringrep_from(ustring_pod)
be provided and used instead of the USTREP(...) or USTR(...) casts as it better represents the transition?

@lgritz
Copy link
Collaborator Author

lgritz commented Nov 3, 2022

Consider changing name of ustring_pod to ustring_param as that makes it more clear where its going to be used.

Ha, it was ustring_param until the last minute, when I thought that was unclear and renamed it ustring_pod. I'm still on the fence about the final name. I think where my head was can be summarized as that "param" made me think "how is this different from passing a ustring as the param?" whereas the pod was to emphasize that it's the non-class, plain-old-data representation of what's inside a ustring.

@lgritz
Copy link
Collaborator Author

lgritz commented Nov 3, 2022

When all this is totally done (past stage 3 with the switch thrown), would the idea be to remove ustringrep and just have ustringhash?

Yeah, I think so. I wanted a temporary name in the interim that I can easy switch back and forth. Once everything is working, it may just get wholesale replaced by ustringhash.

@lgritz
Copy link
Collaborator Author

lgritz commented Nov 3, 2022

I think we should treat all this nomenclature as temporary. When this work gets completed, some of them will no longer be necessary at all, and for others we can then choose what names we want on a permanent basis.

@AlexMWells
Copy link
Contributor

it was ustring_param until the last minute, when I thought that was unclear and renamed it ustring_pod. I'm still on the fence about the final name. I think where my head was can be summarized as that "param" made me think "how is this different from passing a ustring as the param?" whereas the pod was to emphasize that it's the non-class, plain-old-data representation of what's inside a ustring.

I had similar issue, mostly when do I use ustring_pod vs. ustring vs ustringhash

@AlexMWells
Copy link
Contributor

AlexMWells commented Nov 3, 2022

I think it just might be a bit weird because its in an intermediate state. Forward looking,
ustringrep would just be gone, replaced with ustringhash
ustring_pod would be gone, replaced with ustringhash::hash_t
?

@lgritz
Copy link
Collaborator Author

lgritz commented Nov 3, 2022

Yeah, I think something like that is the final state.

@AlexMWells
Copy link
Contributor

Maybe don't worry about the names then (as they are intermediate) but I do recommend killing off the casting USTR macros and using helper functions.

Reminder: phase 1 changed the RendererServices APIs to be based
completely on ustringhash for public method calls, not ustring.

This PR starts along the path of phase 2.

In oslconfig.h, I define a new type `ustringrep` which is the
in-memory/in-shader CPU-side representation of a ustring. Currently,
it's still equivalent to a ustring.

I also define a type called `ustring_pod`, which is the "plain old
data" representation inside a ustringrep (i.e., a const char* when
it's a ustring, and a uint64_t when it's a ustringhash). For reasons
not important, it's exceedingly hard to pass a true
ustring/ustringhash as parameters to or from LLVM-jitted code without
running afoul of LLVM's type checking, so it's just easier to pass the
underlying data type.

So the main work of phase 2 is to change everything related to shader
data from a ustring into a ustringrep, and things passed as const
char* into passing a ustring_pod. In some sense, it's just renaming
and type conversion plumbing.  When that's done, phase 3 is to throw
the switch and change the definition of ustringrep to ustringhash (and
of course fix everything that's broken).

This PR does not complete phase 2, but takes a big bite out of it.
It's an arbitrary bite, not much rhyme or reason to which specific
parts I did so far. Just working on it piece by piece and felt that
this was a place where much has been done, everything still works, and
it's a reviewable chunk without getting too much out of control.

Areas I worked on are related to range_check, raytype, getattribute,
bind_interpolated_param, uninit_check, range_check, naninf_check,
getmessage/setmessage, some texture setup, pointcloud.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
Copy link
Collaborator Author

lgritz commented Nov 4, 2022

Ok, I'm going to merge as it is and move on, cleaning up these things we've mentioned as I go.

@AlexMWells
Copy link
Contributor

Sounds good to me

@lgritz lgritz merged commit bd7fd4c into AcademySoftwareFoundation:main Nov 4, 2022
@lgritz lgritz deleted the lg-ustringrep branch September 15, 2023 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants