Skip to content

Commit 694a8e5

Browse files
author
hongqingwan
committed
libobs-d3d11: Put d3d11 and d3d12 common functions together
1 parent 0b12296 commit 694a8e5

File tree

10 files changed

+1074
-1015
lines changed

10 files changed

+1074
-1015
lines changed

libobs-d3d11/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ add_library(OBS::libobs-d3d11 ALIAS libobs-d3d11)
66
target_sources(
77
libobs-d3d11
88
PRIVATE
9+
d3dx-common.hpp
10+
d3dx-common.cpp
11+
d3d11-unimplemented.cpp
912
d3d11-duplicator.cpp
1013
d3d11-indexbuffer.cpp
1114
d3d11-rebuild.cpp

libobs-d3d11/d3d11-shader.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <fstream>
2929
#include <d3dcompiler.h>
3030

31-
void gs_vertex_shader::GetBuffersExpected(const vector<D3D11_INPUT_ELEMENT_DESC> &inputs)
31+
void gs_vertex_shader::GetBuffersExpected(const std::vector<D3D11_INPUT_ELEMENT_DESC> &inputs)
3232
{
3333
for (size_t i = 0; i < inputs.size(); i++) {
3434
const D3D11_INPUT_ELEMENT_DESC &input = inputs[i];
@@ -52,7 +52,7 @@ gs_vertex_shader::gs_vertex_shader(gs_device_t *device, const char *file, const
5252
{
5353
ShaderProcessor processor(device);
5454
ComPtr<ID3D10Blob> shaderBlob;
55-
string outputString;
55+
std::string outputString;
5656
HRESULT hr;
5757

5858
processor.Process(shaderString, file);
@@ -88,7 +88,7 @@ gs_pixel_shader::gs_pixel_shader(gs_device_t *device, const char *file, const ch
8888
{
8989
ShaderProcessor processor(device);
9090
ComPtr<ID3D10Blob> shaderBlob;
91-
string outputString;
91+
std::string outputString;
9292
HRESULT hr;
9393

9494
processor.Process(shaderString, file);
@@ -226,26 +226,26 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char *
226226
snprintf(hashstr, sizeof(hashstr), "%02llx", hash);
227227

228228
BPtr program_data = os_get_program_data_path_ptr("obs-studio/shader-cache");
229-
auto cachePath = filesystem::u8path(program_data.Get()) / hashstr;
229+
auto cachePath = std::filesystem::u8path(program_data.Get()) / hashstr;
230230
// Increment if on-disk format changes
231231
cachePath += ".v2";
232232

233233
std::fstream cacheFile;
234-
cacheFile.exceptions(fstream::badbit | fstream::eofbit);
234+
cacheFile.exceptions(std::fstream::badbit | std::fstream::eofbit);
235235

236-
if (filesystem::exists(cachePath) && !filesystem::is_empty(cachePath))
237-
cacheFile.open(cachePath, ios::in | ios::binary | ios::ate);
236+
if (std::filesystem::exists(cachePath) && !std::filesystem::is_empty(cachePath))
237+
cacheFile.open(cachePath, std::ios::in | std::ios::binary | std::ios::ate);
238238

239239
if (cacheFile.is_open()) {
240240
uint64_t checksum;
241241

242242
try {
243-
streampos len = cacheFile.tellg();
243+
std::streampos len = cacheFile.tellg();
244244
// Not enough data for checksum + shader
245245
if (len <= sizeof(checksum))
246-
throw length_error("File truncated");
246+
throw std::length_error("File truncated");
247247

248-
cacheFile.seekg(0, ios::beg);
248+
cacheFile.seekg(0, std::ios::beg);
249249

250250
len -= sizeof(checksum);
251251
D3DCreateBlob(len, shader);
@@ -254,14 +254,14 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char *
254254

255255
cacheFile.read((char *)&checksum, sizeof(checksum));
256256
if (calculated_checksum != checksum)
257-
throw exception("Checksum mismatch");
257+
throw std::exception("Checksum mismatch");
258258

259259
is_cached = true;
260-
} catch (const exception &e) {
260+
} catch (const std::exception &e) {
261261
// Something went wrong reading the cache file, delete it
262262
blog(LOG_WARNING, "Loading shader cache file failed with \"%s\": %s", e.what(), file);
263263
cacheFile.close();
264-
filesystem::remove(cachePath);
264+
std::filesystem::remove(cachePath);
265265
}
266266
}
267267

@@ -275,18 +275,18 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char *
275275
throw HRError("Failed to compile shader", hr);
276276
}
277277

278-
cacheFile.open(cachePath, ios::out | ios::binary);
278+
cacheFile.open(cachePath, std::ios::out | std::ios::binary);
279279
if (cacheFile.is_open()) {
280280
try {
281281
uint64_t calculated_checksum =
282282
fnv1a_hash((char *)(*shader)->GetBufferPointer(), (*shader)->GetBufferSize());
283283

284284
cacheFile.write((char *)(*shader)->GetBufferPointer(), (*shader)->GetBufferSize());
285285
cacheFile.write((char *)&calculated_checksum, sizeof(calculated_checksum));
286-
} catch (const exception &e) {
286+
} catch (const std::exception &e) {
287287
blog(LOG_WARNING, "Writing shader cache file failed with \"%s\": %s", e.what(), file);
288288
cacheFile.close();
289-
filesystem::remove(cachePath);
289+
std::filesystem::remove(cachePath);
290290
}
291291
}
292292
}
@@ -303,7 +303,7 @@ void gs_shader::Compile(const char *shaderString, const char *file, const char *
303303
#endif
304304
}
305305

306-
inline void gs_shader::UpdateParam(vector<uint8_t> &constData, gs_shader_param &param, bool &upload)
306+
inline void gs_shader::UpdateParam(std::vector<uint8_t> &constData, gs_shader_param &param, bool &upload)
307307
{
308308
if (param.type != GS_SHADER_PARAM_TEXTURE) {
309309
if (!param.curValue.size())
@@ -342,7 +342,7 @@ inline void gs_shader::UpdateParam(vector<uint8_t> &constData, gs_shader_param &
342342

343343
void gs_shader::UploadParams()
344344
{
345-
vector<uint8_t> constData;
345+
std::vector<uint8_t> constData;
346346
bool upload = false;
347347

348348
constData.reserve(constantSize);

libobs-d3d11/d3d11-shaderprocessor.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ struct ShaderProcessor {
2828
gs_device_t *device;
2929
ShaderParser parser;
3030

31-
void BuildInputLayout(vector<D3D11_INPUT_ELEMENT_DESC> &inputs);
32-
void BuildParams(vector<gs_shader_param> &params);
33-
void BuildSamplers(vector<unique_ptr<ShaderSampler>> &samplers);
34-
void BuildString(string &outputString);
31+
void BuildInputLayout(std::vector<D3D11_INPUT_ELEMENT_DESC> &inputs);
32+
void BuildParams(std::vector<gs_shader_param> &params);
33+
void BuildSamplers(std::vector<std::unique_ptr<ShaderSampler>> &samplers);
34+
void BuildString(std::string &outputString);
3535
void Process(const char *shader_string, const char *file);
3636

3737
inline ShaderProcessor(gs_device_t *device) : device(device) {}

0 commit comments

Comments
 (0)