MCPcopy Create free account
hub / github.com/aliasIsolation/aliasIsolation / reload

Function reload

src/dll/shaderRegistry.cpp:103–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101 }
102
103 bool reload(ShaderReloadInfo *const reloadInfo, CompiledShader *const shader) {
104 LPCSTR profile =
105 reloadInfo->shaderType == ShaderType::Pixel ? "ps_4_0" :
106 reloadInfo->shaderType == ShaderType::Compute ? "cs_5_0" :
107 "vs_4_0";
108
109 std::vector<char> sourceBlob;
110 for (int retry = 0; retry < 100; ++retry, Sleep(10)) {
111 sourceBlob.clear();
112
113 FILE* f;
114 errno_t err = fopen_s(&f, reloadInfo->path.c_str(), "rb");
115 if (err != 0) {
116 continue;
117 }
118
119 fseek(f, 0, SEEK_END);
120 long fileSize = ftell(f);
121 fseek(f, 0, SEEK_SET);
122
123 sourceBlob.resize(fileSize);
124 const long rb = fread_s(sourceBlob.data(), sourceBlob.size(), 1, fileSize, f);
125
126 fclose(f);
127 if (rb == fileSize) {
128 break; // success
129 }
130
131 sourceBlob.clear();
132 }
133
134 if (0 == sourceBlob.size()) {
135 return false;
136 }
137
138 ID3DBlob* shaderBlob = nullptr;
139 char* shaderBinaryPtr = nullptr;
140 size_t shaderBinaryLength = 0;
141
142 if (sourceBlob.size() > 4 && sourceBlob[0] == 'D' && sourceBlob[1] == 'X' && sourceBlob[2] == 'B' && sourceBlob[3] == 'C')
143 {
144 // Binary shader
145 shaderBinaryPtr = sourceBlob.data();
146 shaderBinaryLength = sourceBlob.size();
147 }
148 else
149 {
150 ID3DBlob* errorBlob = nullptr;
151
152 const char* const entryPoint = reloadInfo->shaderType == ShaderType::Pixel ? "mainPS" :
153 reloadInfo->shaderType == ShaderType::Compute ? "mainCS" :
154 "mainVS";
155
156 HRESULT hr = D3DCompile(
157 sourceBlob.data(),
158 sourceBlob.size(),
159 nullptr,
160 nullptr,

Callers 1

reloadIfModifiedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected