Fixup resource remapping in MSL/HLSL.

Seemed rather sketchy, but this must be tested a bit.
This commit is contained in:
Hans-Kristian Arntzen 2019-06-24 14:25:04 +02:00
parent df0570ddd5
commit 135ff5e7a5

View File

@ -450,35 +450,8 @@ bool slang_process(
options.shader_model = version;
vs->set_hlsl_options(options);
ps->set_hlsl_options(options);
#if 0
CompilerGLSL::Options glsl_options;
glsl_options.vertex.flip_vert_y = true;
((CompilerGLSL*)vs)->set_options(glsl_options);
((CompilerGLSL*)ps)->set_options(glsl_options);
#endif
/* not exactly a vertex attribute but this remaps
* float2 FragCoord :TEXCOORD# to float4 FragCoord : SV_POSITION */
std::vector<HLSLVertexAttributeRemap> ps_attrib_remap;
VariableTypeRemapCallback ps_var_remap_cb =
[&](const SPIRType& type, const std::string& var_name, std::string& name_of_type) {
if (var_name == "FragCoord")
name_of_type = "float4";
};
for (Resource& resource : ps_resources.stage_inputs)
{
if (ps->get_name(resource.id) == "FragCoord")
{
uint32_t location = ps->get_decoration(resource.id, spv::DecorationLocation);
ps_attrib_remap.push_back({ location, "SV_Position" });
ps->set_variable_type_remap_callback(ps_var_remap_cb);
}
}
vs_code = vs->compile();
ps_code = ps->compile(ps_attrib_remap);
ps_code = ps->compile();
}
else
#endif
@ -491,13 +464,46 @@ bool slang_process(
vs->set_msl_options(options);
ps->set_msl_options(options);
std::vector<MSLVertexAttr> vs_attrib_remap;
std::vector<MSLResourceBinding> vs_res;
const auto remap_push_constant = [](CompilerMSL *comp,
const ShaderResources &resources) {
for (const Resource& resource : resources.push_constant_buffers)
{
// Explicit 1:1 mapping for bindings.
MSLResourceBinding binding = {};
binding.stage = comp->get_execution_model();
binding.desc_set = kPushConstDescSet;
binding.binding = kPushConstBinding;
// Use earlier decoration override.
binding.msl_buffer = comp->get_decoration(resource.id, spv::DecorationBinding);
comp->add_msl_resource_binding(binding);
}
};
for (Resource& resource : vs_resources.stage_inputs)
{
std::string name = vs->get_name(resource.id);
}
const auto remap_generic_resource = [](CompilerMSL *comp,
const SmallVector<Resource> &resources) {
for (const Resource& resource : resources)
{
// Explicit 1:1 mapping for bindings.
MSLResourceBinding binding = {};
binding.stage = comp->get_execution_model();
binding.desc_set = comp->get_decoration(resource.id, spv::DecorationDescriptorSet);
// Use existing decoration override.
uint32_t msl_binding = comp->get_decoration(resource.id, spv::DecorationBinding);
binding.binding = msl_binding;
binding.msl_buffer = msl_binding;
binding.msl_texture = msl_binding;
binding.msl_sampler = msl_binding;
comp->add_msl_resource_binding(binding);
}
};
remap_push_constant(vs, vs_resources);
remap_push_constant(ps, ps_resources);
remap_generic_resource(vs, vs_resources.uniform_buffers);
remap_generic_resource(ps, ps_resources.uniform_buffers);
remap_generic_resource(vs, vs_resources.sampled_images);
remap_generic_resource(ps, ps_resources.sampled_images);
vs_code = vs->compile();
ps_code = ps->compile();