From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- .../tests/dxbc/test_hlsl_compiler.cpp | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/libs/dxvk-native-1.9.2a/tests/dxbc/test_hlsl_compiler.cpp (limited to 'src/libs/dxvk-native-1.9.2a/tests/dxbc/test_hlsl_compiler.cpp') diff --git a/src/libs/dxvk-native-1.9.2a/tests/dxbc/test_hlsl_compiler.cpp b/src/libs/dxvk-native-1.9.2a/tests/dxbc/test_hlsl_compiler.cpp new file mode 100644 index 00000000..b1670878 --- /dev/null +++ b/src/libs/dxvk-native-1.9.2a/tests/dxbc/test_hlsl_compiler.cpp @@ -0,0 +1,109 @@ +#include +#include +#include + +#include + +#include +#include +#include + +#include "../test_utils.h" + +using namespace dxvk; + +int WINAPI WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) { + int argc = 0; + LPWSTR* argv = CommandLineToArgvW( + GetCommandLineW(), &argc); + + if (argc < 5) { + std::cerr << "Usage: hlsl-compiler target entrypoint input.hlsl output.dxbc [--strip] [--text]" << std::endl; + return 1; + } + + bool strip = false; + bool text = false; + + for (int i = 5; i < argc; i++) { + strip |= str::fromws(argv[i]) == "--strip"; + text |= str::fromws(argv[i]) == "--text"; + } + + const LPWSTR target = argv[1]; + const LPWSTR entryPoint = argv[2]; + const LPWSTR inputFile = argv[3]; + const LPWSTR outputFile = argv[4]; + + std::ifstream ifile(str::fromws(inputFile), std::ios::binary); + ifile.ignore(std::numeric_limits::max()); + std::streamsize length = ifile.gcount(); + ifile.clear(); + + ifile.seekg(0, std::ios_base::beg); + std::vector hlslCode(length); + ifile.read(hlslCode.data(), length); + + Com binary; + Com errors; + + HRESULT hr = D3DCompile( + hlslCode.data(), + hlslCode.size(), + "Shader", nullptr, nullptr, + str::fromws(entryPoint).c_str(), + str::fromws(target).c_str(), + D3DCOMPILE_OPTIMIZATION_LEVEL3 | + D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES, + 0, &binary, &errors); + + if (FAILED(hr)) { + if (errors != nullptr) + std::cerr << reinterpret_cast(errors->GetBufferPointer()) << std::endl; + return 1; + } + + if (strip) { + Com strippedBlob; + + hr = D3DStripShader(binary->GetBufferPointer(), binary->GetBufferSize(), + D3DCOMPILER_STRIP_REFLECTION_DATA | D3DCOMPILER_STRIP_DEBUG_INFO, + &strippedBlob); + + if (FAILED(hr)) { + std::cerr << "Failed to strip shader" << std::endl; + return 1; + } + + binary = strippedBlob; + } + + std::ofstream file; + + if (str::fromws(outputFile) != "-") + file = std::ofstream(str::fromws(outputFile), std::ios::binary | std::ios::trunc); + + std::ostream& outputStream = file.is_open() ? file : std::cout; + + if (text) { + auto data = reinterpret_cast(binary->GetBufferPointer()); + auto size = binary->GetBufferSize() / sizeof(uint32_t); + + outputStream << std::hex; + + for (uint32_t i = 0; i < size; i++) { + if (i && !(i & 0x7)) + outputStream << std::endl; + outputStream << "0x" << std::setfill('0') << std::setw(8) << data[i] << ", "; + } + + outputStream << std::endl; + } else { + outputStream.write(reinterpret_cast(binary->GetBufferPointer()), binary->GetBufferSize()); + } + + return 0; +} -- cgit v1.2.3