Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Kristian Arntzen <post@arntzen-software.no>2020-01-09 13:18:14 +0300
committerHans-Kristian Arntzen <post@arntzen-software.no>2020-01-09 14:41:06 +0300
commitcc153f8d7f797988164e66df3055abe9be200c5f (patch)
tree4a40fb22fd92cec1de03fb13fb6ad62d8d1f4f57 /tests-other
parent34ba8ea4f2947fdc56a76b17f352cb692499bcd7 (diff)
HLSL: Add a resource remapping API similar to MSL.
Allows more flexibility of how resources are assigned without having to remap decorations.
Diffstat (limited to 'tests-other')
-rw-r--r--tests-other/hlsl_resource_binding.spvbin0 -> 796 bytes
-rw-r--r--tests-other/hlsl_resource_bindings.cpp89
2 files changed, 89 insertions, 0 deletions
diff --git a/tests-other/hlsl_resource_binding.spv b/tests-other/hlsl_resource_binding.spv
new file mode 100644
index 00000000..c48dc49e
--- /dev/null
+++ b/tests-other/hlsl_resource_binding.spv
Binary files differ
diff --git a/tests-other/hlsl_resource_bindings.cpp b/tests-other/hlsl_resource_bindings.cpp
new file mode 100644
index 00000000..1a938dac
--- /dev/null
+++ b/tests-other/hlsl_resource_bindings.cpp
@@ -0,0 +1,89 @@
+// Testbench for HLSL resource binding APIs.
+// It does not validate output at the moment, but it's useful for ad-hoc testing.
+
+#include <spirv_cross_c.h>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define SPVC_CHECKED_CALL(x) do { \
+ if ((x) != SPVC_SUCCESS) { \
+ fprintf(stderr, "Failed at line %d.\n", __LINE__); \
+ exit(1); \
+ } \
+} while(0)
+
+static std::vector<SpvId> read_file(const char *path)
+{
+ long len;
+ FILE *file = fopen(path, "rb");
+
+ if (!file)
+ return {};
+
+ fseek(file, 0, SEEK_END);
+ len = ftell(file);
+ rewind(file);
+
+ std::vector<SpvId> buffer(len / sizeof(SpvId));
+ if (fread(buffer.data(), 1, len, file) != (size_t)len)
+ {
+ fclose(file);
+ return {};
+ }
+
+ fclose(file);
+ return buffer;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ return EXIT_FAILURE;
+
+ auto buffer = read_file(argv[1]);
+ if (buffer.empty())
+ return EXIT_FAILURE;
+
+ spvc_context ctx;
+ spvc_parsed_ir parsed_ir;
+ spvc_compiler compiler;
+
+ SPVC_CHECKED_CALL(spvc_context_create(&ctx));
+ SPVC_CHECKED_CALL(spvc_context_parse_spirv(ctx, buffer.data(), buffer.size(), &parsed_ir));
+ SPVC_CHECKED_CALL(spvc_context_create_compiler(ctx, SPVC_BACKEND_HLSL, parsed_ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler));
+
+ spvc_compiler_options opts;
+ SPVC_CHECKED_CALL(spvc_compiler_create_compiler_options(compiler, &opts));
+ SPVC_CHECKED_CALL(spvc_compiler_options_set_uint(opts, SPVC_COMPILER_OPTION_HLSL_SHADER_MODEL, 51));
+ SPVC_CHECKED_CALL(spvc_compiler_install_compiler_options(compiler, opts));
+
+ spvc_hlsl_resource_binding binding;
+ spvc_hlsl_resource_binding_init(&binding);
+ binding.stage = SpvExecutionModelFragment;
+ binding.desc_set = 1;
+ binding.binding = 4;
+ binding.srv.register_space = 2;
+ binding.srv.register_binding = 3;
+ binding.sampler.register_space = 4;
+ binding.sampler.register_binding = 5;
+ SPVC_CHECKED_CALL(spvc_compiler_hlsl_add_resource_binding(compiler, &binding));
+
+ binding.desc_set = SPVC_HLSL_PUSH_CONSTANT_DESC_SET;
+ binding.binding = SPVC_HLSL_PUSH_CONSTANT_BINDING;
+ binding.cbv.register_space = 0;
+ binding.cbv.register_binding = 4;
+ SPVC_CHECKED_CALL(spvc_compiler_hlsl_add_resource_binding(compiler, &binding));
+
+ const char *str;
+ SPVC_CHECKED_CALL(spvc_compiler_compile(compiler, &str));
+
+ fprintf(stderr, "Output:\n%s\n", str);
+
+ if (!spvc_compiler_hlsl_is_resource_used(compiler, SpvExecutionModelFragment, 1, 4))
+ return EXIT_FAILURE;
+
+ if (!spvc_compiler_hlsl_is_resource_used(compiler, SpvExecutionModelFragment, SPVC_HLSL_PUSH_CONSTANT_DESC_SET, SPVC_HLSL_PUSH_CONSTANT_BINDING))
+ return EXIT_FAILURE;
+}
+