8 #ifndef __VOP_CodeGenerator_h__
9 #define __VOP_CodeGenerator_h__
28 #define VOP_MININPUTS_NAME "mininputs"
29 #define VOP_MAXINPUTS_NAME "maxinputs"
36 #define VOP_AUTO_SHADER_PREFIX "_auto_"
37 #define VOP_AUTO_SHADER_PREFIX_LEN 6
38 #define VOP_AUTO_SHADER_FN_PREFIX "auto_"
39 #define VOP_AUTO_SHADER_FN_PREFIX_LEN 5
52 class VOP_VopTypeDefiner;
54 class VOP_ObjectCodeArgs;
57 class VCC_Diagnostics;
58 class VCC_DiagnosticInfo;
63 class vop_CodeCacheData;
64 class vop_CodeGenOutputContext;
73 {
return "VOP_SnippetMicroNode"; }
126 {
return myExportedParmsMgr; }
127 virtual bool hasShaderParameter(
const char *parm_name);
129 void beforeAddNode(
OP_Node *node);
130 void afterAddNode(
OP_Node *node);
146 void endUpdate(
int update_level);
150 myNeedsCodeUpdate =
false;
152 void setNeedsCodeUpdate();
156 void ownerFinishedLoadingNetwork();
157 void generateVopErrors();
161 const char *getEnglishName();
174 int getMinimumInputs()
const;
175 int getMaximumInputs()
const;
179 bool canGenerateCode(
VOP_Type shader_type )
const;
184 void setVexCodeDirty();
197 bool outputVexCode(std::ostream &os,
const char *shadername,
200 bool *is_pure_compiled =
nullptr,
206 return findCachedCode(context_type) ?
true :
false;
226 virtual bool outputVflCode(
227 std::ostream &os,
const char *shadername,
230 bool skipheader =
false,
231 const char * output_node_name =
nullptr,
232 VCC_Diagnostics *diag =
nullptr,
237 bool outputEncapsulatedVflCode(
240 const char *function_name,
243 bool generate_outer_code);
263 int getCachedCodeTimeStamp(
266 bool hasCachedCode()
const;
269 const char *cache_directory,
270 const char *renderer,
273 const char *shaderpath,
274 const char *shadername,
276 bool ignore_dirty_flag,
280 const char *cache_directory,
281 const char *shaderpath,
282 const char *shadername,
284 bool ignore_dirty_flag,
288 void getClassMethodInfos(
304 const char *defcompiler);
306 const char *defcompiler);
311 bool getGeneratorErrors(
UT_String &errors)
const;
312 bool getGeneratorErrors(
UT_String &errors,
314 bool getGeneratorErrorsAndWarnings(
UT_String &msgs)
const;
315 bool getGeneratorErrorsAndWarnings(
UT_String &msgs,
318 bool getDiagnosticsForNode(
VOP_Node *node,
324 {
return myLanguage; }
330 {
return myContextTypeList; }
341 { myIsAutoGenerator = is_auto; }
343 {
return myIsAutoGenerator; }
356 bool needsToGenerateAutoShader(
357 bool allow_value_inputs =
false)
const;
361 bool isSingleContextType()
const;
364 bool isClassBasedShader()
const;
367 bool isClassBasedShader(
377 {
return myOwnerHasParameters; }
395 {
return myCompilerArgs; }
400 void setLockedCompiledCode(
402 bool is_source_code);
413 static void installCommands();
417 static bool convertVopOpToVopOpType(
OP_Node *node,
421 static const char *getDefaultVEXMask();
432 static bool forceCompile(
OP_Node *node);
433 static int forceCompile(
void *
data,
int,
fpreal,
454 void getVopFunctionArgInfosFromExports(
468 {
return myErrorMicroNode; }
470 static void formatDiagnostic(
const VCC_DiagnosticInfo &info,
482 bool getNodesForContextOrNodeFunctionVflCode(
487 const char *output_node_name,
489 VCC_Diagnostics *diagnostics);
496 bool getNodesForSubnetFunctionVflCode(
VOP_NodeList &nodes,
500 bool require_context_check);
507 {
return myNeedAutoConvertCleanup; }
511 { myUseIfdefVex = flag; }
515 { myOmitPragmas = flag; }
529 { myIsChangingAutoShader = flag; }
531 {
return myIsChangingAutoShader; }
536 void generateObjectCode(VOP_ObjectCodeArgs *
args);
540 {
return myLockedCompiledCode[context_type].length() > 0; }
543 void outputVflHeaderComment(std::ostream &os);
544 void outputShaderDefines(std::ostream &os,
546 bool outputShaderVflCodeBlock(std::ostream &os,
547 const char *shadername,
550 const char *output_node_name,
551 VCC_Diagnostics *diagnostics);
552 bool outputStandardShaderVflCodeBlock(std::ostream &os,
553 const char *shadername,
556 const char *output_node_name,
557 VCC_Diagnostics *diagnostics);
558 bool outputFunctionVflCodeBlock(std::ostream &os,
559 const char *function_name,
563 bool generate_outer_code);
564 bool outputMethodVflCodeBlock(
565 const vop_CodeGenOutputContext &output_ctx,
569 VCC_Diagnostics *diagnostics);
570 bool outputClassVflCodeBlock(std::ostream &os,
571 const char *shadername,
574 VCC_Diagnostics *diagnostics);
575 void outputVflPragmas(std::ostream &os,
578 void outputVflFunctionBlock(
579 const vop_CodeGenOutputContext &output_ctx,
583 const char *return_type,
584 const char *function_name,
588 bool generate_outer_code);
589 void outputIsConnectedDeclarations(std::ostream &os,
593 void outputShaderVflDeclaration(
594 const vop_CodeGenOutputContext &output_ctx,
596 const char *return_type,
597 const char *function_name,
599 void outputClassVflDeclaration(
600 const vop_CodeGenOutputContext &output_ctx,
601 const char *shadername,
603 void outputStructVflDeclaration(
604 const vop_CodeGenOutputContext &output_ctx,
605 const char *shadername);
606 void outputFunctionVflDeclaration(
607 const vop_CodeGenOutputContext &output_ctx,
610 const char *return_type,
611 const char *function_name,
614 void outputVflEmptyShaderFunction(std::ostream &os,
615 const char *shadername,
617 void outputShaderParameterDeclarations(std::ostream &os,
621 void outputMemberVariableDeclarations(
622 const vop_CodeGenOutputContext &output_ctx);
623 void outputFunctionParameterDeclarations(std::ostream &os,
630 void getFunctionNameOrOverride(
UT_String &function_name,
631 const char *
override);
633 void clearFileCache();
641 bool hasSubscribingSiblings(
VOP_Type shader_type )
const;
662 bool only_essential)
const;
672 void ensureDstDirCreated(
UT_String &output_file_no_ext,
673 const char *
path,
const char *shaderpath,
674 const char *shadername,
const char *context_suffix);
677 const char *shadername,
680 bool usesStandardVCCOptions();
684 void getContextFileSuffix(
UT_String & suffix,
688 vop_CodeCacheData * findCachedCode(
VOP_ContextType context_type )
const;
695 vop_CodeCacheData * cache_data );
696 void copyCachedErrorToDiagnostic(
697 const vop_CodeCacheData * cache_data );
698 void clearCachedCode();
701 bool getCachedMessages(
709 bool isMetaSwitchParm(
int parm_index)
const;
712 bool isMantraShadingContext(
715 void checkForErrorsOnChildren(
OP_Context &cxt,
724 void generateErrorsAndPropagateToOwner();
741 mutable UT_Lock myCachedCodeLock;
747 int myMinimumNumberOfInputs;
748 int myMaximumNumberOfInputs;
750 mutable int myCollectNodeId;
752 bool myNeedsCodeUpdate;
754 bool myOwnerHasParameters;
755 bool myIsReCookingOwner;
756 bool myNeedAutoConvertCleanup;
760 bool myIsAutoGenerator;
761 bool myIsChangingAutoShader;
775 VOP_VopTypeDefiner * myVopTypeDefiner;
824 const char *shader_name );
827 {
return myNestedSubnetShaders; }
829 { myNestedSubnetShaders[sub_shader] =
name; }
833 bool shouldAddSubShader(
VOP_Node *shader_node)
const;
836 void replaceSubShaderNamePrefix(
UT_String &sub_shader_name,
840 void removeShaderNamePrefix(
UT_String &sub_shader_name )
const;
Reprsents a language for which VOPs can generate source code.
static PRM_Name theVopCompilerName
UT_ErrorManager & getErrorManager()
OP_Network * ownerNetwork() const
void addSubShader(VOP_Node *sub_shader, const char *name) const
virtual void becameDirty(DEP_MicroNode &src, const DEP_PropagateData &propdata)
GLuint const GLchar * name
static PRM_Default theVopCompilerOslDefault
bool isVexCodeCached(VOP_ContextType context_type) const
Determines if the giving context has already been cached.
void setOmitPragmas(bool flag)
Controls whether the source code contains pragmas.
void addExplicitInput(DEP_MicroNode &inp, bool check_dup)
Methods for manipulating explicit edges.
const UT_Map< VOP_Node *, UT_StringHolder > & getNestedSubnetShaders() const
bool isAutoGenerator() const
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
bool getOwnerHasParameters() const
void setIsAutoGenerator(bool is_auto)
const char * className() const override
static PRM_Name theVopForceCompileName
std::map< VOP_ContextType, std::string > TContextTypeStringMap
void setUseIfdefVex(bool flag)
Controls whether the source code is laced with #ifdef __vex.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
GLsizei GLenum GLenum * types
static PRM_ChoiceList theVopCompilerChoices
static PRM_Default theVopCompilerRslDefault
VOP_CodeGenerator & myCodeGenerator
VOP_ExportedParmsManager * exportedParmsManager() const
Return the exported parameters manager.
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
void stealErrors(UT_ErrorManager &src, bool borrow_only=false)
void clearAllUpdateFlags()
GLint GLenum GLsizei GLint GLsizei const void * data
bool needsAutoConvertCleanup() const
~VOP_CodeGeneratorErrorThief()
#define VOP_CONTEXT_TYPE_INVALID
const VOP_Language * getLanguage() const
Get the VOP language generated by this code generator.
VOP_ErrorMicroNode & errorMicroNode()
UT_Array< VCC_DiagnosticInfo > VCC_DiagnosticList
OSL_ContextType
RenderMan shader context types.
Class that contains information about a struct/class method.
GLsizei const GLchar *const * path
void addCodeDependency(DEP_MicroNode *target)
const VOP_LanguageContextTypeList * getLanguageContextTypeList() const
VEX_CodeGenFlags
VEX code generation flags when calling VEX_VexResolver::getVflCode.
VOP_CodeCompilerArgs * getCompilerArgs()
Returns the compiler arguments.
virtual bool allowOperatorAsChild(OP_Operator *)
A global error manager scope.
Propagation info for a dep micro node.
VOP_CodeGeneratorErrorThief(OP_Node &node)
RSL_ContextType
RenderMan shader context types.
virtual VOP_CodeGenerator * getVopCodeGenerator()
bool getIsChangingAutoShader() const
static PRM_Default theVopCompilerVexDefault
void setIsChangingAutoShader(bool flag)
GLsizei const GLfloat * value