Skip to content

Commit

Permalink
Add option to emit Invariant position.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Oct 12, 2021
1 parent 447723b commit e74757f
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 3 deletions.
7 changes: 7 additions & 0 deletions dxil_converter.cpp
Expand Up @@ -3111,6 +3111,8 @@ void Converter::Impl::emit_builtin_decoration(spv::Id id, DXIL::Semantic semanti
{
builder.addDecoration(id, spv::DecorationBuiltIn, spv::BuiltInPosition);
spirv_module.register_builtin_shader_output(id, spv::BuiltInPosition);
if (options.invariant_position)
builder.addDecoration(id, spv::DecorationInvariant);
}
break;

Expand Down Expand Up @@ -4989,6 +4991,10 @@ void Converter::Impl::set_option(const OptionBase &cap)
static_cast<const OptionShaderRayTracingPrimitiveCulling &>(cap).supported;
break;

case Option::InvariantPosition:
options.invariant_position = static_cast<const OptionInvariantPosition &>(cap).enabled;
break;

default:
break;
}
Expand Down Expand Up @@ -5037,6 +5043,7 @@ bool Converter::recognizes_option(Option cap)
case Option::MinPrecisionNative16Bit:
case Option::ShaderI8Dot:
case Option::ShaderRayTracingPrimitiveCulling:
case Option::InvariantPosition:
return true;

default:
Expand Down
13 changes: 12 additions & 1 deletion dxil_converter.hpp
Expand Up @@ -208,7 +208,8 @@ enum class Option : uint32_t
DescriptorQA = 15,
MinPrecisionNative16Bit = 16,
ShaderI8Dot = 17,
ShaderRayTracingPrimitiveCulling = 18
ShaderRayTracingPrimitiveCulling = 18,
InvariantPosition = 19
};

enum class ResourceClass : uint32_t
Expand Down Expand Up @@ -413,6 +414,16 @@ struct OptionShaderRayTracingPrimitiveCulling : OptionBase
bool supported = false;
};

struct OptionInvariantPosition : OptionBase
{
OptionInvariantPosition()
: OptionBase(Option::InvariantPosition)
{
}

bool enabled = false;
};

struct DescriptorTableEntry
{
ResourceClass type;
Expand Down
11 changes: 10 additions & 1 deletion dxil_spirv.cpp
Expand Up @@ -145,7 +145,8 @@ static void print_help()
"\t[--root-descriptor <cbv/uav/srv> <space> <register>]\n"
"\t[--descriptor-qa <set> <binding base> <shader hash>]\n"
"\t[--min-precision-native-16bit]\n"
"\t[--raw-llvm]\n");
"\t[--raw-llvm]\n"
"\t[--invariant-position]\n");
}

struct Arguments
Expand All @@ -172,6 +173,7 @@ struct Arguments
bool bindless_typed_buffer_offsets = false;
bool min_precision_native_16bit = false;
bool raw_llvm = false;
bool invariant_position = false;

unsigned ssbo_alignment = 1;

Expand Down Expand Up @@ -653,6 +655,7 @@ int main(int argc, char **argv)
});
cbs.add("--min-precision-native-16bit", [&](CLIParser &) { args.min_precision_native_16bit = true; });
cbs.add("--raw-llvm", [&](CLIParser &) { args.raw_llvm = true; });
cbs.add("--invariant-position", [&](CLIParser &) { args.invariant_position = true; });
cbs.error_handler = [] { print_help(); };
cbs.default_handler = [&](const char *arg) { args.input_path = arg; };
CLIParser cli_parser(std::move(cbs), argc - 1, argv + 1);
Expand Down Expand Up @@ -826,6 +829,12 @@ int main(int argc, char **argv)
dxil_spv_converter_add_option(converter, &minprec.base);
}

