How to create defines with quotes using dxc's -D argument?

133 Views Asked by At

I'm trying to implement material shaders with a common entry file main.hlsl. It needs to include different files with implementation of shading function to handle different material types. I want to achieve this by using a macro to control the include file path. A simple example looks like this:

#define INCLUDE_FILE "include.hlsl"

#include INCLUDE_FILE

It works correctly and now I want one step further: generate the INCLUDE_FILE macro with dxc commandline argument. But simply adding -DINCLUDE_FILE=""include.hlsl"" didn't work.

I've tried the following approaches:

  1. compile with dxc -E Main -T ps_6_0 -DINCLUDE_FILE="\"include.hlsl\"" .\main.hlsl
  2. compile with dxc -E Main -T ps_6_0 -DINCLUDE_FILE='"include.hlsl"' .\main.hlsl

I got the following error with the command above:

// for the first command
.\main.hlsl:5:10: error: expected "FILENAME" or <FILENAME>
#include INCLUDE_FILE
         ^
<built-in>:67:22: note: expanded from here
#define INCLUDE_FILE \include.hlsl\\
                     ^

// for the second command
.\main.hlsl:5:10: error: expected "FILENAME" or <FILENAME>
#include INCLUDE_FILE
         ^
<built-in>:66:22: note: expanded from here
#define INCLUDE_FILE include.hlsl
                     ^

It seems that they are translated to #define INCLUDE_FILE include.hlsl and #define INCLUDE_FILE \include.hlsl\\ respectively.

I want to know how to pass quotes in command line argument, or is there any equivalent way to implement this feature?


My dxc version is: dxcompiler.dll: 1.7 - 1.6.0.3576 (9395376ef)

0

There are 0 best solutions below