Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for issues 96 and 105 #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/glsl/ir_print_glsl_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static inline const char* get_precision_string (glsl_precision p)
static const int tex_sampler_type_count = 7;
// [glsl_sampler_dim]
static const char* tex_sampler_dim_name[tex_sampler_type_count] = {
"1D", "2D", "3D", "Cube", "Rect", "Buf", "External",
"1D", "2D", "3D", "Cube", "Rect", "Buf", "2D",
};
static int tex_sampler_dim_size[tex_sampler_type_count] = {
1, 2, 3, 3, 2, 2, 2,
Expand Down Expand Up @@ -254,6 +254,8 @@ _mesa_print_ir_glsl(exec_list *instructions,
str.asprintf_append ("#extension GL_EXT_shader_framebuffer_fetch : enable\n");
if (state->ARB_shader_bit_encoding_enable)
str.asprintf_append("#extension GL_ARB_shader_bit_encoding : enable\n");
if (state->OES_EGL_image_external_enable)
str.asprintf_append("#extension GL_OES_EGL_image_external : enable\n");
}

// remove unused struct declarations
Expand Down
7 changes: 7 additions & 0 deletions src/glsl/ir_print_metal_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct metal_print_context
, inoutStr(ralloc_strdup(buffer, ""))
, uniformStr(ralloc_strdup(buffer, ""))
, paramsStr(ralloc_strdup(buffer, ""))
, structsStr(ralloc_strdup(buffer, ""))
, writingParams(false)
, matrixCastsDone(false)
, matrixConstructorsDone(false)
Expand All @@ -117,6 +118,7 @@ struct metal_print_context
string_buffer inoutStr;
string_buffer uniformStr;
string_buffer paramsStr;
string_buffer structsStr;
bool writingParams;
bool matrixCastsDone;
bool matrixConstructorsDone;
Expand Down Expand Up @@ -265,6 +267,10 @@ _mesa_print_ir_metal(exec_list *instructions,
strOut = &ctx.inoutStr;
}

else if (ir->ir_type == ir_type_typedecl)
{
strOut = &ctx.structsStr;
}

ir_print_metal_visitor v (ctx, *strOut, &gtracker, mode, state);
v.loopstate = ls;
Expand Down Expand Up @@ -329,6 +335,7 @@ _mesa_print_ir_metal(exec_list *instructions,

ctx.prefixStr.asprintf_append("%s", ctx.inputStr.c_str());
ctx.prefixStr.asprintf_append("%s", ctx.outputStr.c_str());
ctx.prefixStr.asprintf_append("%s", ctx.structsStr.c_str());
ctx.prefixStr.asprintf_append("%s", ctx.uniformStr.c_str());
ctx.prefixStr.asprintf_append("%s", ctx.str.c_str());

Expand Down
16 changes: 16 additions & 0 deletions tests/vertex/metal_struct_uniform-inES3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 300 es

precision mediump float;

struct MyStruct
{
vec4 v1;
vec4 v2;
};

uniform MyStruct s1;

void main()
{
gl_Position = vec4(s1.v1.xyz, 1.0);
}
19 changes: 19 additions & 0 deletions tests/vertex/metal_struct_uniform-outES3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 300 es
precision mediump float;
struct MyStruct {
vec4 v1;
vec4 v2;
};
uniform MyStruct s1;
void main ()
{
highp vec4 tmpvar_1;
tmpvar_1.w = 1.0;
tmpvar_1.xyz = s1.v1.xyz;
gl_Position = tmpvar_1;
}


// stats: 1 alu 0 tex 0 flow
// uniforms: 1 (total size: 0)
// #0: s1 (high other) 0x0 [-1]
29 changes: 29 additions & 0 deletions tests/vertex/metal_struct_uniform-outES3Metal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <metal_stdlib>
using namespace metal;
struct xlatMtlShaderInput {
};
struct xlatMtlShaderOutput {
float4 gl_Position [[position]];
};
struct MyStruct {
float4 v1;
float4 v2;
};
struct xlatMtlShaderUniform {
MyStruct s1;
};
;
vertex xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
{
xlatMtlShaderOutput _mtl_o;
float4 tmpvar_1;
tmpvar_1.w = 1.0;
tmpvar_1.xyz = _mtl_u.s1.v1.xyz;
_mtl_o.gl_Position = tmpvar_1;
return _mtl_o;
}


// stats: 1 alu 0 tex 0 flow
// uniforms: 1 (total size: 0)
// #0: s1 (high other) 0x0 [-1] loc 0