8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 import com.sun.scenario.effect.compiler.JSLC; 27 import com.sun.scenario.effect.compiler.JSLC.JSLCInfo; 28 import com.sun.scenario.effect.impl.state.LinearConvolveKernel; 29 import java.io.File; 30 31 /** 32 * This class is only used at build time to generate EffectPeer 33 * implementations from the LinearConvolve JSL file, and should 34 * not be included in the resulting runtime jar file. 35 */ 36 public class CompileLinearConvolve { 37 /* 38 * The basic idea here is to create a few different versions of the 39 * LinearConvolve hardware effect peers, based on the kernel size. 40 * The LinearConvolveKernel state class contains the algorithm that 41 * determines how many peers should be generated and at which optimized 42 * sizes. 43 */ 44 private static void compileLinearConvolve(JSLCInfo jslcinfo, String name) 45 throws Exception 46 { 47 int outTypes = jslcinfo.outTypes; 48 jslcinfo.shaderName = "Effect"; 49 File baseFile = jslcinfo.getJSLFile(name); 50 String base = CompileJSL.readFile(baseFile); 51 long basetime = baseFile.lastModified(); 52 53 // output one hardware shader for each unrolled size (as determined 54 // by the LinearConvolveKernel quantization algorithm) 55 jslcinfo.outTypes = (outTypes & JSLC.OUT_HW_SHADERS); 56 int lastpeersize = -1; 57 for (int i = 1; i < LinearConvolveKernel.MAX_KERNEL_SIZE; i += 4) { 58 int peersize = LinearConvolveKernel.getPeerSize(i); 59 if (peersize != lastpeersize) { 60 String source = String.format(base, peersize/4, peersize/4); 61 jslcinfo.peerName = name + "_" + peersize; 62 JSLC.compile(jslcinfo, source, basetime); 63 lastpeersize = peersize; 64 } 65 } 66 67 // output a single hardware peer class (can be instantiated for 68 // each of the shaders generated above) 69 jslcinfo.outTypes = (outTypes & JSLC.OUT_HW_PEERS); 70 jslcinfo.peerName = name; 71 jslcinfo.interfaceName = "LinearConvolvePeer"; 72 int peersize = LinearConvolveKernel.MAX_KERNEL_SIZE / 4; 73 String genericbase = String.format(base, peersize, 0); 74 JSLC.compile(jslcinfo, genericbase, basetime); 75 76 // output a single version of the software peer (there's 77 // no loop unrolling in this case) 78 jslcinfo.outTypes = (outTypes & JSLC.OUT_SW_PEERS); 79 JSLC.compile(jslcinfo, genericbase, basetime); 80 } 81 82 public static void main(String[] args) throws Exception { 83 JSLCInfo jslcinfo = new JSLCInfo("LinearConvolve[Shadow]"); 84 int index = jslcinfo.parseArgs(args); 85 if (index != args.length - 1) { 86 jslcinfo.usage(System.err); 87 } 88 String arg = args[index]; 89 if (arg.equals("LinearConvolve") || 90 arg.equals("LinearConvolveShadow")) 91 { 92 compileLinearConvolve(jslcinfo, arg); | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 import com.sun.scenario.effect.compiler.JSLC; 27 import com.sun.scenario.effect.compiler.JSLC.JSLCInfo; 28 import com.sun.scenario.effect.impl.state.LinearConvolveRenderState; 29 import java.io.File; 30 31 /** 32 * This class is only used at build time to generate EffectPeer 33 * implementations from the LinearConvolve JSL file, and should 34 * not be included in the resulting runtime jar file. 35 */ 36 public class CompileLinearConvolve { 37 /* 38 * The basic idea here is to create a few different versions of the 39 * LinearConvolve hardware effect peers, based on the kernel size. 40 * The LinearConvolveRenderState state class contains the algorithm that 41 * determines how many peers should be generated and at which optimized 42 * sizes. 43 */ 44 private static void compileLinearConvolve(JSLCInfo jslcinfo, String name) 45 throws Exception 46 { 47 int outTypes = jslcinfo.outTypes; 48 jslcinfo.shaderName = "Effect"; 49 File baseFile = jslcinfo.getJSLFile(name); 50 String base = CompileJSL.readFile(baseFile); 51 long basetime = baseFile.lastModified(); 52 53 // output one hardware shader for each unrolled size (as determined 54 // by the LinearConvolveRenderState quantization algorithm) 55 jslcinfo.outTypes = (outTypes & JSLC.OUT_HW_SHADERS); 56 int lastpeersize = -1; 57 for (int i = 1; i < LinearConvolveRenderState.MAX_KERNEL_SIZE; i += 4) { 58 int peersize = LinearConvolveRenderState.getPeerSize(i); 59 if (peersize != lastpeersize) { 60 String source = String.format(base, peersize/4, peersize/4); 61 jslcinfo.peerName = name + "_" + peersize; 62 JSLC.compile(jslcinfo, source, basetime); 63 lastpeersize = peersize; 64 } 65 } 66 67 // output a single hardware peer class (can be instantiated for 68 // each of the shaders generated above) 69 jslcinfo.outTypes = (outTypes & JSLC.OUT_HW_PEERS); 70 jslcinfo.peerName = name; 71 jslcinfo.genericsName = "LinearConvolveRenderState"; 72 jslcinfo.interfaceName = null; // "LinearConvolvePeer"; 73 int peersize = LinearConvolveRenderState.MAX_KERNEL_SIZE / 4; 74 String genericbase = String.format(base, peersize, 0); 75 JSLC.compile(jslcinfo, genericbase, basetime); 76 77 // output a single version of the software peer (there's 78 // no loop unrolling in this case) 79 jslcinfo.outTypes = (outTypes & JSLC.OUT_SW_PEERS); 80 JSLC.compile(jslcinfo, genericbase, basetime); 81 } 82 83 public static void main(String[] args) throws Exception { 84 JSLCInfo jslcinfo = new JSLCInfo("LinearConvolve[Shadow]"); 85 int index = jslcinfo.parseArgs(args); 86 if (index != args.length - 1) { 87 jslcinfo.usage(System.err); 88 } 89 String arg = args[index]; 90 if (arg.equals("LinearConvolve") || 91 arg.equals("LinearConvolveShadow")) 92 { 93 compileLinearConvolve(jslcinfo, arg); |