diff options
Diffstat (limited to '3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp')
-rw-r--r-- | 3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp b/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp index 8f861047ded..08067ccaff1 100644 --- a/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp +++ b/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp @@ -13,6 +13,7 @@ # define __out #endif // defined(__MINGW32__) +#define COM_NO_WINDOWS_H #include <d3dcompiler.h> #include <d3d11shader.h> #include <bx/os.h> @@ -21,7 +22,7 @@ # define D3D_SVF_USED 2 #endif // D3D_SVF_USED -namespace bgfx +namespace bgfx { namespace hlsl { typedef HRESULT(WINAPI* PFN_D3D_COMPILE)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData , _In_ SIZE_T SrcDataSize @@ -67,7 +68,7 @@ namespace bgfx }; static const D3DCompiler s_d3dcompiler[] = - { // BK - the only different in interface is GetRequiresFlags at the end + { // BK - the only different method in interface is GetRequiresFlags at the end // of IID_ID3D11ShaderReflection47 (which is not used anyway). { "D3DCompiler_47.dll", { 0x8d536ca1, 0x0cca, 0x4956, { 0xa8, 0x37, 0x78, 0x69, 0x63, 0x75, 0x55, 0x84 } } }, { "D3DCompiler_46.dll", { 0x0a233719, 0x3960, 0x4578, { 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1 } } }, @@ -104,7 +105,13 @@ namespace bgfx continue; } - BX_TRACE("Loaded %s compiler.", compiler->fileName); + if (g_verbose) + { + char filePath[MAX_PATH]; + GetModuleFileNameA( (HMODULE)s_d3dcompilerdll, filePath, sizeof(filePath) ); + BX_TRACE("Loaded %s compiler (%s).", compiler->fileName, filePath); + } + return compiler; } @@ -536,7 +543,7 @@ namespace bgfx return true; } - bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass) + static bool compile(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer, bool _firstPass) { const char* profile = _cmdLine.findOption('p', "profile"); if (NULL == profile) @@ -611,19 +618,24 @@ namespace bgfx { const char* log = (char*)errorMsg->GetBufferPointer(); - int32_t line = 0; + int32_t line = 0; int32_t column = 0; - int32_t start = 0; - int32_t end = INT32_MAX; + int32_t start = 0; + int32_t end = INT32_MAX; + + bool found = false + || 2 == sscanf(log, "(%u,%u):", &line, &column) + || 2 == sscanf(log, " :%u:%u: ", &line, &column) + ; - if (2 == sscanf(log, "(%u,%u):", &line, &column) + if (found && 0 != line) { start = bx::uint32_imax(1, line - 10); - end = start + 20; + end = start + 20; } - printCode(_code.c_str(), line, start, end); + printCode(_code.c_str(), line, start, end, column); fprintf(stderr, "Error: D3DCompile failed 0x%08x %s\n", (uint32_t)hr, log); errorMsg->Release(); return false; @@ -634,7 +646,7 @@ namespace bgfx uint16_t attrs[bgfx::Attrib::Count]; uint16_t size = 0; - if (_d3d == 9) + if (_version == 9) { if (!getReflectionDataD3D9(code, uniforms) ) { @@ -647,7 +659,7 @@ namespace bgfx UniformNameList unusedUniforms; if (!getReflectionDataD3D11(code, profile[0] == 'v', uniforms, numAttrs, attrs, size, unusedUniforms) ) { - fprintf(stderr, "Unable to get D3D11 reflection data.\n"); + fprintf(stderr, "Error: Unable to get D3D11 reflection data.\n"); goto error; } @@ -687,7 +699,7 @@ namespace bgfx } // recompile with the unused uniforms converted to statics - return compileHLSLShader(_cmdLine, _d3d, output.c_str(), _writer, false); + return compile(_cmdLine, _version, output.c_str(), _writer, false); } } @@ -742,7 +754,7 @@ namespace bgfx bx::write(_writer, nul); } - if (_d3d > 9) + if (_version > 9) { bx::write(_writer, numAttrs); bx::write(_writer, attrs, numAttrs*sizeof(uint16_t) ); @@ -783,16 +795,22 @@ namespace bgfx return result; } +} // namespace hlsl + + bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer) + { + return hlsl::compile(_cmdLine, _version, _code, _writer, true); + } + } // namespace bgfx #else namespace bgfx { - - bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass) + bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer) { - BX_UNUSED(_cmdLine, _d3d, _code, _writer, _firstPass); + BX_UNUSED(_cmdLine, _version, _code, _writer); fprintf(stderr, "HLSL compiler is not supported on this platform.\n"); return false; } |