[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49743] trunk/blender: generate COM_OpenCLKernels.cl.h automatically at build time, this allows editing COM_OpenCLKernels. cl and rebuilding and means we dont have to have both files in svn.

Campbell Barton ideasman42 at gmail.com
Thu Aug 9 21:59:37 CEST 2012


Revision: 49743
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49743
Author:   campbellbarton
Date:     2012-08-09 19:59:36 +0000 (Thu, 09 Aug 2012)
Log Message:
-----------
generate COM_OpenCLKernels.cl.h automatically at build time, this allows editing COM_OpenCLKernels.cl and rebuilding and means we dont have to have both files in svn.

updates made to cmake and scons.

Modified Paths:
--------------
    trunk/blender/SConstruct
    trunk/blender/source/blender/compositor/CMakeLists.txt
    trunk/blender/source/blender/compositor/SConscript
    trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp

Added Paths:
-----------
    trunk/blender/build_files/cmake/data_to_c.cmake

Removed Paths:
-------------
    trunk/blender/release/datafiles/clkernelstoh.py
    trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h

Modified: trunk/blender/SConstruct
===================================================================
--- trunk/blender/SConstruct	2012-08-09 18:12:58 UTC (rev 49742)
+++ trunk/blender/SConstruct	2012-08-09 19:59:36 UTC (rev 49743)
@@ -445,6 +445,50 @@
 # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']:
 #     os.makedirs ( B.doc_build_dir )
 
+###################################
+# Ensure all data files are valid #
+###################################
+if not os.path.isdir ( B.root_build_dir + 'data_headers'):
+	os.makedirs ( B.root_build_dir + 'data_headers' )
+# use for includes
+env['DATA_HEADERS'] = "#" + env['BF_BUILDDIR'] + "/data_headers"
+def ensure_data(FILE_FROM, FILE_TO, VAR_NAME):
+	if os.sep == "\\":
+		FILE_FROM = FILE_FROM.replace("/", "\\")
+		FILE_TO   = FILE_TO.replace("/", "\\")
+
+	# first check if we need to bother.
+	if os.path.exists(FILE_TO):
+		if os.path.getmtime(FILE_FROM) < os.path.getmtime(FILE_TO):
+			return
+
+	print(B.bc.HEADER + "Generating: " + B.bc.ENDC + "%r" % os.path.basename(FILE_TO))
+	fpin = open(FILE_FROM, "rb")
+	fpin.seek(0, os.SEEK_END)
+	size = fpin.tell()
+	fpin.seek(0)
+
+	fpout = open(FILE_TO, "w")
+	fpout.write("int  %s_size = %d;\n" % (VAR_NAME, size))
+	fpout.write("char %s[] = {\n" % VAR_NAME)
+
+	while size > 0:
+		size -= 1
+		if size % 32 == 31:
+			fpout.write("\n")
+
+		fpout.write("%3d," % ord(fpin.read(1)))
+	fpout.write("\n  0};\n\n")
+
+	fpin.close()
+	fpout.close()
+
+ensure_data("source/blender/compositor/operations/COM_OpenCLKernels.cl",
+            B.root_build_dir + "data_headers/COM_OpenCLKernels.cl.h",
+            "clkernelstoh_COM_OpenCLKernels_cl")
+
+##### END DATAFILES ##########
+
 Help(opts.GenerateHelpText(env))
 
 # default is new quieter output, but if you need to see the 

