Moving the call to GPU_code_generate_glsl_lib() to the end of GPU_extensions_init() solves the problem, and (in my opinion) cleans things up a little. However, I'd like your feedback before committing.
--Mitchell Stokes On Fri, Dec 16, 2011 at 6:33 PM, Mitchell Stokes <moguri...@gmail.com> wrote: > GPU_code_generate_glsl_lib() is not called for the Blenderplayer. Is > there any problem to moving this function into GPU_extensions_init()? > It seems like it would encapsulate initialization a bit more. > > --Mitchell Stokes > > On Fri, Dec 16, 2011 at 6:20 PM, Mitchell Stokes <moguri...@gmail.com> wrote: >> This commit causes the Blenderplayer to crash on startup. Here is the >> call stack: >> >>> blenderplayer.exe!strstr(const char * str1=0x0000000000000000, const >>> char * str2=0x00000001411649b8) Line 45 + 0x4 bytes C >> blenderplayer.exe!gpu_parse_functions_string(GHash * >> hash=0x0000000002de2e98, unsigned char * code=0x0000000000000000) >> Line 129 + 0x11 bytes C >> blenderplayer.exe!GPU_lookup_function(const unsigned char * >> name=0x0000000141165ca0) Line 241 C >> blenderplayer.exe!GPU_link(GPUMaterial * mat=0x0000000002de2668, >> const unsigned char * name=0x0000000141165ca0, ...) Line 1161 + 0xa >> bytes C >> blenderplayer.exe!GPU_shadeinput_set(GPUMaterial * >> mat=0x0000000002de2668, Material * ma=0x0000000002e70508, >> GPUShadeInput * shi=0x00000000002dc330) Line 1300 C >> blenderplayer.exe!GPU_blender_material(GPUMaterial * >> mat=0x0000000002de2668, Material * ma=0x0000000002e70508) Line 1424 C >> blenderplayer.exe!GPU_material_from_blender(Scene * >> scene=0x0000000002e5d598, Material * ma=0x0000000002e70508) Line 1449 >> + 0xf bytes C >> blenderplayer.exe!BL_BlenderShader::ReloadMaterial() Line 44 + 0x23 >> bytes C++ >> blenderplayer.exe!BL_BlenderShader::BL_BlenderShader(KX_Scene * >> scene=0x0000000002d2a8e0, Material * ma=0x0000000002e70508, int >> lightlayer=1) Line 34 C++ >> blenderplayer.exe!KX_BlenderMaterial::SetBlenderGLSLShader(int >> layer=1) Line 784 + 0x45 bytes C++ >> blenderplayer.exe!KX_BlenderMaterial::OnConstruction(int layer=1) >> Line 169 C++ >> blenderplayer.exe!BL_ConvertMesh(Mesh * mesh=0x0000000002e7beb8, >> Object * blenderobj=0x0000000002e61d28, KX_Scene * >> scene=0x0000000002d2a8e0, KX_BlenderSceneConverter * >> converter=0x0000000002d29040) Line 1083 + 0x38 bytes C++ >> blenderplayer.exe!gameobject_from_blenderobject(Object * >> ob=0x0000000002e61d28, KX_Scene * kxscene=0x0000000002d2a8e0, >> RAS_IRenderTools * rendertools=0x0000000002d1d1d0, >> KX_BlenderSceneConverter * converter=0x0000000002d29040) Line 1774 + >> 0x22 bytes C++ >> blenderplayer.exe!BL_ConvertBlenderObjects(Main * >> maggie=0x0000000002e156f8, KX_Scene * kxscene=0x0000000002d2a8e0, >> KX_KetsjiEngine * ketsjiEngine=0x0000000002d272a0, e_PhysicsEngine >> physics_engine=UseBullet, RAS_IRenderTools * >> rendertools=0x0000000002d1d1d0, RAS_ICanvas * >> canvas=0x0000000002d192e0, KX_BlenderSceneConverter * >> converter=0x0000000002d29040, bool alwaysUseExpandFraming=false) Line >> 2083 + 0x29 bytes C++ >> blenderplayer.exe!KX_BlenderSceneConverter::ConvertScene(KX_Scene * >> destinationscene=0x0000000002d2a8e0, RAS_IRenderTools * >> rendertools=0x0000000002d1d1d0, RAS_ICanvas * >> canvas=0x0000000002d192e0) Line 378 C++ >> blenderplayer.exe!GPG_Application::startEngine() Line 729 C++ >> blenderplayer.exe!GPG_Application::startWindow(STR_String & >> title={...}, int windowLeft=100, int windowTop=100, int >> windowWidth=640, int windowHeight=480, const bool stereoVisual=false, >> const int stereoMode=1, const unsigned short samples=0) Line 338 + >> 0xd bytes C++ >> blenderplayer.exe!main(int argc=2, char * * argv=0x00000000003e3240) >> Line 945 + 0x59 bytes C++ >> blenderplayer.exe!__tmainCRTStartup() Line 278 + 0x19 bytes C >> blenderplayer.exe!mainCRTStartup() Line 189 C >> >> --Mitchell Stokes >> >> On Thu, Dec 15, 2011 at 5:58 AM, Antony Riakiotakis <kal...@gmail.com> wrote: >>> Revision: 42647 >>> >>> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42647 >>> Author: psy-fi >>> Date: 2011-12-15 13:58:09 +0000 (Thu, 15 Dec 2011) >>> Log Message: >>> ----------- >>> Bicubic bump map filtering. >>> >>> This commit introduces bicubic bump map capabilities for the viewport for >>> OpenGL 3.0+ capable GPUs. >>> >>> To use the functionality change the bump mapping method to "best quality" >>> Previous "best quality" setting becomes "medium quality" now. >>> For non OpenGL 3.0 GPUs this becomes the same as "medium quality" >>> >>> Also: >>> * added tooltip descriptions to the bump method settings. >>> * modified the shader to ommit extraneous matrix multiplications for >>> matrices already provided by OpenGL. >>> >>> Bicubic shader by Morten Mikkelsen. Thanks a lot! >>> >>> Oh...and FIRST! >>> >>> Modified Paths: >>> -------------- >>> trunk/blender/release/scripts/startup/bl_ui/properties_texture.py >>> trunk/blender/source/blender/blenkernel/intern/material.c >>> trunk/blender/source/blender/gpu/GPU_extensions.h >>> trunk/blender/source/blender/gpu/intern/gpu_codegen.c >>> trunk/blender/source/blender/gpu/intern/gpu_material.c >>> trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl >>> trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl.c >>> trunk/blender/source/blender/makesdna/DNA_texture_types.h >>> trunk/blender/source/blender/makesrna/intern/rna_material.c >>> trunk/blender/source/blender/render/intern/source/render_texture.c >>> trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c >>> >>> Modified: trunk/blender/release/scripts/startup/bl_ui/properties_texture.py >>> =================================================================== >>> --- trunk/blender/release/scripts/startup/bl_ui/properties_texture.py >>> 2011-12-15 13:41:29 UTC (rev 42646) >>> +++ trunk/blender/release/scripts/startup/bl_ui/properties_texture.py >>> 2011-12-15 13:58:09 UTC (rev 42647) >>> @@ -1056,7 +1056,7 @@ >>> >>> # the space setting is supported for: derivative-maps + >>> bump-maps (DEFAULT,BEST_QUALITY), not for normal-maps >>> sub = row.row() >>> - sub.active = (tex.use_map_normal or tex.use_map_warp) and not >>> (tex.texture.type == 'IMAGE' and tex.texture.use_normal_map) and >>> ((tex.bump_method in {'BUMP_DEFAULT', 'BUMP_BEST_QUALITY'}) or >>> (tex.texture.type == 'IMAGE' and tex.texture.use_derivative_map)) >>> + sub.active = (tex.use_map_normal or tex.use_map_warp) and not >>> (tex.texture.type == 'IMAGE' and tex.texture.use_normal_map) and >>> ((tex.bump_method in {'BUMP_LOW_QUALITY', 'BUMP_MEDIUM_QUALITY', >>> 'BUMP_BEST_QUALITY'}) or (tex.texture.type == 'IMAGE' and >>> tex.texture.use_derivative_map)) >>> sub.prop(tex, "bump_objectspace", text="Space") >>> >>> >>> >>> Modified: trunk/blender/source/blender/blenkernel/intern/material.c >>> =================================================================== >>> --- trunk/blender/source/blender/blenkernel/intern/material.c 2011-12-15 >>> 13:41:29 UTC (rev 42646) >>> +++ trunk/blender/source/blender/blenkernel/intern/material.c 2011-12-15 >>> 13:58:09 UTC (rev 42647) >>> @@ -903,7 +903,7 @@ >>> >>> /* always get derivatives for these textures */ >>> if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, >>> TEX_ENVMAP) ma->texco |= TEXCO_OSA; >>> - else if(mtex->texflag & >>> (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) ma->texco |= TEXCO_OSA; >>> + else if(mtex->texflag & >>> (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) >>> ma->texco |= TEXCO_OSA; >>> >>> if(ma->texco & >>> (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1; >>> else if(ma->texco & >>> (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1; >>> >>> Modified: trunk/blender/source/blender/gpu/GPU_extensions.h >>> =================================================================== >>> --- trunk/blender/source/blender/gpu/GPU_extensions.h 2011-12-15 13:41:29 >>> UTC (rev 42646) >>> +++ trunk/blender/source/blender/gpu/GPU_extensions.h 2011-12-15 13:58:09 >>> UTC (rev 42647) >>> @@ -61,6 +61,8 @@ >>> int GPU_glsl_support(void); >>> int GPU_non_power_of_two_support(void); >>> int GPU_color_depth(void); >>> +void GPU_code_generate_glsl_lib(void); >>> +int GPU_bicubic_bump_support(void); >>> >>> /* GPU Types */ >>> >>> >>> Modified: trunk/blender/source/blender/gpu/intern/gpu_codegen.c >>> =================================================================== >>> --- trunk/blender/source/blender/gpu/intern/gpu_codegen.c 2011-12-15 >>> 13:41:29 UTC (rev 42646) >>> +++ trunk/blender/source/blender/gpu/intern/gpu_codegen.c 2011-12-15 >>> 13:58:09 UTC (rev 42647) >>> @@ -59,6 +59,10 @@ >>> extern char datatoc_gpu_shader_material_glsl[]; >>> extern char datatoc_gpu_shader_vertex_glsl[]; >>> >>> + >>> +static char *glsl_material_library = NULL; >>> + >>> + >>> /* structs and defines */ >>> >>> static const char* GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", >>> "vec4", >>> @@ -229,7 +233,7 @@ >>> { >>> if(!FUNCTION_HASH) { >>> FUNCTION_HASH = BLI_ghash_new(BLI_ghashutil_strhash, >>> BLI_ghashutil_strcmp, "GPU_lookup_function gh"); >>> - gpu_parse_functions_string(FUNCTION_HASH, >>> datatoc_gpu_shader_material_glsl); >>> + gpu_parse_functions_string(FUNCTION_HASH, >>> glsl_material_library); >>> /*FUNCTION_PROTOTYPES = >>> gpu_generate_function_prototyps(FUNCTION_HASH); >>> FUNCTION_LIB = >>> GPU_shader_create_lib(datatoc_gpu_shader_material_glsl);*/ >>> } >>> @@ -248,6 +252,9 @@ >>> BLI_ghash_free(FUNCTION_HASH, NULL, >>> (GHashValFreeFP)MEM_freeN); >>> FUNCTION_HASH = NULL; >>> } >>> + >>> + if(glsl_material_library) >>> + MEM_freeN(glsl_material_library); >>> /*if(FUNCTION_PROTOTYPES) { >>> MEM_freeN(FUNCTION_PROTOTYPES); >>> FUNCTION_PROTOTYPES = NULL; >>> @@ -640,6 +647,35 @@ >>> return code; >>> } >>> >>> +int GPU_bicubic_bump_support(void){ >>> + return GLEW_ARB_texture_gather && GLEW_ARB_texture_query_lod && >>> GLEW_VERSION_3_0; >>> +} >>> + >>> +void GPU_code_generate_glsl_lib(void){ >>> + DynStr *ds; >>> + >>> + /* only initialize the library once */ >>> + if(glsl_material_library) >>> + return; >>> + >>> + ds = BLI_dynstr_new(); >>> + >>> + if(GPU_bicubic_bump_support()){ >>> + BLI_dynstr_append(ds, "/* These are needed for high quality >>> bump mapping */\n" >>> + "#version 130\n" >>> + "#extension GL_ARB_texture_gather: enable\n" >>> + "#extension GL_ARB_texture_query_lod: >>> enable\n" >>> + "#define BUMP_BICUBIC\n"); >>> + } >>> + BLI_dynstr_append(ds, datatoc_gpu_shader_material_glsl); >>> + >>> + >>> + glsl_material_library = BLI_dynstr_get_cstring(ds); >>> + >>> + BLI_dynstr_free(ds); >>> +} >>> + >>> + >>> /* GPU pass binding/unbinding */ >>> >>> GPUShader *GPU_pass_shader(GPUPass *pass) >>> @@ -1318,7 +1354,7 @@ >>> /* generate code and compile with opengl */ >>> fragmentcode = code_generate_fragment(nodes, outlink->output, name); >>> vertexcode = code_generate_vertex(nodes); >>> - shader = GPU_shader_create(vertexcode, fragmentcode, >>> datatoc_gpu_shader_material_glsl); /*FUNCTION_LIB);*/ >>> + shader = GPU_shader_create(vertexcode, fragmentcode, >>> glsl_material_library); /*FUNCTION_LIB);*/ >>> >>> /* failed? */ >>> if (!shader) { >>> @@ -1335,7 +1371,7 @@ >>> pass->shader = shader; >>> pass->fragmentcode = fragmentcode; >>> pass->vertexcode = vertexcode; >>> - pass->libcode = datatoc_gpu_shader_material_glsl; >>> + pass->libcode = glsl_material_library; >>> >>> /* extract dynamic inputs and throw away nodes */ >>> GPU_nodes_extract_dynamic_inputs(pass, nodes); >>> >>> Modified: trunk/blender/source/blender/gpu/intern/gpu_material.c >>> =================================================================== >>> --- trunk/blender/source/blender/gpu/intern/gpu_material.c 2011-12-15 >>> 13:41:29 UTC (rev 42646) >>> +++ trunk/blender/source/blender/gpu/intern/gpu_material.c 2011-12-15 >>> 13:58:09 UTC (rev 42647) >>> @@ -1086,7 +1086,7 @@ >>> GPU_link(mat, >>> "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn); >>> } >>> >>> - } else if( (mtex->texflag & >>> (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) || found_deriv_map) { >>> + } else if( (mtex->texflag & >>> (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP)) || found_deriv_map) { >>> /* ntap bumpmap image */ >>> int iBumpSpace; >>> float ima_x, ima_y; >>> @@ -1184,10 +1184,21 @@ >>> GPU_link( mat, >>> "mtex_bump_tap3", >>> texco, >>> GPU_image(tex->ima, &tex->iuser), tnorfac, >>> &dBs, &dBt >>> ); >>> - else >>> - GPU_link( mat, >>> "mtex_bump_tap5", >>> + else if( mtex->texflag & >>> MTEX_5TAP_BUMP ) >>> + GPU_link( mat, >>> "mtex_bump_tap5", >>> texco, >>> GPU_image(tex->ima, &tex->iuser), tnorfac, >>> &dBs, &dBt >>> ); >>> + else if( mtex->texflag & >>> MTEX_BICUBIC_BUMP ){ >>> + >>> if(GPU_bicubic_bump_support()){ >>> + GPU_link( >>> mat, "mtex_bump_bicubic", >>> + >>> texco, GPU_image(tex->ima, &tex->iuser), tnorfac, >>> + >>> &dBs, &dBt ); >>> + }else{ >>> + GPU_link( >>> mat, "mtex_bump_tap5", >>> + >>> texco, GPU_image(tex->ima, &tex->iuser), tnorfac, >>> + >>> &dBs, &dBt ); >>> + } >>> + } >>> >>> >>> if( mtex->texflag & >>> MTEX_BUMP_TEXTURESPACE ) { >>> >>> Modified: trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl >>> =================================================================== >>> --- trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl >>> 2011-12-15 13:41:29 UTC (rev 42646) >>> +++ trunk/blender/source/blender/gpu/intern/gpu_shader_material.glsl >>> 2011-12-15 13:58:09 UTC (rev 42647) >>> @@ -1152,8 +1152,8 @@ >>> out float >>> fPrevMagnitude_out, out vec3 vNacc_out, >>> out vec3 vR1, out >>> vec3 vR2, out float fDet ) >>> { >>> - mat3 obj2view = to_mat3(mView * mObj); >>> - mat3 view2obj = to_mat3(mObjInv * mViewInv); >>> + mat3 obj2view = to_mat3(gl_ModelViewMatrix); >>> + mat3 view2obj = to_mat3(gl_ModelViewMatrixInverse); >>> >>> vec3 vSigmaS = view2obj * dFdx( surf_pos ); >>> vec3 vSigmaT = view2obj * dFdy( surf_pos ); >>> @@ -1225,6 +1225,84 @@ >>> dBt = hScale * (Hul - Hll); >>> } >>> >>> +#ifdef BUMP_BICUBIC >>> + >>> +void mtex_bump_bicubic( vec3 texco, sampler2D ima, float hScale, >>> + out float dBs, out float dBt ) >>> +{ >>> + vec2 TexDx = dFdx(texco.xy); >>> + vec2 TexDy = dFdy(texco.xy); >>> + >>> + vec2 STl = texco.xy - 0.5 * TexDx ; >>> + vec2 STr = texco.xy + 0.5 * TexDx ; >>> + vec2 STd = texco.xy - 0.5 * TexDy ; >>> + vec2 STu = texco.xy + 0.5 * TexDy ; >>> + >>> + float Hl = texture2D(ima, STl).x; >>> + float Hr = texture2D(ima, STr).x; >>> + float Hd = texture2D(ima, STd).x; >>> + float Hu = texture2D(ima, STu).x; >>> + >>> + vec2 dHdxy = vec2(Hr - Hl, Hu - Hd); >>> + float fBlend = clamp(1.0-textureQueryLOD(ima, texco.xy).x, 0.0, >>> 1.0); >>> + if(fBlend!=0.0) >>> + { >>> + // the derivative of the bicubic sampling of level 0 >>> + ivec2 vDim; >>> + vDim = textureSize(ima, 0); >>> + >>> + vec2 fTexLoc = vDim*texco.xy-vec2(0.5,0.5); >>> + ivec2 iTexLoc = ivec2(floor(fTexLoc)); >>> + vec2 t = clamp(fTexLoc - iTexLoc, 0.0, 1.0); // >>> sat just to be pedantic >>> + >>> + ivec2 iTexLocMod = iTexLoc + ivec2(-1, -1); >>> + >>> +/******************************************************************************************* >>> + * This block will replace the one below when one channel textures are >>> properly supported. * >>> + >>> ******************************************************************************************* >>> + vec4 vSamplesUL = textureGather(ima, (iTexLoc+ivec2(-1,-1) >>> + vec2(0.5,0.5))/vDim ); >>> + vec4 vSamplesUR = textureGather(ima, (iTexLoc+ivec2(1,-1) + >>> vec2(0.5,0.5))/vDim ); >>> + vec4 vSamplesLL = textureGather(ima, (iTexLoc+ivec2(-1,1) + >>> vec2(0.5,0.5))/vDim ); >>> + vec4 vSamplesLR = textureGather(ima, (iTexLoc+ivec2(1,1) + >>> vec2(0.5,0.5))/vDim ); >>> + >>> + mat4 H = mat4(vSamplesUL.w, vSamplesUL.x, vSamplesLL.w, >>> vSamplesLL.x, >>> + vSamplesUL.z, vSamplesUL.y, >>> vSamplesLL.z, vSamplesLL.y, >>> + vSamplesUR.w, vSamplesUR.x, >>> vSamplesLR.w, vSamplesLR.x, >>> + vSamplesUR.z, vSamplesUR.y, >>> vSamplesLR.z, vSamplesLR.y); >>> +*/ >>> + mat4 H; >>> + >>> + for(int i = 0; i < 4; i++){ >>> + for(int j = 0; j < 4; j++){ >>> + mtex_rgbtoint(texelFetch(ima, (iTexLocMod + >>> ivec2(i,j)), 0), H[i][j]); >>> + } >>> + } >>> + >>> + float x = t.x, y = t.y; >>> + float x2 = x * x, x3 = x2 * x, y2 = y * y, y3 = y2 * y; >>> + >>> + vec4 X = vec4(-0.5*(x3+x)+x2, 1.5*x3-2.5*x2+1, >>> -1.5*x3+2*x2+0.5*x, 0.5*(x3-x2)); >>> + vec4 Y = vec4(-0.5*(y3+y)+y2, 1.5*y3-2.5*y2+1, >>> -1.5*y3+2*y2+0.5*y, 0.5*(y3-y2)); >>> + vec4 dX = vec4(-1.5*x2+2*x-0.5, 4.5*x2-5*x, >>> -4.5*x2+4*x+0.5, 1.5*x2-x); >>> + vec4 dY = vec4(-1.5*y2+2*y-0.5, 4.5*y2-5*y, >>> -4.5*y2+4*y+0.5, 1.5*y2-y); >>> + >>> + // complete derivative in normalized coordinates (mul by >>> vDim) >>> >>> @@ Diff output truncated at 10240 characters. @@ >>> _______________________________________________ >>> Bf-blender-cvs mailing list >>> bf-blender-...@blender.org >>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs _______________________________________________ Bf-committers mailing list Bf-committers@blender.org http://lists.blender.org/mailman/listinfo/bf-committers