MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/Cauldron / HashShaderString

Function HashShaderString

src/common/base/ShaderCompiler.cpp:27–96  ·  view source on GitHub ↗

Hash a string of source code and recurse over its #include files

Source from the content-addressed store, hash-verified

25// Hash a string of source code and recurse over its #include files
26//
27size_t HashShaderString(const char *pRootDir, const char *pShader, size_t hash)
28{
29 hash = Hash(pShader, strlen(pShader), hash);
30
31 const char *pch = pShader;
32 while (*pch != 0)
33 {
34 if (*pch == '/') // parse comments
35 {
36 pch++;
37 if (*pch != 0 && *pch == '/')
38 {
39 pch++;
40 while (*pch != 0 && *pch != '\n')
41 pch++;
42 }
43 else if (*pch != 0 && *pch == '*')
44 {
45 pch++;
46 while ( (*pch != 0 && *pch != '*') && (*(pch+1) != 0 && *(pch+1) != '/'))
47 pch++;
48 }
49 }
50 else if (*pch == '#') // parse #include
51 {
52 pch++;
53 const char include[] = "include";
54 int i = 0;
55 while ((*pch!= 0) && *pch == include[i])
56 {
57 pch++;
58 i++;
59 }
60
61 if (i == strlen(include))
62 {
63 while (*pch != 0 && *pch == ' ')
64 pch++;
65
66 if (*pch != 0 && *pch == '\"')
67 {
68 pch++;
69 const char *pName = pch;
70
71 while (*pch != 0 && *pch != '\"')
72 pch++;
73
74 char includeName[1024];
75 strcpy_s<1024>(includeName, pRootDir);
76 strncat_s<1024>(includeName, pName, pch - pName);
77
78 pch++;
79
80 char *pShaderCode = NULL;
81 if (ReadFile(includeName, &pShaderCode, NULL, false))
82 {
83 hash = HashShaderString(pRootDir, pShaderCode, hash);
84 free(pShaderCode);

Callers 2

DXCompileFunction · 0.85
VKCompileFunction · 0.85

Calls 2

HashFunction · 0.85
ReadFileFunction · 0.85

Tested by

no test coverage detected