Added: trunk/blender/build_files/cmake/data_to_c.cmake
===================================================================
--- trunk/blender/build_files/cmake/data_to_c.cmake	                        (rev 0)
+++ trunk/blender/build_files/cmake/data_to_c.cmake	2012-08-09 19:59:36 UTC (rev 49743)
@@ -0,0 +1,25 @@
+# cmake script, to be called on its own with 3 defined args
+#
+# - FILE_FROM
+# - FILE_TO
+# - VAR_NAME
+
+# not highly optimal, may replace with generated C program like makesdna
+file(READ ${FILE_FROM} file_from_string HEX)
+string(LENGTH ${file_from_string} _max_index)
+math(EXPR size_on_disk ${_max_index}/2)
+
+file(REMOVE ${FILE_TO})
+
+file(APPEND ${FILE_TO} "int  ${VAR_NAME}_size = ${size_on_disk};\n")
+file(APPEND ${FILE_TO} "char ${VAR_NAME}[] = {")
+
+set(_index 0)
+
+while(NOT _index EQUAL _max_index)
+    string(SUBSTRING "${file_from_string}" ${_index} 2 _pair)
+    file(APPEND ${FILE_TO} "0x${_pair},")
+    math(EXPR _index ${_index}+2)
+endwhile()
+# null terminator not essential but good if we want plane strings encoded
+file(APPEND ${FILE_TO} "0x00};\n")

Deleted: trunk/blender/release/datafiles/clkernelstoh.py
===================================================================
--- trunk/blender/release/datafiles/clkernelstoh.py	2012-08-09 18:12:58 UTC (rev 49742)
+++ trunk/blender/release/datafiles/clkernelstoh.py	2012-08-09 19:59:36 UTC (rev 49743)
@@ -1,70 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# This program 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 2
-# of the License, or (at your option) any later version.
-#
-# This program 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 this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2012 Blender Foundation.
-# All rights reserved.
-#
-# Contributor(s): Jeroen Bakker
-#
-# ***** END GPL LICENCE BLOCK *****
-
-# <pep8 compliant>
-
-import sys
-import os
-
-if len(sys.argv) < 2:
-    sys.stdout.write("Usage: clkernelstoh <cl_file>\n")
-    sys.exit(1)
-
-filename = sys.argv[1]
-
-try:
-    fpin = open(filename, "r")
-except:
-    sys.stdout.write("Unable to open input %s\n" % sys.argv[1])
-    sys.exit(1)
-
-if filename[0:2] == "." + os.sep:
-    filename = filename[2:]
-
-cname = filename + ".h"
-sys.stdout.write("Making H file <%s>\n" % cname)
-
-filename = filename.split("/")[-1].split("\\")[-1]
-filename = filename.replace(".", "_")
-
-try:
-    fpout = open(cname, "w")
-except:
-    sys.stdout.write("Unable to open output %s\n" % cname)
-    sys.exit(1)
-
-fpout.write("/* clkernelstoh output of file <%s> */\n\n" % filename)
-fpout.write("const char * clkernelstoh_%s = " % filename)
-
-lines = fpin.readlines()
-for line in lines:
-    fpout.write("\"")
-    fpout.write(line.rstrip())
-    fpout.write("\\n\" \\\n")
-fpout.write("\"\\0\";\n")
-
-fpin.close()
-fpout.close()

Modified: trunk/blender/source/blender/compositor/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/compositor/CMakeLists.txt	2012-08-09 18:12:58 UTC (rev 49742)
+++ trunk/blender/source/blender/compositor/CMakeLists.txt	2012-08-09 19:59:36 UTC (rev 49743)
@@ -50,6 +50,21 @@
 
 )
 
