-
Notifications
You must be signed in to change notification settings - Fork 360
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
Remove direct access to ShaderGlobals members from llvm_ops #1414
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4054,8 +4054,8 @@ LLVMGEN (llvm_gen_calculatenormal) | |
|
||
llvm::Value *args[] = { | ||
rop.llvm_void_ptr (Result), | ||
rop.sg_void_ptr(), | ||
rop.llvm_load_arg (P, true /*derivs*/, false /*op_is_uniform*/), | ||
rop.llvm_global_symbol_ptr(Strings::flipHandedness), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a matter of sanity checking, might consider pulling the global_symbol_ptr out and passing the optional is_uniform parameter and OSL_ASSERT(!is_uniform) as the function being called will interpret the pointer as varying. |
||
nullptr}; | ||
int arg_count = 3; | ||
|
||
|
@@ -4313,19 +4313,15 @@ LLVMGEN (llvm_gen_raytype) | |
llvm::Value * sg = rop.sg_void_ptr(); | ||
if (Name.is_constant()) { | ||
// We can statically determine the bit pattern | ||
ustring name = ((ustring *)Name.data())[0]; | ||
llvm::Value *args[] = { | ||
sg, | ||
rop.ll.constant (rop.shadingsys().raytype_bit (name))}; | ||
|
||
llvm::Value *ret = rop.ll.call_function (rop.build_name("raytype_bit"), args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to remove |
||
|
||
if(!result_is_uniform) | ||
{ | ||
llvm::Value* bit; | ||
bit = rop.ll.constant(rop.shadingsys().raytype_bit(Name.get_string())); | ||
llvm::Value* raytype = rop.ll.op_load_int( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if less is more, meaning was op_load_int needed, in that LLVM_Util::ptr_to_cast or LLVM_Util::ptr_cast and LLVM_Util::op_load which could be used to provide the same functionality. |
||
rop.llvm_global_symbol_ptr(Strings::raytype)); | ||
llvm::Value* bitanded = rop.ll.op_and(raytype, bit); | ||
llvm::Value* ret = rop.ll.op_int_to_bool_to_int(bitanded); | ||
if (!result_is_uniform) | ||
ret = rop.ll.widen_value(ret); | ||
} | ||
rop.llvm_store_value (ret, Result); | ||
|
||
} else { | ||
FuncSpec func_spec("raytype_name"); | ||
// No way to know which name is being asked for | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the non-const case suggest following the same pattern you did for llvm_gen, go into wide_shading.cpp and rename the uniform and varying versions of raytype_name to raytype_bit. For the uniform verson of raytype_name just return the bit by removing the bitwise AND For the varying version, leave the foreach_unique loop, but again drop the bitwise AND
To simplify, you can can probably combine some of the code between the uniform and non-uniform branches |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,7 @@ DECL (osl_dict_find_iis, "iXiX") | |
DECL (osl_dict_find_iss, "iXXX") | ||
DECL (osl_dict_next, "iXi") | ||
DECL (osl_dict_value, "iXiXLX") | ||
DECL (osl_raytype_name, "iXX") | ||
DECL (osl_raytype_bit, "iXX") | ||
#ifdef OSL_LLVM_NO_BITCODE | ||
DECL (osl_range_check, "iiiXXXiXiXX") | ||
#endif | ||
|
@@ -376,11 +376,11 @@ DECL (osl_trace_set_traceset, "xXs") | |
DECL (osl_trace, "iXXXXXXXX") | ||
|
||
#ifdef OSL_LLVM_NO_BITCODE | ||
DECL (osl_calculatenormal, "xXXX") | ||
DECL (osl_calculatenormal, "xXXi") | ||
DECL (osl_area, "fX") | ||
DECL (osl_filterwidth_fdf, "fX") | ||
DECL (osl_filterwidth_vdv, "xXX") | ||
DECL (osl_raytype_bit, "iXi") | ||
DECL (osl_raytype_bit_from_name, "iXi") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see |
||
#endif | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4174,15 +4174,17 @@ osl_range_check_err (int indexvalue, int length, const char *symname, | |
|
||
|
||
|
||
// Return the raytype bit corresponding to a raytype name. | ||
// Asked if the raytype is a name we can't know until mid-shader. | ||
OSL_SHADEOP int osl_raytype_name (void *sg_, void *name) | ||
// FIXME: We should pass the context, not the sg. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a FIXME, any technical barrier to passing context? For that matter, I've been pondering a ReadOnlyContext or DeviceContext that might be a stripped down version of the full context to answer just these types of questions. |
||
OSL_SHADEOP int osl_raytype_bit (void *sg_, void *name) | ||
{ | ||
ShaderGlobals *sg = (ShaderGlobals *)sg_; | ||
int bit = sg->context->shadingsys().raytype_bit (USTR(name)); | ||
return (sg->raytype & bit) != 0; | ||
return sg->context->shadingsys().raytype_bit(USTR(name)); | ||
} | ||
|
||
|
||
|
||
OSL_SHADEOP int osl_get_attribute(void *sg_, | ||
int dest_derivs, | ||
void *obj_name_, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does op_int_to_bool_to_int generate better code than opt_bool_to_int(op_ne(a, constant(0)))?
If so might be useful elsewhere.