Expand constexpr sampler sanity check.

This commit is contained in:
Hans-Kristian Arntzen 2019-06-10 16:00:20 +02:00
parent 30bb197a5d
commit 7fd379774e
2 changed files with 49 additions and 1 deletions

View File

@ -65,6 +65,29 @@ int main(int argc, char **argv)
SPVC_CHECKED_CALL(spvc_context_parse_spirv(ctx, buffer.data(), buffer.size(), &parsed_ir));
SPVC_CHECKED_CALL(spvc_context_create_compiler(ctx, SPVC_BACKEND_MSL, parsed_ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler));
spvc_msl_resource_binding binding;
spvc_msl_resource_binding_init(&binding);
binding.desc_set = 1;
binding.binding = 2;
binding.stage = SpvExecutionModelFragment;
binding.msl_texture = 0;
binding.msl_sampler = 0;
SPVC_CHECKED_CALL(spvc_compiler_msl_add_resource_binding(compiler, &binding));
binding.binding = 3;
binding.msl_texture = 1;
binding.msl_sampler = 1000; // Will be remapped anyways, sanity check.
SPVC_CHECKED_CALL(spvc_compiler_msl_add_resource_binding(compiler, &binding));
binding.desc_set = 2;
binding.binding = 2;
binding.msl_texture = 2;
SPVC_CHECKED_CALL(spvc_compiler_msl_add_resource_binding(compiler, &binding));
binding.binding = 3;
binding.msl_texture = 3;
SPVC_CHECKED_CALL(spvc_compiler_msl_add_resource_binding(compiler, &binding));
spvc_msl_constexpr_sampler samp;
spvc_msl_constexpr_sampler_init(&samp);
samp.s_address = SPVC_MSL_SAMPLER_ADDRESS_REPEAT;
@ -75,11 +98,36 @@ int main(int argc, char **argv)
samp.s_address = SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
samp.t_address = SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
samp.r_address = SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
SPVC_CHECKED_CALL(spvc_compiler_msl_remap_constexpr_sampler_by_binding(compiler, 2, 2, &samp));
SPVC_CHECKED_CALL(spvc_compiler_msl_remap_constexpr_sampler_by_binding(compiler, 2, 4, &samp));
samp.compare_enable = SPVC_TRUE;
samp.compare_func = SPVC_MSL_SAMPLER_COMPARE_FUNC_LESS;
samp.s_address = SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
samp.t_address = SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
samp.r_address = SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
SPVC_CHECKED_CALL(spvc_compiler_msl_remap_constexpr_sampler_by_binding(compiler, 2, 5, &samp));
const char *str;
SPVC_CHECKED_CALL(spvc_compiler_compile(compiler, &str));
// Should not be marked as used.
if (spvc_compiler_msl_is_resource_used(compiler, SpvExecutionModelFragment, 2, 4))
return EXIT_FAILURE;
// Should not be marked as used.
if (spvc_compiler_msl_is_resource_used(compiler, SpvExecutionModelFragment, 2, 5))
return EXIT_FAILURE;
// Should be marked, as a sanity check.
if (!spvc_compiler_msl_is_resource_used(compiler, SpvExecutionModelFragment, 1, 2))
return EXIT_FAILURE;
if (!spvc_compiler_msl_is_resource_used(compiler, SpvExecutionModelFragment, 1, 3))
return EXIT_FAILURE;
if (!spvc_compiler_msl_is_resource_used(compiler, SpvExecutionModelFragment, 2, 2))
return EXIT_FAILURE;
if (!spvc_compiler_msl_is_resource_used(compiler, SpvExecutionModelFragment, 2, 3))
return EXIT_FAILURE;
fprintf(stderr, "Output:\n%s\n", str);
}

Binary file not shown.