{
const dxil_spv_option_invariant_position invariant = { { DXIL_SPV_OPTION_INVARIANT_POSITION },
args.invariant_position ? DXIL_SPV_TRUE : DXIL_SPV_FALSE };
dxil_spv_converter_add_option(converter, &invariant.base);
}

dxil_spv_converter_add_option(converter, &args.offset_buffer_layout.base);

unsigned num_entry_points = 1;
Expand Down
9 changes: 9 additions & 0 deletions dxil_spirv_c.cpp
Expand Up @@ -812,6 +812,15 @@ dxil_spv_result dxil_spv_converter_add_option(dxil_spv_converter converter, cons
break;
}

case DXIL_SPV_OPTION_INVARIANT_POSITION:
{
OptionInvariantPosition helper;
helper.enabled = bool(reinterpret_cast<const dxil_spv_option_invariant_position *>(option)->enabled);

converter->options.emplace_back(duplicate(helper));
break;
}

default:
return DXIL_SPV_ERROR_UNSUPPORTED_FEATURE;
}
Expand Down
9 changes: 8 additions & 1 deletion dxil_spirv_c.h
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#endif

#define DXIL_SPV_API_VERSION_MAJOR 2
#define DXIL_SPV_API_VERSION_MINOR 12
#define DXIL_SPV_API_VERSION_MINOR 13
#define DXIL_SPV_API_VERSION_PATCH 0

#define DXIL_SPV_DESCRIPTOR_QA_INTERFACE_VERSION 1
Expand Down Expand Up @@ -279,6 +279,7 @@ typedef enum dxil_spv_option
DXIL_SPV_OPTION_MIN_PRECISION_NATIVE_16BIT = 16,
DXIL_SPV_OPTION_SHADER_I8_DOT = 17,
DXIL_SPV_OPTION_SHADER_RAY_TRACING_PRIMITIVE_CULLING = 18,
DXIL_SPV_OPTION_INVARIANT_POSITION = 19,
DXIL_SPV_OPTION_INT_MAX = 0x7fffffff
} dxil_spv_option;

Expand Down Expand Up @@ -422,6 +423,12 @@ typedef struct dxil_spv_option_shader_ray_tracing_primitive_culling
dxil_spv_bool supported;
} dxil_spv_option_shader_ray_tracing_primitive_culling;

typedef struct dxil_spv_option_invariant_position
{
dxil_spv_option_base base;
dxil_spv_bool enabled;
} dxil_spv_option_invariant_position;

/* Gets the ABI version used to build this library. Used to detect API/ABI mismatches. */
DXIL_SPV_PUBLIC_API void dxil_spv_get_version(unsigned *major, unsigned *minor, unsigned *patch);

Expand Down
1 change: 1 addition & 0 deletions opcodes/converter_impl.hpp
Expand Up @@ -407,6 +407,7 @@ struct Converter::Impl
bool min_precision_prefer_native_16bit = false;
bool shader_i8_dot_enabled = false;
bool ray_tracing_primitive_culling_enabled = false;
bool invariant_position = false;
} options;

struct BindlessInfo
Expand Down
102 changes: 102 additions & 0 deletions reference/shaders/stages/simple.invariant.vert

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions shaders/stages/simple.invariant.vert
@@ -0,0 +1,4 @@
float4 main(float4 a : A, float4 b : B, float4 c : C) : SV_Position
{
return mad(a, b, c);
}
2 changes: 2 additions & 0 deletions test_shaders.py
Expand Up @@ -200,6 +200,8 @@ def cross_compile_dxil(shader, args, paths, is_asm):
hlsl_cmd += ['--descriptor-qa', '10', '10', 'deadbeef']
if '.native-fp16.' in shader:
hlsl_cmd += ['--min-precision-native-16bit']
if '.invariant.' in shader:
hlsl_cmd += ['--invariant-position']

subprocess.check_call(hlsl_cmd)
if is_asm:
Expand Down

0 comments on commit e74757f

Please sign in to comment.