<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 5, 2013, at 7:14 PM, "Redmond, Paul" <<a href="mailto:paul.redmond@intel.com">paul.redmond@intel.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">Seems reasonable to me.<br></div></blockquote><div><br></div><div>Committed r176561. Thanks, Paul.</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>From: Chad Rosier <<a href="mailto:mcrosier@apple.com">mcrosier@apple.com</a><<a href="mailto:mcrosier@apple.com">mailto:mcrosier@apple.com</a>>><br>Date: Tuesday, 5 March, 2013 5:54 PM<br>To: "<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><<a href="mailto:llvm-commits@cs.uiuc.edu">mailto:llvm-commits@cs.uiuc.edu</a>>" <<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><<a href="mailto:llvm-commits@cs.uiuc.edu">mailto:llvm-commits@cs.uiuc.edu</a>>><br>Cc: Paul Redmond <<a href="mailto:paul.redmond@intel.com">paul.redmond@intel.com</a><<a href="mailto:paul.redmond@intel.com">mailto:paul.redmond@intel.com</a>>>, Duncan Sands <<a href="mailto:baldrick@free.fr">baldrick@free.fr</a><<a href="mailto:baldrick@free.fr">mailto:baldrick@free.fr</a>>><br>Subject: Re: [llvm-commits] [test-suite] r171745 - in /test-suite/trunk: LICENSE.TXT SingleSource/Benchmarks/Makefile SingleSource/Benchmarks/SmallPT/ SingleSource/Benchmarks/SmallPT/LICENSE.txt SingleSource/Benchmarks/SmallPT/Makefile SingleSource/Benchmarks/S...<br><br>All,<br>Smallpt has been failing on a few of our internal nightly testers since it was introduced. Fortunately,<br>there's nothing wrong with the code that's being generated. The issue is that the stack is being<br>blown out for unoptimized builds. Below is a patch that bounds the recursion in an attempt to<br>prevent such failures. Hopefully, this makes the runtime a little more tractable as well.<br><br>Index: SingleSource/Benchmarks/SmallPT/smallpt.cpp<br>===================================================================<br>--- SingleSource/Benchmarks/SmallPT/smallpt.cpp(revision 176513)<br>+++ SingleSource/Benchmarks/SmallPT/smallpt.cpp(working copy)<br>@@ -53,6 +53,7 @@<br> Vec x=r.o+r.d*t, n=(x-obj.p).norm(), nl=n.dot(r.d)<0?n:n*-1, f=obj.c;<br> double p = f.x>f.y && f.x>f.z ? f.x : f.y>f.z ? f.y : f.z; // max refl<br> if (++depth>5) if (erand48(Xi)<p) f=f*(1/p); else return obj.e; //R.R.<br>+ if (depth>128) return obj.e; //Bound to avoid stack overflow at -O0.<br> if (obj.refl == DIFF){ // Ideal DIFFUSE reflection<br> double r1=2*M_PI*erand48(Xi), r2=erand48(Xi), r2s=sqrt(r2);<br> Vec w=nl, u=((fabs(w.x)>.1?Vec(0,1):Vec(1))%w).norm(), v=w%u;<br><br>Chad<br><br>On Jan 7, 2013, at 7:25 AM, Paul Redmond <<a href="mailto:paul.redmond@intel.com">paul.redmond@intel.com</a><<a href="mailto:paul.redmond@intel.com">mailto:paul.redmond@intel.com</a>>> wrote:<br><br>Author: predmond<br>Date: Mon Jan 7 09:25:10 2013<br>New Revision: 171745<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=171745&view=rev">http://llvm.org/viewvc/llvm-project?rev=171745&view=rev</a><br>Log:<br>add smallpt benchmark to test-suite<br><br>original source from<span class="Apple-converted-space"> </span><a href="http://www.kevinbeason.com/smallpt/">http://www.kevinbeason.com/smallpt/</a><span class="Apple-converted-space"> </span>with the following<br>modifications:<br>- commented out openmp pragma<br>- disabled writing to output image to file<br><br>Added:<br> test-suite/trunk/SingleSource/Benchmarks/SmallPT/<br> test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt<br> test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile<br> test-suite/trunk/SingleSource/Benchmarks/SmallPT/README<br> test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp<br> test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output<br>Modified:<br> test-suite/trunk/LICENSE.TXT<br> test-suite/trunk/SingleSource/Benchmarks/Makefile<br><br>Modified: test-suite/trunk/LICENSE.TXT<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/LICENSE.TXT?rev=171745&r1=171744&r2=171745&view=diff">http://llvm.org/viewvc/llvm-project/test-suite/trunk/LICENSE.TXT?rev=171745&r1=171744&r2=171745&view=diff</a><br>==============================================================================<br>--- test-suite/trunk/LICENSE.TXT (original)<br>+++ test-suite/trunk/LICENSE.TXT Mon Jan 7 09:25:10 2013<br>@@ -108,3 +108,4 @@<br>SingleSource Tests: llvm-test/SingleSource/Benchmarks/Misc<br> llvm-test/SingleSource/CustomChecked<br> llvm-test/SingleSource/Gizmos<br>+ llvm-test/SingleSource/Benchmarks/SmallPT<br><br>Modified: test-suite/trunk/SingleSource/Benchmarks/Makefile<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/Makefile?rev=171745&r1=171744&r2=171745&view=diff">http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/Makefile?rev=171745&r1=171744&r2=171745&view=diff</a><br>==============================================================================<br>--- test-suite/trunk/SingleSource/Benchmarks/Makefile (original)<br>+++ test-suite/trunk/SingleSource/Benchmarks/Makefile Mon Jan 7 09:25:10 2013<br>@@ -1,6 +1,7 @@<br>LEVEL = ../..<br>PARALLEL_DIRS := Dhrystone CoyoteBench Shootout Shootout-C++ Stanford McGill \<br>- Misc Misc-C++ Misc-C++-EH BenchmarkGame Adobe-C++ Polybench Linpack LivermoreLoops<br>+ Misc Misc-C++ Misc-C++-EH BenchmarkGame Adobe-C++ Polybench Linpack LivermoreLoops \<br>+ SmallPT<br>LDFLAGS += -lm<br><br># Disable Polybench tests on ARM for the time being, they are very long running.<br><br>Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt?rev=171745&view=auto">http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt?rev=171745&view=auto</a><br>==============================================================================<br>--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt (added)<br>+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt Mon Jan 7 09:25:10 2013<br>@@ -0,0 +1,22 @@<br>+LICENSE<br>+<br>+Copyright (c) 2006-2008 Kevin Beason (<a href="mailto:kevin.beason@gmail.com">kevin.beason@gmail.com</a><<a href="mailto:kevin.beason@gmail.com">mailto:kevin.beason@gmail.com</a>>)<br>+<br>+Permission is hereby granted, free of charge, to any person obtaining<br>+a copy of this software and associated documentation files (the<br>+"Software"), to deal in the Software without restriction, including<br>+without limitation the rights to use, copy, modify, merge, publish,<br>+distribute, sublicense, and/or sell copies of the Software, and to<br>+permit persons to whom the Software is furnished to do so, subject to<br>+the following conditions:<br>+<br>+The above copyright notice and this permission notice shall be included<br>+in all copies or substantial portions of the Software.<br>+<br>+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.<br>+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY<br>+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br><br>Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile?rev=171745&view=auto">http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile?rev=171745&view=auto</a><br>==============================================================================<br>--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile (added)<br>+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile Mon Jan 7 09:25:10 2013<br>@@ -0,0 +1,7 @@<br>+LEVEL = ../../..<br>+LDFLAGS += -lm<br>+FP_TOLERANCE := 0.001<br>+<br>+include $(LEVEL)/Makefile.config<br>+<br>+include $(LEVEL)/SingleSource/Makefile.singlesrc<br><br>Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/README<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/README?rev=171745&view=auto">http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/README?rev=171745&view=auto</a><br>==============================================================================<br>--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/README (added)<br>+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/README Mon Jan 7 09:25:10 2013<br>@@ -0,0 +1,119 @@<br>+TITLE<br>+<br>+smallpt: Global Illumination in 99 lines of C++<br>+<br>+CREDITS<br>+<br>+Author: Kevin Beason (kevin.beason [at]<span class="Apple-converted-space"> </span><a href="http://gmail.com/">gmail.com</a><<a href="http://gmail.com/">http://gmail.com/</a>>)<br>+Date: 10/11/2008<br>+<br>+SUMMARY<br>+<br>+smallpt is a small Monte Carlo path tracer, and generates a single image of a<br>+modified Cornell box rendered with full global illumination (GI). It does this<br>+by solving the rendering equation, including ideal Lambertian, specular, and<br>+dielectric reflection, area lights, anti-aliasing, importance sampling, and<br>+multi-threading. It is only 99 lines of C++, but illustrates photo realistic<br>+rendering in a correct, and concise manner.<br>+<br>+DESCRIPTION<br>+<br>+The source code for a small program that path traces a simple Cornell box and<br>+produces accurate results in a terse implementation is given, which provides an<br>+educational example to new graphics students (and seasoned alike), and yields a<br>+ground truth image, all in an easy to read package. Never before has a correct,<br>+complete, and functioning path tracer been presented so succinctly. Readers<br>+will see ray-sphere intersection, Monte Carlo path tracing, Russian roulette,<br>+importance sampling, anti-aliasing, and OpenMP multi-threading in a concrete<br>+working example, which may be read from beginning to end in a single<br>+sitting. The program compiles with GCC 4.2 down to a 16k executable and<br>+produces a 1024x768 resolution image using 5000 paths in 2 hours on an Intel<br>+Core 2 Quad machine. With slight modifications (smallpt4k.cpp) the code compiles to<br>+under 4KB.<br>+<br>+FEATURES<br>+<br>+* Global illumination<br>+* Unbiased Monte Carlo path tracing<br>+* Cornell box scene description<br>+* Ray-sphere intersection<br>+* Soft shadows from diffuse luminaire<br>+* Specular, Diffuse, and Glass BRDFs<br>+* Cosine importance sampling of the hemisphere for diffuse reflection<br>+* Russian roulette for path termination<br>+* Russian roulette for selecting reflection or refraction for glass BRDF<br>+* Antialiasing via super-sampling with importance-sampled tent distribution,<br>+ and 2x2 subpixels<br>+* Automatic multi-threading using OpenMP<br>+* Less than 100 lines of 72-column code<br>+* With provided code changes, can compile to 4K binary<br>+<br>+BUILDING<br>+<br>+There are two versions of smallpt. The basic version is called "smallpt"<br>+(smallpt.cpp), and is 99 lines. A second version, "smallpt4k" (smallpt4k.cpp),<br>+is 102 lines but compiles to 4K instead of 16KB. It is just a<br>+proof-of-concept. They compute slightly different images due to compiler optimization differences.<br>+The 4 KB version takes 30% longer.<br>+<br>+1) Modify top of Makefile to select the correct compiler.<br>+2) "make smallpt" (This builds both the regular version)<br>+3) "make smallpt4k" (This builds the 4K version. Requires sstrip, see Makefile.)<br>+<br>+USAGE<br>+<br>+The program takes one argument, the number of samples per pixel. This value<br>+must be greater than 4 to accommodate the 2x2 subpixel grid. For example,<br>+the included reference image was generated with:<br>+<br>+ time ./smallpt 5000<br>+<br>+This took 124 minutes (2 hours) on a Intel Core 2 Quad Q6600 2.4GHz machine<br>+running Kubuntu Linux (32-bit Gutsy).<br>+<br>+The tiny version takes no arguments (5000 samples/pixel is hard coded):<br>+<br>+ time ./smallpt4k<br>+<br>+Compilation requires gzip and ELFkicker's sstrip command. See the Makefile for<br>+details. It executes in slightly longer time, and yields a slightly different<br>+image due to compiler optimizations differences.<br>+<br>+The time command tells you how long the render takes and is optional. You can<br>+view the image with most any image viewer. For example, if you have ImageMagick<br>+installed:<br>+<br>+ display image.ppm<br>+<br>+MORE INFO<br>+<br>+MINILIGHT - a minimal global illumination renderer, by Harrison Ainsworth<br>+A similar, earlier project. More general but also larger (100x). The site has<br>+some good information on Monte Carlo path tracing. Instead of repeating it<br>+here, the reader is referred to that site:<br>+<a href="http://www.hxa7241.org/minilight/minilight.html">http://www.hxa7241.org/minilight/minilight.html</a><br>+<br>+Realistic Ray Tracing by Peter Shirley<br>+Almost 100% of smallpt is derived from this book.<br>+<a href="http://www.amazon.com/Realistic-Ray-Tracing-Peter-Shirley/dp/1568811101">http://www.amazon.com/Realistic-Ray-Tracing-Peter-Shirley/dp/1568811101</a><br>+<br>+Henrik Wann Jensen's Cornell box images<br>+The inpiration of the output generated by smallpt.<br>+<a href="http://graphics.ucsd.edu/~henrik/images/cbox.html">http://graphics.ucsd.edu/~henrik/images/cbox.html</a><br>+<br>+100 lines C++ sphereflake raytracer, by Thierry Berger-Perrin<br>+Ray sphere intersection code stolen from here. (No full GI.)<br>+<a href="http://ompf.org/ray/sphereflake/">http://ompf.org/ray/sphereflake/</a><br>+<br>+sf4k, also by Thierry Berger-Perrin<br>+Idea for 4K-ness. (No full GI.)<br>+<a href="http://ompf.org/stuff/sf4k/">http://ompf.org/stuff/sf4k/</a><br>+<br>+C++ vs OCaml: Ray tracer comparison, by Jon D. Harrop<br>+105 line C++ ray tracer. (No full GI.)<br>+<a href="http://www.ffconsultancy.com/languages/ray_tracer/comparison.html">http://www.ffconsultancy.com/languages/ray_tracer/comparison.html</a><br>+<br>+Introduction to Linux as 4 KB Platform<br>+Some information regarding shrinking binaries to 4KB on Linux .<br>+<a href="http://in4k.untergrund.net/index.php?title=Linux">http://in4k.untergrund.net/index.php?title=Linux</a><br>+<br><br>Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp?rev=171745&view=auto">http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp?rev=171745&view=auto</a><br>==============================================================================<br>--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp (added)<br>+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp Mon Jan 7 09:25:10 2013<br>@@ -0,0 +1,102 @@<br>+#include <math.h> // smallpt, a Path Tracer by Kevin Beason, 2008<br>+#include <stdlib.h> // Make : g++ -O3 -fopenmp smallpt.cpp -o smallpt<br>+#include <stdio.h> // Remove "-fopenmp" for g++ version < 4.2<br>+struct Vec { // Usage: time ./smallpt 5000 && xv image.ppm<br>+ double x, y, z; // position, also color (r,g,b)<br>+ Vec(double x_=0, double y_=0, double z_=0){ x=x_; y=y_; z=z_; }<br>+ Vec operator+(const Vec &b) const { return Vec(x+b.x,y+b.y,z+b.z); }<br>+ Vec operator-(const Vec &b) const { return Vec(x-b.x,y-b.y,z-b.z); }<br>+ Vec operator*(double b) const { return Vec(x*b,y*b,z*b); }<br>+ Vec mult(const Vec &b) const { return Vec(x*b.x,y*b.y,z*b.z); }<br>+ Vec& norm(){ return *this = *this * (1/sqrt(x*x+y*y+z*z)); }<br>+ double dot(const Vec &b) const { return x*b.x+y*b.y+z*b.z; } // cross:<br>+ Vec operator%(Vec&b){return Vec(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);}<br>+};<br>+struct Ray { Vec o, d; Ray(Vec o_, Vec d_) : o(o_), d(d_) {} };<br>+enum Refl_t { DIFF, SPEC, REFR }; // material types, used in radiance()<br>+struct Sphere {<br>+ double rad; // radius<br>+ Vec p, e, c; // position, emission, color<br>+ Refl_t refl; // reflection type (DIFFuse, SPECular, REFRactive)<br>+ Sphere(double rad_, Vec p_, Vec e_, Vec c_, Refl_t refl_):<br>+ rad(rad_), p(p_), e(e_), c(c_), refl(refl_) {}<br>+ double intersect(const Ray &r) const { // returns distance, 0 if nohit<br>+ Vec op = p-r.o; // Solve t^2*d.d + 2*t*(o-p).d + (o-p).(o-p)-R^2 = 0<br>+ double t, eps=1e-4, b=op.dot(r.d), det=b*b-op.dot(op)+rad*rad;<br>+ if (det<0) return 0; else det=sqrt(det);<br>+ return (t=b-det)>eps ? t : ((t=b+det)>eps ? t : 0);<br>+ }<br>+};<br>+Sphere spheres[] = {//Scene: radius, position, emission, color, material<br>+ Sphere(1e5, Vec( 1e5+1,40.8,81.6), Vec(),Vec(.75,.25,.25),DIFF),//Left<br>+ Sphere(1e5, Vec(-1e5+99,40.8,81.6),Vec(),Vec(.25,.25,.75),DIFF),//Rght<br>+ Sphere(1e5, Vec(50,40.8, 1e5), Vec(),Vec(.75,.75,.75),DIFF),//Back<br>+ Sphere(1e5, Vec(50,40.8,-1e5+170), Vec(),Vec(), DIFF),//Frnt<br>+ Sphere(1e5, Vec(50, 1e5, 81.6), Vec(),Vec(.75,.75,.75),DIFF),//Botm<br>+ Sphere(1e5, Vec(50,-1e5+81.6,81.6),Vec(),Vec(.75,.75,.75),DIFF),//Top<br>+ Sphere(16.5,Vec(27,16.5,47), Vec(),Vec(1,1,1)*.999, SPEC),//Mirr<br>+ Sphere(16.5,Vec(73,16.5,78), Vec(),Vec(1,1,1)*.999, REFR),//Glas<br>+ Sphere(600, Vec(50,681.6-.27,81.6),Vec(12,12,12), Vec(), DIFF) //Lite<br>+};<br>+inline double clamp(double x){ return x<0 ? 0 : x>1 ? 1 : x; }<br>+inline int toInt(double x){ return int(pow(clamp(x),1/2.2)*255+.5); }<br>+inline bool intersect(const Ray &r, double &t, int &id){<br>+ double n=sizeof(spheres)/sizeof(Sphere), d, inf=t=1e20;<br>+ for(int i=int(n);i--;) if((d=spheres[i].intersect(r))&&d<t){t=d;id=i;}<br>+ return t<inf;<br>+}<br>+Vec radiance(const Ray &r, int depth, unsigned short *Xi){<br>+ double t; // distance to intersection<br>+ int id=0; // id of intersected object<br>+ if (!intersect(r, t, id)) return Vec(); // if miss, return black<br>+ const Sphere &obj = spheres[id]; // the hit object<br>+ Vec x=r.o+r.d*t, n=(x-obj.p).norm(), nl=n.dot(r.d)<0?n:n*-1, f=obj.c;<br>+ double p = f.x>f.y && f.x>f.z ? f.x : f.y>f.z ? f.y : f.z; // max refl<br>+ if (++depth>5) if (erand48(Xi)<p) f=f*(1/p); else return obj.e; //R.R.<br>+ if (obj.refl == DIFF){ // Ideal DIFFUSE reflection<br>+ double r1=2*M_PI*erand48(Xi), r2=erand48(Xi), r2s=sqrt(r2);<br>+ Vec w=nl, u=((fabs(w.x)>.1?Vec(0,1):Vec(1))%w).norm(), v=w%u;<br>+ Vec d = (u*cos(r1)*r2s + v*sin(r1)*r2s + w*sqrt(1-r2)).norm();<br>+ return obj.e + f.mult(radiance(Ray(x,d),depth,Xi));<br>+ } else if (obj.refl == SPEC) // Ideal SPECULAR reflection<br>+ return obj.e + f.mult(radiance(Ray(x,r.d-n*2*n.dot(r.d)),depth,Xi));<br>+ Ray reflRay(x, r.d-n*2*n.dot(r.d)); // Ideal dielectric REFRACTION<br>+ bool into = n.dot(nl)>0; // Ray from outside going in?<br>+ double nc=1, nt=1.5, nnt=into?nc/nt:nt/nc, ddn=r.d.dot(nl), cos2t;<br>+ if ((cos2t=1-nnt*nnt*(1-ddn*ddn))<0) // Total internal reflection<br>+ return obj.e + f.mult(radiance(reflRay,depth,Xi));<br>+ Vec tdir = (r.d*nnt - n*((into?1:-1)*(ddn*nnt+sqrt(cos2t)))).norm();<br>+ double a=nt-nc, b=nt+nc, R0=a*a/(b*b), c = 1-(into?-ddn:tdir.dot(n));<br>+ double Re=R0+(1-R0)*c*c*c*c*c,Tr=1-Re,P=.25+.5*Re,RP=Re/P,TP=Tr/(1-P);<br>+ return obj.e + f.mult(depth>2 ? (erand48(Xi)<P ? // Russian roulette<br>+ radiance(reflRay,depth,Xi)*RP:radiance(Ray(x,tdir),depth,Xi)*TP) :<br>+ radiance(reflRay,depth,Xi)*Re+radiance(Ray(x,tdir),depth,Xi)*Tr);<br>+}<br>+int main(int argc, char *argv[]){<br>+ int w=1024, h=768, samps = argc==2 ? atoi(argv[1])/4 : 1; // # samples<br>+ Ray cam(Vec(50,52,295.6), Vec(0,-0.042612,-1).norm()); // cam pos, dir<br>+ Vec cx=Vec(w*.5135/h), cy=(cx%cam.d).norm()*.5135, r, *c=new Vec[w*h];<br>+ //#pragma omp parallel for schedule(dynamic, 1) private(r) // OpenMP<br>+ fprintf(stderr,"Rendering (%d spp)\n",samps*4);<br>+ for (int y=0; y<h; y++){ // Loop over image rows<br>+ //fprintf(stderr,"\rRendering (%d spp) %5.2f%%",samps*4,100.*y/(h-1));<br>+ for (unsigned short x=0, Xi[3]={0,0,y*y*y}; x<w; x++) // Loop cols<br>+ for (int sy=0, i=(h-y-1)*w+x; sy<2; sy++) // 2x2 subpixel rows<br>+ for (int sx=0; sx<2; sx++, r=Vec()){ // 2x2 subpixel cols<br>+ for (int s=0; s<samps; s++){<br>+ double r1=2*erand48(Xi), dx=r1<1 ? sqrt(r1)-1: 1-sqrt(2-r1);<br>+ double r2=2*erand48(Xi), dy=r2<1 ? sqrt(r2)-1: 1-sqrt(2-r2);<br>+ Vec d = cx*( ( (sx+.5 + dx)/2 + x)/w - .5) +<br>+ cy*( ( (sy+.5 + dy)/2 + y)/h - .5) + cam.d;<br>+ r = r + radiance(Ray(cam.o+d*140,d.norm()),0,Xi)*(1./samps);<br>+ } // Camera rays are pushed ^^^^^ forward to start in interior<br>+ c[i] = c[i] + Vec(clamp(r.x),clamp(r.y),clamp(r.z))*.25;<br>+ }<br>+ }<br>+#if 0<br>+ FILE *f = fopen("image.ppm", "w"); // Write image to PPM file.<br>+ fprintf(f, "P3\n%d %d\n%d\n", w, h, 255);<br>+ for (int i=0; i<w*h; i++)<br>+ fprintf(f, "%d %d %d\n", toInt(c[i].x), toInt(c[i].y), toInt(c[i].z));<br>+#endif<br>+}<br><br>Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output?rev=171745&view=auto">http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output?rev=171745&view=auto</a><br>==============================================================================<br>--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output (added)<br>+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output Mon Jan 7 09:25:10 2013<br>@@ -0,0 +1,2 @@<br>+Rendering (4 spp)<br>+exit 0<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><<a href="mailto:llvm-commits@cs.uiuc.edu">mailto:llvm-commits@cs.uiuc.edu</a>><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br></body></html>