Skip to content

Commit

Permalink
Some small tweaks to compile under c++17.
Browse files Browse the repository at this point in the history
These are almost all char vs. byte variants, and c++17 is strict about byte != char.

Add some casting, and convert some vectors from byte to char where it's clear they actually are char.

This all compiles without errors now, but is untested.
  • Loading branch information
bo3b committed Aug 20, 2024
1 parent edba148 commit 19e636a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions D3DCompiler/d3dcWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ HRESULT WINAPI D3DCompile(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
binaryHash = fnv_64_buf((*ppCode)->GetBufferPointer(), (*ppCode)->GetBufferSize());
sprintf(shaderName, "%08lx%08lx-%s_%08lx%08lx.txt", (UINT32)(binaryHash >> 32), (UINT32)binaryHash, pTarget, (UINT32)(sourceHash >> 32), (UINT32)sourceHash);
LogInfo(" Filename = %s\n", shaderName);
LogInfo(" Compiled bytecode size = %d, bytecode handle = %p\n", (*ppCode)->GetBufferSize(), (*ppCode)->GetBufferPointer());
LogInfo(" Compiled bytecode size = %llu, bytecode handle = %p\n", (*ppCode)->GetBufferSize(), (*ppCode)->GetBufferPointer());

if (SHADER_PATH[0])
{
Expand Down Expand Up @@ -487,7 +487,7 @@ HRESULT WINAPI D3DCompile(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
pSrcData = new char[SrcDataSize];
fread((void *) pSrcData, 1, SrcDataSize, f);
fclose(f);
LogInfo(" Source code loaded. Size = %d\n", SrcDataSize);
LogInfo(" Source code loaded. Size = %llu\n", SrcDataSize);


// Compile replacement.
Expand Down
2 changes: 1 addition & 1 deletion D3D_Shaders/Assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2892,7 +2892,7 @@ HRESULT disassemblerDX9(vector<byte> *buffer, vector<byte> *ret, const char *com
}
#endif

HRESULT disassembler(vector<byte> *buffer, vector<byte> *ret, const char *comment,
HRESULT disassembler(vector<byte> *buffer, vector<char> *ret, const char *comment,
int hexdump, bool d3dcompiler_46_compat,
bool disassemble_undecipherable_data,
bool patch_cb_offsets)
Expand Down
11 changes: 7 additions & 4 deletions D3D_Shaders/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
#include <vector>
#include <unordered_map>

using namespace std;
using std::byte;
using std::vector;
using std::string;


// VS2013 BUG WORKAROUND: Make sure this class has a unique type name!
class AssemblerParseError: public exception {
class AssemblerParseError: public std::exception {
public:
string context, desc, msg;
int line_no;
Expand All @@ -35,7 +38,7 @@ class AssemblerParseError: public exception {
{
msg = "Assembly parse error";
if (line_no > 0)
msg += string(" on line ") + to_string(line_no);
msg += string(" on line ") + std::to_string(line_no);
msg += ", " + desc + ":\n\"" + context + "\"";
}

Expand Down Expand Up @@ -84,7 +87,7 @@ struct token_operand
};

vector<string> stringToLines(const char* start, size_t size);
HRESULT disassembler(vector<byte> *buffer, vector<byte> *ret, const char *comment,
HRESULT disassembler(vector<byte> *buffer, vector<char> *ret, const char *comment,
int hexdump = 0, bool d3dcompiler_46_compat = false,
bool disassemble_undecipherable_data = false,
bool patch_cb_offsets = false);
Expand Down
9 changes: 8 additions & 1 deletion HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,14 @@ static int process(string const *filename)
// if (args.validate)
// disassemble again and perform fuzzy compare

output = string(new_bytecode.begin(), new_bytecode.end());
// c++17 requires a stricter byte vs char, so this approach no longer works.
// output = string(new_bytecode.begin(), new_bytecode.end());
// Instead of that, let's just do the obvious loop to build the string.
// In this case, it's not actually a string or chars, it actually is bytes,
// so probably we'd rather have a better WriteOutput
for (std::byte b : new_bytecode)
output.push_back(static_cast<char>(b));

if (WriteOutput(filename, ".shdr", &output))
return EXIT_FAILURE;

Expand Down
2 changes: 1 addition & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ static string BinaryToAsmText(const void *pShaderBytecode, size_t BytecodeLength
{
string comments;
vector<byte> byteCode(BytecodeLength);
vector<byte> disassembly;
vector<char> disassembly;
HRESULT r;

comments = "// using 3Dmigoto v" + string(VER_FILE_VERSION_STR) + " on " + LogTime() + "//\n";
Expand Down

0 comments on commit 19e636a

Please sign in to comment.