From patchwork Thu Jul 21 12:36:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 2988 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1ABB223F53 for ; Thu, 21 Jul 2011 12:43:49 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id DE22BA18398 for ; Thu, 21 Jul 2011 12:43:48 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so845420qyk.11 for ; Thu, 21 Jul 2011 05:43:48 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr175101qcc.148.1311252228677; Thu, 21 Jul 2011 05:43:48 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs139560qcb; Thu, 21 Jul 2011 05:43:48 -0700 (PDT) Received: by 10.216.137.4 with SMTP id x4mr757153wei.53.1311251798336; Thu, 21 Jul 2011 05:36:38 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id f58si672961wed.38.2011.07.21.05.36.37; Thu, 21 Jul 2011 05:36:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QjsUX-0000DP-Kj for ; Thu, 21 Jul 2011 12:36:37 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 9BD0E2E802E for ; Thu, 21 Jul 2011 12:36:37 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 103 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 103: Simplified shader construction in SceneConditionals. Message-Id: <20110721123637.17019.13749.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:37 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13475"; Instance="initZopeless config overlay" X-Launchpad-Hash: 56e2401cfe222ddfea9ffeed2c279f8903947bd1 ------------------------------------------------------------ revno: 103 committer: Alexandros Frantzis timestamp: Thu 2011-07-07 16:59:05 +0300 message: Simplified shader construction in SceneConditionals. removed: data/shaders/conditionals-epilogue.frag data/shaders/conditionals-epilogue.vert data/shaders/conditionals-prologue.frag data/shaders/conditionals-prologue.vert data/shaders/conditionals-step-conditional.frag data/shaders/conditionals-step-conditional.vert data/shaders/conditionals-step-simple.frag data/shaders/conditionals-step-simple.vert added: data/shaders/conditionals-step-conditional.all data/shaders/conditionals-step-simple.all data/shaders/conditionals.frag data/shaders/conditionals.vert modified: src/scene-conditionals.cpp --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === removed file 'data/shaders/conditionals-epilogue.frag' --- data/shaders/conditionals-epilogue.frag 2011-07-04 14:31:07 +0000 +++ data/shaders/conditionals-epilogue.frag 1970-01-01 00:00:00 +0000 @@ -1,3 +0,0 @@ - gl_FragColor = vec4(n, n, n, 1.0); -} - === removed file 'data/shaders/conditionals-epilogue.vert' --- data/shaders/conditionals-epilogue.vert 2011-07-05 09:06:52 +0000 +++ data/shaders/conditionals-epilogue.vert 1970-01-01 00:00:00 +0000 @@ -1,8 +0,0 @@ - vec4 pos = vec4(position.x, - position.y + 0.1 * d * fract(position.x), - position.z, 1.0); - - // Transform the position to clip coordinates - gl_Position = ModelViewProjectionMatrix * pos; -} - === removed file 'data/shaders/conditionals-prologue.frag' --- data/shaders/conditionals-prologue.frag 2011-07-05 12:23:55 +0000 +++ data/shaders/conditionals-prologue.frag 1970-01-01 00:00:00 +0000 @@ -1,9 +0,0 @@ -#ifdef GL_ES -precision mediump float; -#endif - -varying vec4 dummy; - -void main(void) -{ - float n = fract(gl_FragCoord.x * gl_FragCoord.y * 0.0001); === removed file 'data/shaders/conditionals-prologue.vert' --- data/shaders/conditionals-prologue.vert 2011-07-05 09:06:52 +0000 +++ data/shaders/conditionals-prologue.vert 1970-01-01 00:00:00 +0000 @@ -1,14 +0,0 @@ -attribute vec3 position; - -uniform mat4 ModelViewProjectionMatrix; - -// Removing this varying causes an inexplicable performance regression -// with r600g... Keeping it for now. -varying vec4 dummy; - -void main(void) -{ - dummy = vec4(1.0); - - float d = fract(position.x); - === added file 'data/shaders/conditionals-step-conditional.all' --- data/shaders/conditionals-step-conditional.all 1970-01-01 00:00:00 +0000 +++ data/shaders/conditionals-step-conditional.all 2011-07-07 13:59:05 +0000 @@ -0,0 +1,4 @@ + if (d >= 0.5) + d = fract(2.0 * d); + else + d = fract(3.0 * d); === removed file 'data/shaders/conditionals-step-conditional.frag' --- data/shaders/conditionals-step-conditional.frag 2011-07-04 14:31:07 +0000 +++ data/shaders/conditionals-step-conditional.frag 1970-01-01 00:00:00 +0000 @@ -1,4 +0,0 @@ -if (n >= 0.5) - n = fract(2.0 * n); -else - n = fract(3.0 * n); === removed file 'data/shaders/conditionals-step-conditional.vert' --- data/shaders/conditionals-step-conditional.vert 2011-07-05 09:06:52 +0000 +++ data/shaders/conditionals-step-conditional.vert 1970-01-01 00:00:00 +0000 @@ -1,5 +0,0 @@ - if (d >= 0.5) - d = fract(2.0 * d); - else - d = fract(3.0 * d); - === added file 'data/shaders/conditionals-step-simple.all' --- data/shaders/conditionals-step-simple.all 1970-01-01 00:00:00 +0000 +++ data/shaders/conditionals-step-simple.all 2011-07-07 13:59:05 +0000 @@ -0,0 +1,1 @@ + d = fract(3.0 * d); === removed file 'data/shaders/conditionals-step-simple.frag' --- data/shaders/conditionals-step-simple.frag 2011-07-04 14:31:07 +0000 +++ data/shaders/conditionals-step-simple.frag 1970-01-01 00:00:00 +0000 @@ -1,1 +0,0 @@ -n = fract(3.0 * n); === removed file 'data/shaders/conditionals-step-simple.vert' --- data/shaders/conditionals-step-simple.vert 2011-07-05 09:06:52 +0000 +++ data/shaders/conditionals-step-simple.vert 1970-01-01 00:00:00 +0000 @@ -1,1 +0,0 @@ - d = fract(3.0 * d); === added file 'data/shaders/conditionals.frag' --- data/shaders/conditionals.frag 1970-01-01 00:00:00 +0000 +++ data/shaders/conditionals.frag 2011-07-07 13:59:05 +0000 @@ -0,0 +1,15 @@ +#ifdef GL_ES +precision mediump float; +#endif + +varying vec4 dummy; + +void main(void) +{ + float d = fract(gl_FragCoord.x * gl_FragCoord.y * 0.0001); + +$MAIN$ + + gl_FragColor = vec4(d, d, d, 1.0); +} + === added file 'data/shaders/conditionals.vert' --- data/shaders/conditionals.vert 1970-01-01 00:00:00 +0000 +++ data/shaders/conditionals.vert 2011-07-07 13:59:05 +0000 @@ -0,0 +1,25 @@ +attribute vec3 position; + +uniform mat4 ModelViewProjectionMatrix; + +// Removing this varying causes an inexplicable performance regression +// with r600g... Keeping it for now. +varying vec4 dummy; + +void main(void) +{ + dummy = vec4(1.0); + + float d = fract(position.x); + +$MAIN$ + + vec4 pos = vec4(position.x, + position.y + 0.1 * d * fract(position.x), + position.z, 1.0); + + // Transform the position to clip coordinates + gl_Position = ModelViewProjectionMatrix * pos; +} + + === modified file 'src/scene-conditionals.cpp' --- src/scene-conditionals.cpp 2011-07-07 13:45:19 +0000 +++ src/scene-conditionals.cpp 2011-07-07 13:59:05 +0000 @@ -28,17 +28,12 @@ #include #include -static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/conditionals-"); - -static const std::string vtx_file_prologue(shader_file_base + "prologue.vert"); -static const std::string vtx_file_step_conditional(shader_file_base + "step-conditional.vert"); -static const std::string vtx_file_step_simple(shader_file_base + "step-simple.vert"); -static const std::string vtx_file_epilogue(shader_file_base + "epilogue.vert"); - -static const std::string frg_file_prologue(shader_file_base + "prologue.frag"); -static const std::string frg_file_step_conditional(shader_file_base + "step-conditional.frag"); -static const std::string frg_file_step_simple(shader_file_base + "step-simple.frag"); -static const std::string frg_file_epilogue(shader_file_base + "epilogue.frag"); +static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/conditionals"); + +static const std::string vtx_file(shader_file_base + ".vert"); +static const std::string frg_file(shader_file_base + ".frag"); +static const std::string step_conditional_file(shader_file_base + "-step-conditional.all"); +static const std::string step_simple_file(shader_file_base + "-step-simple.all"); SceneConditionals::SceneConditionals(Canvas &pCanvas) : SceneGrid(pCanvas, "conditionals") @@ -57,58 +52,69 @@ { } +static std::string & +replace_string(std::string &str, const std::string &remove, const std::string &insert) +{ + std::string::size_type pos = 0; + + while ((pos = str.find(remove, pos)) != std::string::npos) { + str.replace(pos, remove.size(), insert); + pos++; + } + + return str; +} + static std::string get_vertex_shader_source(int steps, bool conditionals) { - std::string vtx_prologue, vtx_step_conditional, vtx_step_simple, vtx_epilogue; + std::string vtx_string, step_conditional_string, step_simple_string; - if (!gotSource(vtx_file_prologue, vtx_prologue) || - !gotSource(vtx_file_step_conditional, vtx_step_conditional) || - !gotSource(vtx_file_step_simple, vtx_step_simple) || - !gotSource(vtx_file_epilogue, vtx_epilogue)) + if (!gotSource(vtx_file, vtx_string) || + !gotSource(step_conditional_file, step_conditional_string) || + !gotSource(step_simple_file, step_simple_string)) { return ""; } - std::stringstream ss; + std::stringstream ss_main; - ss << vtx_prologue; for (int i = 0; i < steps; i++) { if (conditionals) - ss << vtx_step_conditional; + ss_main << step_conditional_string; else - ss << vtx_step_simple; + ss_main << step_simple_string; } - ss << vtx_epilogue; - - return ss.str(); + + replace_string(vtx_string, "$MAIN$", ss_main.str()); + + return vtx_string; } static std::string get_fragment_shader_source(int steps, bool conditionals) { - std::string frg_prologue, frg_step_conditional, frg_step_simple, frg_epilogue; + std::string frg_string, step_conditional_string, step_simple_string; - if (!gotSource(frg_file_prologue, frg_prologue) || - !gotSource(frg_file_step_conditional, frg_step_conditional) || - !gotSource(frg_file_step_simple, frg_step_simple) || - !gotSource(frg_file_epilogue, frg_epilogue)) + if (!gotSource(frg_file, frg_string) || + !gotSource(step_conditional_file, step_conditional_string) || + !gotSource(step_simple_file, step_simple_string)) { return ""; } - std::stringstream ss; + std::stringstream ss_main; - ss << frg_prologue; for (int i = 0; i < steps; i++) { if (conditionals) - ss << frg_step_conditional; + ss_main << step_conditional_string; else - ss << frg_step_simple; + ss_main << step_simple_string; } - ss << frg_epilogue; - - return ss.str(); + + replace_string(frg_string, "$MAIN$", ss_main.str()); + + return frg_string; } void SceneConditionals::setup()