+# --- data file ---
+# ... may make this a macro
+list(APPEND INC
+	${CMAKE_CURRENT_BINARY_DIR}/operations
+)
+add_custom_command(
+	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h
+	COMMAND ${CMAKE_COMMAND}
+	        -DFILE_FROM=${CMAKE_CURRENT_SOURCE_DIR}/operations/COM_OpenCLKernels.cl
+	        -DFILE_TO=${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h
+	        -DVAR_NAME=clkernelstoh_COM_OpenCLKernels_cl
+	        -P ${CMAKE_SOURCE_DIR}/build_files/cmake/data_to_c.cmake
+	DEPENDS operations/COM_OpenCLKernels.cl)
+# --- end data file --
+
 set(SRC
 	COM_compositor.h
 	COM_defines.h
@@ -638,6 +653,9 @@
 
 	operations/COM_MaskOperation.cpp
 	operations/COM_MaskOperation.h
+
+	# generated file
+	${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h
 )
 
 blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}")

Modified: trunk/blender/source/blender/compositor/SConscript
===================================================================
--- trunk/blender/source/blender/compositor/SConscript	2012-08-09 18:12:58 UTC (rev 49742)
+++ trunk/blender/source/blender/compositor/SConscript	2012-08-09 19:59:36 UTC (rev 49743)
@@ -11,4 +11,7 @@
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
     incs += ' ' + env['BF_PTHREADS_INC']
 
+# data files
+incs += ' ' + env['DATA_HEADERS']
+
 env.BlenderLib ( 'bf_composite', sources, Split(incs), defines=defs, libtype=['core'], priority = [164] )

Modified: trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp	2012-08-09 18:12:58 UTC (rev 49742)
+++ trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp	2012-08-09 19:59:36 UTC (rev 49743)
@@ -288,7 +288,8 @@
 
 				g_context = clCreateContext(NULL, numberOfDevices, cldevices, clContextError, NULL, &error);
 				if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));  }
-				g_program = clCreateProgramWithSource(g_context, 1, &clkernelstoh_COM_OpenCLKernels_cl, 0, &error);
+				const char *cl_str[2] = {clkernelstoh_COM_OpenCLKernels_cl, NULL};
+				g_program = clCreateProgramWithSource(g_context, 1, cl_str, 0, &error);
 				error = clBuildProgram(g_program, numberOfDevices, cldevices, 0, 0, 0);
 				if (error != CL_SUCCESS) { 
 					cl_int error2;

Deleted: trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h	2012-08-09 18:12:58 UTC (rev 49742)
+++ trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h	2012-08-09 19:59:36 UTC (rev 49743)
@@ -1,250 +0,0 @@
-/* clkernelstoh output of file <COM_OpenCLKernels_cl> */
-
-const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \
-" * Copyright 2011, Blender Foundation.\n" \
-" *\n" \
-" * This program is free software; you can redistribute it and/or\n" \
-" * modify it under the terms of the GNU General Public License\n" \
-" * as published by the Free Software Foundation; either version 2\n" \
-" * of the License, or (at your option) any later version.\n" \
-" *\n" \
-" * This program is distributed in the hope that it will be useful,\n" \
-" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
-" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" \
-" * GNU General Public License for more details.\n" \
-" *\n" \
-" * You should have received a copy of the GNU General Public License\n" \
-" * along with this program; if not, write to the Free Software Foundation,\n" \
-" * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" \
-" *\n" \
-" * Contributor:\n" \
-" *		Jeroen Bakker\n" \
-" *		Monique Dewanchand\n" \
-" */\n" \
-"\n" \
-"/// This file contains all opencl kernels for node-operation implementations\n" \
-"\n" \
-"// Global SAMPLERS\n" \
-"const sampler_t SAMPLER_NEAREST       = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;\n" \
-"const sampler_t SAMPLER_NEAREST_CLAMP = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n" \
-"\n" \
-"__constant const int2 zero = {0,0};\n" \
-"\n" \
-"// KERNEL --- BOKEH BLUR ---\n" \
-"__kernel void bokehBlurKernel(__read_only image2d_t boundingBox, __read_only image2d_t inputImage,\n" \
-"                              __read_only image2d_t bokehImage, __write_only image2d_t output,\n" \
-"                              int2 offsetInput, int2 offsetOutput, int radius, int step, int2 dimension, int2 offset)\n" \
-"{\n" \
-"	int2 coords = {get_global_id(0), get_global_id(1)};\n" \
-"	coords += offset;\n" \
-"	float tempBoundingBox;\n" \
-"	float4 color = {0.0f,0.0f,0.0f,0.0f};\n" \
-"	float4 multiplyer = {0.0f,0.0f,0.0f,0.0f};\n" \
-"	float4 bokeh;\n" \

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list