From patchwork Thu Jul 21 12:36:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 2962 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 4560623F4D for ; Thu, 21 Jul 2011 12:43:07 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id F0DCBA1822A for ; Thu, 21 Jul 2011 12:43:06 +0000 (UTC) Received: by mail-qy0-f173.google.com with SMTP id 10so3962504qyk.11 for ; Thu, 21 Jul 2011 05:43:06 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr209206qcb.38.1311252186735; Thu, 21 Jul 2011 05:43:06 -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 hl14cs139524qcb; Thu, 21 Jul 2011 05:43:06 -0700 (PDT) Received: by 10.216.78.206 with SMTP id g56mr188712wee.37.1311251798423; 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 e8si2396485wed.43.2011.07.21.05.36.38; 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-0000sH-OQ 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 B1B292E802E 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: 104 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 104: Merge implementation of shader loop benchmarking scene. Message-Id: <20110721123637.17019.51327.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: 6c100683cc373d33006ac42511027286a22c332d Merge authors: Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 104 [merge] committer: Alexandros Frantzis timestamp: Fri 2011-07-08 16:55:40 +0300 message: Merge implementation of shader loop benchmarking scene. added: data/shaders/loop-step-loop.all data/shaders/loop-step-simple.all data/shaders/loop.frag data/shaders/loop.vert src/scene-loop.cpp modified: src/main.cpp src/scene.h --- 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 === added file 'data/shaders/loop-step-loop.all' --- data/shaders/loop-step-loop.all 1970-01-01 00:00:00 +0000 +++ data/shaders/loop-step-loop.all 2011-07-08 12:48:36 +0000 @@ -0,0 +1,2 @@ + for (int i = 0; i < $NLOOPS$; i++) + d = fract(3.0 * d); === added file 'data/shaders/loop-step-simple.all' --- data/shaders/loop-step-simple.all 1970-01-01 00:00:00 +0000 +++ data/shaders/loop-step-simple.all 2011-07-08 12:48:36 +0000 @@ -0,0 +1,1 @@ + d = fract(3.0 * d); === added file 'data/shaders/loop.frag' --- data/shaders/loop.frag 1970-01-01 00:00:00 +0000 +++ data/shaders/loop.frag 2011-07-08 12:48:36 +0000 @@ -0,0 +1,16 @@ +#ifdef GL_ES +precision mediump float; +#endif + +varying vec4 dummy; +uniform int FragmentLoops; + +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/loop.vert' --- data/shaders/loop.vert 1970-01-01 00:00:00 +0000 +++ data/shaders/loop.vert 2011-07-08 12:48:36 +0000 @@ -0,0 +1,26 @@ +attribute vec3 position; + +uniform mat4 ModelViewProjectionMatrix; +uniform int VertexLoops; + +// 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/main.cpp' --- src/main.cpp 2011-07-07 13:40:51 +0000 +++ src/main.cpp 2011-07-08 13:46:32 +0000 @@ -52,6 +52,9 @@ "conditionals:vertex-steps=5:fragment-steps=0", "function:fragment-steps=5:fragment-complexity=low", "function:fragment-steps=5:fragment-complexity=medium", + "loop:vertex-steps=5:fragment-steps=5:fragment-loop=false", + "loop:vertex-steps=5:fragment-steps=5:fragment-uniform=false", + "loop:vertex-steps=5:fragment-steps=5:fragment-uniform=true", NULL }; @@ -213,6 +216,7 @@ Benchmark::register_scene(*new SceneShading(canvas)); Benchmark::register_scene(*new SceneConditionals(canvas)); Benchmark::register_scene(*new SceneFunction(canvas)); + Benchmark::register_scene(*new SceneLoop(canvas)); if (Options::list_scenes) { list_scenes(); === added file 'src/scene-loop.cpp' --- src/scene-loop.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-loop.cpp 2011-07-08 13:00:36 +0000 @@ -0,0 +1,183 @@ +/* + * Copyright © 2010-2011 Linaro Limited + * + * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark. + * + * glmark2 is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * glmark2. If not, see . + * + * Authors: + * Alexandros Frantzis (glmark2) + */ +#include "scene.h" +#include "mat.h" +#include "stack.h" +#include "vec.h" +#include "log.h" + +#include + +static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/loop"); + +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_simple_file(shader_file_base + "-step-simple.all"); +static const std::string step_loop_file(shader_file_base + "-step-loop.all"); + +SceneLoop::SceneLoop(Canvas &pCanvas) : + SceneGrid(pCanvas, "loop") +{ + mOptions["fragment-steps"] = Scene::Option("fragment-steps", "1", + "The number of computational steps in the fragment shader"); + mOptions["fragment-loop"] = Scene::Option("fragment-function", "true", + "Whether to execute the steps in the vertex shader using a for loop"); + mOptions["vertex-steps"] = Scene::Option("vertex-steps", "1", + "The number of computational steps in the vertex shader"); + mOptions["vertex-loop"] = Scene::Option("vertex-function", "true", + "Whether to execute the steps in the vertex shader using a for loop"); + mOptions["vertex-uniform"] = Scene::Option("vertex-uniform", "true", + "Whether to use a uniform in the vertex shader for the number of loop iterations to perform (i.e. vertex-steps)"); + mOptions["fragment-uniform"] = Scene::Option("fragment-uniform", "true", + "Whether to use a uniform in the fragment shader for the number of loop iterations to perform (i.e. fragment-steps)"); +} + +SceneLoop::~SceneLoop() +{ +} + +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_fragment_shader_source(int steps, bool loop, bool uniform) +{ + std::string frg_string, step_simple_string, step_loop_string; + + if (!gotSource(frg_file, frg_string) || + !gotSource(step_simple_file, step_simple_string) || + !gotSource(step_loop_file, step_loop_string)) + { + return ""; + } + + std::stringstream ss_main; + + if (loop) { + if (uniform) { + replace_string(step_loop_string, "$NLOOPS$", "FragmentLoops"); + } + else { + std::stringstream ss_steps; + ss_steps << steps; + replace_string(step_loop_string, "$NLOOPS$", ss_steps.str()); + } + ss_main << step_loop_string; + } + else { + for (int i = 0; i < steps; i++) + ss_main << step_simple_string; + } + + replace_string(frg_string, "$MAIN$", ss_main.str()); + + return frg_string; +} + +static std::string +get_vertex_shader_source(int steps, bool loop, bool uniform) +{ + std::string vtx_string, step_simple_string, step_loop_string; + + if (!gotSource(vtx_file, vtx_string) || + !gotSource(step_simple_file, step_simple_string) || + !gotSource(step_loop_file, step_loop_string)) + { + return ""; + } + + std::stringstream ss_main; + + if (loop) { + if (uniform) { + replace_string(step_loop_string, "$NLOOPS$", "VertexLoops"); + } + else { + std::stringstream ss_steps; + ss_steps << steps; + replace_string(step_loop_string, "$NLOOPS$", ss_steps.str()); + } + ss_main << step_loop_string; + } + else { + for (int i = 0; i < steps; i++) + ss_main << step_simple_string; + } + + replace_string(vtx_string, "$MAIN$", ss_main.str()); + + return vtx_string; +} + + +void SceneLoop::setup() +{ + SceneGrid::setup(); + + /* Parse options */ + bool vtx_loop = mOptions["vertex-loop"].value == "true"; + bool frg_loop = mOptions["fragment-loop"].value == "true"; + bool vtx_uniform = mOptions["vertex-uniform"].value == "true"; + bool frg_uniform = mOptions["fragment-uniform"].value == "true"; + int vtx_steps = 0; + int frg_steps = 0; + + std::stringstream ss; + + ss << mOptions["vertex-steps"].value; + ss >> vtx_steps; + ss.clear(); + ss << mOptions["fragment-steps"].value; + ss >> frg_steps; + + /* Load shaders */ + std::string vtx_shader(get_vertex_shader_source(vtx_steps, vtx_loop, + vtx_uniform)); + std::string frg_shader(get_fragment_shader_source(frg_steps, frg_loop, + frg_uniform)); + + if (!Scene::load_shaders_from_strings(mProgram, vtx_shader, frg_shader)) + return; + + mProgram.start(); + + mProgram.loadUniformScalar(vtx_steps, "VertexLoops"); + mProgram.loadUniformScalar(frg_steps, "FragmentLoops"); + + std::vector attrib_locations; + attrib_locations.push_back(mProgram.getAttribIndex("position")); + mMesh.set_attrib_locations(attrib_locations); + + mRunning = true; + mStartTime = Scene::get_timestamp_us() / 1000000.0; + mLastUpdateTime = mStartTime; +} === modified file 'src/scene.h' --- src/scene.h 2011-07-07 13:45:19 +0000 +++ src/scene.h 2011-07-08 12:48:36 +0000 @@ -244,4 +244,13 @@ ~SceneFunction(); }; + +class SceneLoop : public SceneGrid +{ +public: + SceneLoop(Canvas &pCanvas); + void setup(); + + ~SceneLoop(); +}; #endif