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: 2981 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 0B56E23F4D for ; Thu, 21 Jul 2011 12:43:44 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id B8897A18398 for ; Thu, 21 Jul 2011 12:43:43 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so854415qwb.11 for ; Thu, 21 Jul 2011 05:43:43 -0700 (PDT) Received: by 10.229.68.200 with SMTP id w8mr191681qci.114.1311252223520; Thu, 21 Jul 2011 05:43:43 -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 hl14cs139551qcb; Thu, 21 Jul 2011 05:43:43 -0700 (PDT) Received: by 10.227.198.197 with SMTP id ep5mr196426wbb.33.1311251798221; 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 c13si2404448wbh.3.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-0000s9-H6 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 7B6C12E802E 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: 101 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 101: Merge SceneFunction implementation. Message-Id: <20110721123637.17019.64171.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: c8ef2da41b1f837b28f852b986a5a8fc698050ee Merge authors: Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 101 [merge] committer: Alexandros Frantzis timestamp: Thu 2011-07-07 16:41:20 +0300 message: Merge SceneFunction implementation. added: data/shaders/function-call.all data/shaders/function-step-low.all data/shaders/function-step-medium.all data/shaders/function.frag data/shaders/function.vert src/scene-function.cpp src/scene-grid.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/function-call.all' --- data/shaders/function-call.all 1970-01-01 00:00:00 +0000 +++ data/shaders/function-call.all 2011-07-07 13:16:12 +0000 @@ -0,0 +1,1 @@ + d = process(d); === added file 'data/shaders/function-step-low.all' --- data/shaders/function-step-low.all 1970-01-01 00:00:00 +0000 +++ data/shaders/function-step-low.all 2011-07-07 13:16:12 +0000 @@ -0,0 +1,1 @@ + d = fract(3.0 * d); === added file 'data/shaders/function-step-medium.all' --- data/shaders/function-step-medium.all 1970-01-01 00:00:00 +0000 +++ data/shaders/function-step-medium.all 2011-07-07 13:16:12 +0000 @@ -0,0 +1,2 @@ + d = fract(3.0 * d) * fract(3.0 * d); + d = fract(sqrt(d)); === added file 'data/shaders/function.frag' --- data/shaders/function.frag 1970-01-01 00:00:00 +0000 +++ data/shaders/function.frag 2011-07-07 13:16:12 +0000 @@ -0,0 +1,20 @@ +#ifdef GL_ES +precision mediump float; +#endif + +varying vec4 dummy; + +float process(float d) +{ +$PROCESS$ + return d; +} + +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/function.vert' --- data/shaders/function.vert 1970-01-01 00:00:00 +0000 +++ data/shaders/function.vert 2011-07-07 13:16:12 +0000 @@ -0,0 +1,30 @@ +attribute vec3 position; + +uniform mat4 ModelViewProjectionMatrix; + +// Removing this varying causes an inexplicable performance regression +// with r600g... Keeping it for now. +varying vec4 dummy; + +float process(float d) +{ + $PROCESS$ + return d; +} + +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-06 10:10:13 +0000 +++ src/main.cpp 2011-07-07 13:40:51 +0000 @@ -50,6 +50,8 @@ "conditionals:vertex-steps=0:fragment-steps=0", "conditionals:vertex-steps=0:fragment-steps=5", "conditionals:vertex-steps=5:fragment-steps=0", + "function:fragment-steps=5:fragment-complexity=low", + "function:fragment-steps=5:fragment-complexity=medium", NULL }; @@ -210,6 +212,7 @@ Benchmark::register_scene(*new SceneTexture(canvas)); Benchmark::register_scene(*new SceneShading(canvas)); Benchmark::register_scene(*new SceneConditionals(canvas)); + Benchmark::register_scene(*new SceneFunction(canvas)); if (Options::list_scenes) { list_scenes(); === added file 'src/scene-function.cpp' --- src/scene-function.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-function.cpp 2011-07-07 13:35:24 +0000 @@ -0,0 +1,178 @@ +/* + * 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/function"); + +static const std::string vtx_file(shader_file_base + ".vert"); +static const std::string frg_file(shader_file_base + ".frag"); +static const std::string call_file(shader_file_base + "-call.all"); +static const std::string step_low_file(shader_file_base + "-step-low.all"); +static const std::string step_medium_file(shader_file_base + "-step-medium.all"); + +SceneFunction::SceneFunction(Canvas &pCanvas) : + SceneGrid(pCanvas, "function") +{ + mOptions["fragment-steps"] = Scene::Option("fragment-steps", "1", + "The number of computational steps in the fragment shader"); + mOptions["fragment-function"] = Scene::Option("fragment-function", "true", + "Whether each computational step includes a function call"); + mOptions["vertex-steps"] = Scene::Option("vertex-steps", "1", + "The number of computational steps in the vertex shader"); + mOptions["vertex-function"] = Scene::Option("vertex-function", "true", + "Whether each computational step includes an if-else clause"); + mOptions["vertex-complexity"] = Scene::Option("vertex-complexity", "low", + "The complexity of each computational step in the vertex shader"); + mOptions["fragment-complexity"] = Scene::Option("fragment-complexity", "low", + "The complexity of each computational step in the fragment shader"); +} + +SceneFunction::~SceneFunction() +{ +} + +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 function, std::string &complexity) +{ + std::string vtx_string, step_low_string, step_medium_string, call_string; + + if (!gotSource(vtx_file, vtx_string) || + !gotSource(step_low_file, step_low_string) || + !gotSource(step_medium_file, step_medium_string) || + !gotSource(call_file, call_string)) + { + return ""; + } + + std::stringstream ss_main; + std::string process_string; + + if (complexity == "low") + process_string = step_low_string; + else if (complexity == "medium") + process_string = step_medium_string; + + for (int i = 0; i < steps; i++) { + if (function) + ss_main << call_string; + else + ss_main << process_string; + } + + replace_string(vtx_string, "$PROCESS$", function ? process_string : ""); + replace_string(vtx_string, "$MAIN$", ss_main.str()); + + return vtx_string; +} + +static std::string +get_fragment_shader_source(int steps, bool function, std::string &complexity) +{ + std::string frg_string, step_low_string, step_medium_string, call_string; + + if (!gotSource(frg_file, frg_string) || + !gotSource(step_low_file, step_low_string) || + !gotSource(step_medium_file, step_medium_string) || + !gotSource(call_file, call_string)) + { + return ""; + } + + std::stringstream ss_main; + std::string process_string; + + if (complexity == "low") + process_string = step_low_string; + else if (complexity == "medium") + process_string = step_medium_string; + + for (int i = 0; i < steps; i++) { + if (function) + ss_main << call_string; + else + ss_main << process_string; + } + + replace_string(frg_string, "$PROCESS$", function ? process_string : ""); + replace_string(frg_string, "$MAIN$", ss_main.str()); + + return frg_string; +} + +void SceneFunction::setup() +{ + SceneGrid::setup(); + + /* Parse options */ + bool vtx_function = mOptions["vertex-function"].value == "true"; + bool frg_function = mOptions["fragment-function"].value == "true"; + std::string vtx_complexity = mOptions["vertex-complexity"].value; + std::string frg_complexity = mOptions["fragment-complexity"].value; + 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_function, + vtx_complexity)); + std::string frg_shader(get_fragment_shader_source(frg_steps, frg_function, + frg_complexity)); + + if (!Scene::load_shaders_from_strings(mProgram, vtx_shader, frg_shader)) + return; + + mProgram.start(); + + 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; +} === added file 'src/scene-grid.cpp' --- src/scene-grid.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-grid.cpp 2011-07-07 13:35:24 +0000 @@ -0,0 +1,139 @@ +/* + * 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 + +SceneGrid::SceneGrid(Canvas &pCanvas, const std::string &name) : + Scene(pCanvas, name) +{ + mOptions["grid-size"] = Scene::Option("grid-size", "32", + "The number of squares per side of the grid (controls the number of vertices)"); + mOptions["grid-length"] = Scene::Option("grid-length", "5.0", + "The length of each side of the grid (normalized) (controls the area drawn to)"); +} + +SceneGrid::~SceneGrid() +{ +} + +int SceneGrid::load() +{ + mRotationSpeed = 36.0f; + mRunning = false; + + return 1; +} + +void SceneGrid::unload() +{ +} + +void SceneGrid::setup() +{ + Scene::setup(); + + int grid_size = 0; + double grid_length = 0; + + std::stringstream ss; + + ss << mOptions["grid-size"].value; + ss >> grid_size; + ss.clear(); + ss << mOptions["grid-length"].value; + ss >> grid_length; + + /* Create and configure the grid mesh */ + std::vector vertex_format; + vertex_format.push_back(3); + mMesh.set_vertex_format(vertex_format); + + /* + * The spacing needed in order for the area of the requested grid + * to be the same as the area of a grid with size 32 and spacing 0.02. + */ + double spacing = grid_length * (1 - 4.38 / 5.0) / (grid_size - 1.0); + + mMesh.make_grid(grid_size, grid_size, grid_length, grid_length, + grid_size > 1 ? spacing : 0); + mMesh.build_vbo(); + + std::vector attrib_locations; + attrib_locations.push_back(mProgram.getAttribIndex("position")); + mMesh.set_attrib_locations(attrib_locations); + + mCurrentFrame = 0; + mRotation = 0.0f; +} + +void SceneGrid::teardown() +{ + mProgram.stop(); + mProgram.release(); + mMesh.reset(); + + Scene::teardown(); +} + +void SceneGrid::update() +{ + double current_time = Scene::get_timestamp_us() / 1000000.0; + double dt = current_time - mLastUpdateTime; + double elapsed_time = current_time - mStartTime; + + mLastUpdateTime = current_time; + + if (elapsed_time >= mDuration) { + mAverageFPS = mCurrentFrame / elapsed_time; + mRunning = false; + } + + mRotation += mRotationSpeed * dt; + + mCurrentFrame++; +} + +void SceneGrid::draw() +{ + // Load the ModelViewProjectionMatrix uniform in the shader + LibMatrix::Stack4 model_view; + LibMatrix::mat4 model_view_proj(mCanvas.projection()); + + model_view.translate(0.0f, 0.0f, -5.0f); + model_view.rotate(mRotation, 0.0f, 0.0f, 1.0f); + model_view_proj *= model_view.getCurrent(); + + mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); + + mMesh.render_vbo(); +} + +Scene::ValidationResult +SceneGrid::validate() +{ + return Scene::ValidationUnknown; +} === modified file 'src/scene.h' --- src/scene.h 2011-07-04 13:22:56 +0000 +++ src/scene.h 2011-07-07 13:35:24 +0000 @@ -205,6 +205,28 @@ float mRotationSpeed; }; +class SceneGrid : public Scene +{ +public: + SceneGrid(Canvas &pCanvas, const std::string &name); + virtual int load(); + virtual void unload(); + virtual void setup(); + virtual void teardown(); + virtual void update(); + virtual void draw(); + virtual ValidationResult validate(); + + ~SceneGrid(); + +protected: + Program mProgram; + + Mesh mMesh; + float mRotation; + float mRotationSpeed; +}; + class SceneConditionals : public Scene { public: @@ -226,4 +248,13 @@ float mRotation; float mRotationSpeed; }; + +class SceneFunction : public SceneGrid +{ +public: + SceneFunction(Canvas &pCanvas); + void setup(); + + ~SceneFunction(); +}; #endif