Assign block locations to members in MSL.

This commit is contained in:
Hans-Kristian Arntzen 2017-06-21 09:55:46 +02:00
parent 602ed34e34
commit a1f5453519
5 changed files with 54 additions and 4 deletions

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_in
{
float4 VertexOut_color2 [[user(locn3)]];
float4 VertexOut_color [[user(locn2)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.FragColor = in.VertexOut_color + in.VertexOut_color2;
return out;
}

View File

@ -16,7 +16,8 @@ struct main0_in
struct main0_out
{
float4 VertexOut_color [[user(locn0)]];
float4 VertexOut_color2 [[user(locn3)]];
float4 VertexOut_color [[user(locn2)]];
float4 gl_Position [[position]];
};
@ -25,6 +26,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant Transform& block [[buf
main0_out out = {};
out.gl_Position = block.transform * float4(in.position, 1.0);
out.VertexOut_color = in.color;
out.VertexOut_color2 = in.color + float4(1.0);
return out;
}

View File

@ -0,0 +1,14 @@
#version 450
layout(location = 2) in VertexOut
{
vec4 color;
vec4 color2;
} inputs;
layout(location = 0) out vec4 FragColor;
void main()
{
FragColor = inputs.color + inputs.color2;
}

View File

@ -8,13 +8,15 @@ uniform Transform
layout(location = 0) in vec3 position;
layout(location = 1) in vec4 color;
layout(location = 0) out VertexOut
layout(location = 2) out VertexOut
{
vec4 color;
vec4 color2;
} outputs;
void main()
{
gl_Position = block.transform*vec4(position, 1.0);
gl_Position = block.transform * vec4(position, 1.0);
outputs.color = color;
outputs.color2 = color + vec4(1.0);
}

View File

@ -414,8 +414,9 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
auto &mbr_type = get<SPIRType>(mbr_type_id);
if (is_matrix(mbr_type))
{
exclude_member_from_stage_in(type, mbr_idx);
}
else if (!is_builtin || has_active_builtin(builtin, storage))
{
// Add a reference to the member to the interface struct.
@ -437,6 +438,14 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
set_member_decoration(ib_type_id, ib_mbr_idx, DecorationLocation, locn);
mark_location_as_used_by_shader(locn, storage);
}
else if (has_decoration(p_var->self, DecorationLocation))
{
// The block itself might have a location and in this case, all members of the block
// receive incrementing locations.
uint32_t locn = get_decoration(p_var->self, DecorationLocation) + mbr_idx;
set_member_decoration(ib_type_id, ib_mbr_idx, DecorationLocation, locn);
mark_location_as_used_by_shader(locn, storage);
}
// Mark the member as builtin if needed
if (is_builtin)