contrib: fxc2: support -O binary output mode

This commit is contained in:
Steve Lhomme 2024-04-19 11:23:35 +02:00
parent 4c31622635
commit d04d70fb20
5 changed files with 143 additions and 6 deletions

View File

@ -0,0 +1,79 @@
From f6c828b27699c7ee8bdd85b79ac519a13e8b3a57 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 19 Apr 2024 11:22:12 +0200
Subject: [PATCH 1/3] handle -O option to write to a binary file rather than a
header
---
fxc2.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/fxc2.cpp b/fxc2.cpp
index 205fa16..a4037af 100755
--- a/fxc2.cpp
+++ b/fxc2.cpp
@@ -79,6 +79,7 @@ int main(int argc, char* argv[])
D3D_SHADER_MACRO* defines = new D3D_SHADER_MACRO[numDefines];
defines[numDefines-1].Name = NULL;
defines[numDefines-1].Definition = NULL;
+ bool outputToHeader = true;
int i, c;
static struct option longOptions[] =
@@ -92,7 +93,7 @@ int main(int argc, char* argv[])
D3D_SHADER_MACRO* newDefines;
int optionIndex = 0;
- c = getopt_long_only (argc, argv, "T:E:D:V:F:",
+ c = getopt_long_only (argc, argv, "T:E:D:V:F:O:",
longOptions, &optionIndex);
/* Detect the end of the options. */
@@ -156,6 +157,7 @@ int main(int argc, char* argv[])
{
case 'h':
outputFile = strdup(&optarg[1]);
+ outputToHeader = true;
if(verbose) {
printf ("option -Fh (Output File) with arg %s\n", &optarg[1]);
}
@@ -166,6 +168,14 @@ int main(int argc, char* argv[])
}
break;
+ case 'O':
+ outputFile = strdup(&optarg[0]);
+ outputToHeader = false;
+ if(verbose) {
+ printf ("option -O (Output File) with arg %s\n", &optarg[0]);
+ }
+ break;
+
case '?':
default:
print_usage_arg();
@@ -315,8 +325,12 @@ int main(int argc, char* argv[])
int len = output->GetBufferSize();
FILE* f;
- errno_t err = fopen_s(&f, outputFile, "w");
+ const auto openMode = outputToHeader ? "wb" : "w";
+ errno_t err = fopen_s(&f, outputFile, openMode);
+ if (!outputToHeader) {
+ fwrite(outString, 1, len, f);
+ } else {
fprintf(f, "const BYTE %s[] =\n{\n", variableName);
for (i = 0; i < len; i++) {
fprintf(f, "%4i", outString[i]);
@@ -327,6 +341,7 @@ int main(int argc, char* argv[])
}
fprintf(f, "\n};");
+ }
fclose(f);
if(verbose) {
--
2.37.3.windows.1

View File

@ -0,0 +1,26 @@
From 39629169b7c8c2cc7c2fe7fdd057132352482fec Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 19 Apr 2024 11:43:08 +0200
Subject: [PATCH 2/3] fix redefinition warning
---
fxc2.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fxc2.cpp b/fxc2.cpp
index 2b3f587..17b0ccb 100755
--- a/fxc2.cpp
+++ b/fxc2.cpp
@@ -11,7 +11,9 @@
#include <wchar.h>
+#ifndef D3D_COMPILE_STANDARD_FILE_INCLUDE
#define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1)
+#endif
typedef HRESULT(__stdcall *pCompileFromFileg)(LPCWSTR,
const D3D_SHADER_MACRO[],
ID3DInclude*,
--
2.37.3.windows.1

View File

@ -0,0 +1,29 @@
From b21a639c2c79cf7543d57ef14fe79911ed6be7ae Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 19 Apr 2024 15:09:41 +0200
Subject: [PATCH 3/3] improve error messages after compilation
---
fxc2.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fxc2.cpp b/fxc2.cpp
index 17b0ccb..dbc5728 100755
--- a/fxc2.cpp
+++ b/fxc2.cpp
@@ -306,10 +306,10 @@ int main(int argc, char* argv[])
if (FAILED(hr)) {
if (errors) {
char* error = (char*)errors->GetBufferPointer();
- printf("Got an error (%i) while compiling:\n%s\n", hr, error);
+ printf("Got an error (0x%lX) while compiling: '%s'\n%s\n", hr, inputFile, error);
errors->Release();
} else {
- printf("Got an error (%i) while compiling, but no error message from the function.\n", hr);
+ printf("Got an error (0x%lX) while compiling '%s', but no error message from the function.\n", hr, inputFile);
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
--
2.37.3.windows.1

View File

@ -1,4 +1,4 @@
From 24359310304ceee121489fd785fb31484cf36c0d Mon Sep 17 00:00:00 2001
From cff056e74403c99b8d672cce5b289615a4d7338f Mon Sep 17 00:00:00 2001
From: Pierre Lamot <pierre.lamot@yahoo.fr>
Date: Mon, 14 Jan 2019 15:37:02 +0100
Subject: [PATCH 4/4] Revert "Fix: narrowing conversion from 'int' to 'BYTE'"
@ -9,19 +9,19 @@ This reverts commit 82527b81104e5e21390d3ddcd328700c67ce73d4.
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/fxc2.cpp b/fxc2.cpp
index 01a8d07..ac17328 100755
index 5b8c86c..205fa16 100755
--- a/fxc2.cpp
+++ b/fxc2.cpp
@@ -310,7 +310,7 @@ int main(int argc, const char* argv[])
@@ -317,7 +317,7 @@ int main(int argc, char* argv[])
FILE* f;
errno_t err = fopen_s(&f, outputFile, "w");
- fprintf(f, "const signed char %s[] =\n{\n", variableName);
+ fprintf(f, "const BYTE %s[] =\n{\n", variableName);
for (int i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
fprintf(f, "%4i", outString[i]);
if (i != len - 1)
@@ -319,7 +319,7 @@ int main(int argc, const char* argv[])
@@ -326,7 +326,7 @@ int main(int argc, char* argv[])
fprintf(f, "\n");
}
@ -31,5 +31,5 @@ index 01a8d07..ac17328 100755
if(verbose) {
--
2.19.1
2.37.3.windows.1

View File

@ -18,6 +18,9 @@ fxc2: fxc2-$(FXC2_VERSION).tar.xz .sum-fxc2
$(APPLY) $(SRC)/fxc2/0001-make-Vn-argument-as-optional-and-provide-default-var.patch
$(APPLY) $(SRC)/fxc2/0002-accept-windows-style-flags-and-splitted-argument-val.patch
$(APPLY) $(SRC)/fxc2/0004-Revert-Fix-narrowing-conversion-from-int-to-BYTE.patch
$(APPLY) $(SRC)/fxc2/0001-handle-O-option-to-write-to-a-binary-file-rather-tha.patch
$(APPLY) $(SRC)/fxc2/0002-fix-redefinition-warning.patch
$(APPLY) $(SRC)/fxc2/0003-improve-error-messages-after-compilation.patch
$(MOVE)
ifeq ($(shell uname -m),aarch64)