2.2 Clone datablock crash

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

2.2 Clone datablock crash

Post by Lax » Mon Jun 10, 2019 8:13 pm

Hi,

I'm testing Ogre 2.2 and encountered a bug in Ogre.
As soon as a datablock gets cloned, in renderOneFrame later, the application does crash in:
ID3D11PixelShader* D3D11HLSLProgram::getPixelShader(void) const
{
assert(mType == GPT_FRAGMENT_PROGRAM);
assert(mPixelShader);
return mPixelShader;
}
Because the mPixelShader is 0. It does not matter which datablock is cloned.

Log:

Code: Select all

OGRE EXCEPTION(-2147467259:RenderingAPIException): Cannot compile D3D11 high-level shader 100000004PixelShader_ps Errors:
H:\GameEngineDevelopment2_2\bin\Debug\100000004PixelShader_ps.hlsl(715,35-62): error X4000: variable 'pixelData' used without having been completely initialized
 in D3D11HLSLProgram::compileMicrocode at h:\gameenginedevelopment2_2\external\ogre2.2sdk\rendersystems\direct3d11\src\ogred3d11hlslprogram.cpp (line 558)
Debug Pixelshader:

Code: Select all

#if 0
	***	first_valid_detail_map_nm	0
	***	hlms_dual_paraboloid_mapping	0
	***	envprobe_map_sampler	1
	***	hlms_lights_spotparams	0
	***	envMapRegSampler	1
	***	emissive_map_sampler	1
	***	hlms_disable_stage	0
	***	hlms_lights_area_approx	0
	***	specular_map_sampler	1
	***	texcoord	0
	***	fast_shader_build_hack	1
	***	glsl	635204550
	***	hlms_high_quality	0
	***	hlms_num_shadow_map_lights	0
	***	hlms_lights_directional	0
	***	hlms_shadowcaster	1
	***	samplerStateStart	1
	***	alpha_test	0
	***	roughness_map_sampler	1
	***	glsles	1070293233
	***	hw_gamma_write	1
	***	detail_map_nm2_sampler	1
	***	hlms_shadowcaster_directional	1
	***	hlms_pssm_splits	0
	***	hlms_lights_spot	0
	***	detail_map1_sampler	1
	***	detail_map_nm3_sampler	1
	***	hlms_alphablend	1
	***	hlms_num_shadow_map_textures	0
	***	hlms_shadow_uses_depth_texture	1
	***	detail_map3_sampler	1
	***	materials_per_buffer	2
	***	hw_gamma_read	1
	***	hlms_skeleton	0
	***	hlms_pssm_splits_minus_one	-1
	***	forward3d	0
	***	partial_pso_clip_distances	0
	***	syntax	-334286542
	***	NeedsMoreThan1BonePerVertex	-1
	***	hlms_lights_point	0
	***	diffuse_map_sampler	1
	***	metal	-1698855755
	***	detail_map_nm1_sampler	1
	***	s_lights_directional_non_caster	0
	***	uv_diffuse	0
	***	detail_weight_map_sampler	1
	***	hlms_lights_attenuation	0
	***	detail_map_nm0_sampler	1
	***	hlms_render_depth_only	1
	***	normal_map_tex_sampler	1
	***	detail_map2_sampler	1
	***	full_pso_clip_distances	0
	***	detail_map0_sampler	1
	***	use_planar_reflections	0
	***	hlsl	-334286542
	DONE DUMPING PROPERTIES
	DONE DUMPING PIECES
#endif

//#include "SyntaxHighlightingMisc.h"


#define ushort uint
#define ogre_float4x3 float4x3

//Short used for read operations. It's an int in GLSL & HLSL. An ushort in Metal
#define rshort2 int2
//Short used for write operations. It's an int in GLSL. An ushort in HLSL & Metal
#define wshort2 uint2

#define toFloat3x3( x ) ((float3x3)(x))
#define buildFloat3x3( row0, row1, row2 ) transpose( float3x3( row0, row1, row2 ) )

#define min3( a, b, c ) min( a, min( b, c ) )
#define max3( a, b, c ) max( a, max( b, c ) )

#define INLINE
#define NO_INTERPOLATION_PREFIX nointerpolation
#define NO_INTERPOLATION_SUFFIX

#define finalDrawId input.drawId
#define PARAMS_ARG_DECL
#define PARAMS_ARG

#define floatBitsToUint(x) asuint(x)
#define uintBitsToFloat(x) asfloat(x)
#define floatBitsToInt(x) asint(x)
#define fract frac
#define lessThan( a, b ) (a < b)

#define inVs_vertexId input.vertexId
#define inVs_vertex input.vertex
#define inVs_blendWeights input.blendWeights
#define inVs_blendIndices input.blendIndices
#define inVs_qtangent input.qtangent
#define inVs_drawId input.drawId

#define outVs_Position outVs.gl_Position
#define outVs_clipDistance0 outVs.gl_ClipDistance0

#define gl_SampleMaskIn0 gl_SampleMask
#define interpolateAtSample( interp, subsample ) EvaluateAttributeAtSample( interp, subsample )
#define findLSB firstbitlow

#define outPs_colour0 outPs.colour0
#define OGRE_Sample( tex, sampler, uv ) tex.Sample( sampler, uv )
#define OGRE_SampleLevel( tex, sampler, uv, lod ) tex.SampleLevel( sampler, uv, lod )
#define OGRE_SampleArray2D( tex, sampler, uv, arrayIdx ) tex.Sample( sampler, float3( uv, arrayIdx ) )
#define OGRE_SampleArray2DLevel( tex, sampler, uv, arrayIdx, lod ) tex.SampleLevel( sampler, float3( uv, arrayIdx ), lod )
#define OGRE_SampleArrayCubeLevel( tex, sampler, uv, arrayIdx, lod ) tex.SampleLevel( sampler, float4( uv, arrayIdx ), lod )
#define OGRE_SampleGrad( tex, sampler, uv, ddx, ddy ) tex.SampleGrad( sampler, uv, ddx, ddy )
#define OGRE_SampleArray2DGrad( tex, sampler, uv, arrayIdx, ddx, ddy ) tex.SampleGrad( sampler, float3( uv, arrayIdx ), ddx, ddy )
#define OGRE_ddx( val ) ddx( val )
#define OGRE_ddy( val ) ddy( val )
#define OGRE_Load2D( tex, iuv, lod ) tex.Load( int3( iuv, lod ) )
#define OGRE_Load2DMS( tex, iuv, subsample ) tex.Load( iuv, subsample )

#define bufferFetch( buffer, idx ) buffer.Load( idx )
#define bufferFetch1( buffer, idx ) buffer.Load( idx ).x

#define CONST_BUFFER( bufferName, bindingPoint ) cbuffer bufferName : register(b##bindingPoint)
#define CONST_BUFFER_STRUCT_BEGIN( structName, bindingPoint ) cbuffer structName : register(b##bindingPoint) { struct _##structName
#define CONST_BUFFER_STRUCT_END( variableName ) variableName; }

#define FLAT_INTERPOLANT( decl, bindingPoint ) nointerpolation decl : TEXCOORD##bindingPoint
#define INTERPOLANT( decl, bindingPoint ) decl : TEXCOORD##bindingPoint


	#define UV_DIFFUSE(x) (x)
	#define UV_NORMAL(x) (x)
	#define UV_SPECULAR(x) (x)
	#define UV_ROUGHNESS(x) (x)
	#define UV_DETAIL_WEIGHT(x) (x)
	#define UV_DETAIL0(x) (x)
	#define UV_DETAIL1(x) (x)
	#define UV_DETAIL2(x) (x)
	#define UV_DETAIL3(x) (x)
	#define UV_DETAIL_NM0(x) (x)
	#define UV_DETAIL_NM1(x) (x)
	#define UV_DETAIL_NM2(x) (x)
	#define UV_DETAIL_NM3(x) (x)
	#define UV_EMISSIVE(x) (x)
	



	
		#define float_fresnel float
		#define make_float_fresnel( x ) x
	

	
			#define OGRE_DEPTH_CMP_GE( a, b ) (a) <= (b)
		#define OGRE_DEPTH_DEFAULT_CLEAR 0.0
	

	struct PixelData
	{
		
			float4 diffuse; //We only use the .w component, Alpha
		
	};

	#define SampleDetailWeightMap( tex, sampler, uv, arrayIdx ) OGRE_SampleArray2D( tex, sampler, uv, arrayIdx )
	
	
	
	
	
	

	

	

	

	


// START UNIFORM DECLARATION


// END UNIFORM DECLARATION
struct PS_INPUT
{

									

};

///!hlms_shadowcaster


	
	
		#define outDepth outPs.colour0
	







	struct PS_OUTPUT
	{
		
			
			
				float colour0 : SV_Depth;
			
		
	};


void main( PS_INPUT inPs )
{


	
	
	
	
		

	


}
Debug VertexShader:

Code: Select all

#if 0
	***	first_valid_detail_map_nm	0
	***	hlms_dual_paraboloid_mapping	0
	***	hlms_lights_spotparams	0
	***	hlms_lights_area_approx	0
	***	fast_shader_build_hack	1
	***	glsl	635204550
	***	hlms_high_quality	0
	***	hlms_num_shadow_map_lights	0
	***	hlms_lights_directional	0
	***	hlms_shadowcaster	1
	***	samplerStateStart	1
	***	alpha_test	0
	***	glsles	1070293233
	***	hw_gamma_write	1
	***	hlms_shadowcaster_directional	1
	***	hlms_pssm_splits	0
	***	hlms_lights_spot	0
	***	hlms_alphablend	1
	***	hlms_num_shadow_map_textures	0
	***	hlms_shadow_uses_depth_texture	1
	***	materials_per_buffer	2
	***	hw_gamma_read	1
	***	hlms_skeleton	0
	***	forward3d	0
	***	syntax	-334286542
	***	hlms_lights_point	0
	***	metal	-1698855755
	***	s_lights_directional_non_caster	0
	***	uv_diffuse	0
	***	hlms_lights_attenuation	0
	***	hlms_render_depth_only	1
	***	use_planar_reflections	0
	***	hlsl	-334286542
	DONE DUMPING PROPERTIES
	DONE DUMPING PIECES
#endif

//#include "SyntaxHighlightingMisc.h"


#define ushort uint
#define ogre_float4x3 float4x3

//Short used for read operations. It's an int in GLSL & HLSL. An ushort in Metal
#define rshort2 int2
//Short used for write operations. It's an int in GLSL. An ushort in HLSL & Metal
#define wshort2 uint2

#define toFloat3x3( x ) ((float3x3)(x))
#define buildFloat3x3( row0, row1, row2 ) transpose( float3x3( row0, row1, row2 ) )

#define min3( a, b, c ) min( a, min( b, c ) )
#define max3( a, b, c ) max( a, max( b, c ) )

#define INLINE
#define NO_INTERPOLATION_PREFIX nointerpolation
#define NO_INTERPOLATION_SUFFIX

#define finalDrawId input.drawId
#define PARAMS_ARG_DECL
#define PARAMS_ARG

#define floatBitsToUint(x) asuint(x)
#define uintBitsToFloat(x) asfloat(x)
#define floatBitsToInt(x) asint(x)
#define fract frac
#define lessThan( a, b ) (a < b)

#define inVs_vertexId input.vertexId
#define inVs_vertex input.vertex
#define inVs_blendWeights input.blendWeights
#define inVs_blendIndices input.blendIndices
#define inVs_qtangent input.qtangent
#define inVs_drawId input.drawId

#define outVs_Position outVs.gl_Position
#define outVs_clipDistance0 outVs.gl_ClipDistance0

#define gl_SampleMaskIn0 gl_SampleMask
#define interpolateAtSample( interp, subsample ) EvaluateAttributeAtSample( interp, subsample )
#define findLSB firstbitlow

#define outPs_colour0 outPs.colour0
#define OGRE_Sample( tex, sampler, uv ) tex.Sample( sampler, uv )
#define OGRE_SampleLevel( tex, sampler, uv, lod ) tex.SampleLevel( sampler, uv, lod )
#define OGRE_SampleArray2D( tex, sampler, uv, arrayIdx ) tex.Sample( sampler, float3( uv, arrayIdx ) )
#define OGRE_SampleArray2DLevel( tex, sampler, uv, arrayIdx, lod ) tex.SampleLevel( sampler, float3( uv, arrayIdx ), lod )
#define OGRE_SampleArrayCubeLevel( tex, sampler, uv, arrayIdx, lod ) tex.SampleLevel( sampler, float4( uv, arrayIdx ), lod )
#define OGRE_SampleGrad( tex, sampler, uv, ddx, ddy ) tex.SampleGrad( sampler, uv, ddx, ddy )
#define OGRE_SampleArray2DGrad( tex, sampler, uv, arrayIdx, ddx, ddy ) tex.SampleGrad( sampler, float3( uv, arrayIdx ), ddx, ddy )
#define OGRE_ddx( val ) ddx( val )
#define OGRE_ddy( val ) ddy( val )
#define OGRE_Load2D( tex, iuv, lod ) tex.Load( int3( iuv, lod ) )
#define OGRE_Load2DMS( tex, iuv, subsample ) tex.Load( iuv, subsample )

#define bufferFetch( buffer, idx ) buffer.Load( idx )
#define bufferFetch1( buffer, idx ) buffer.Load( idx ).x

#define CONST_BUFFER( bufferName, bindingPoint ) cbuffer bufferName : register(b##bindingPoint)
#define CONST_BUFFER_STRUCT_BEGIN( structName, bindingPoint ) cbuffer structName : register(b##bindingPoint) { struct _##structName
#define CONST_BUFFER_STRUCT_END( variableName ) variableName; }

#define FLAT_INTERPOLANT( decl, bindingPoint ) nointerpolation decl : TEXCOORD##bindingPoint
#define INTERPOLANT( decl, bindingPoint ) decl : TEXCOORD##bindingPoint



	
		#define worldViewMat worldView
	

	
float4x4 UNPACK_MAT4( Buffer<float4> matrixBuf, uint pixelIdx )
{
	float4 row1 = matrixBuf.Load( int((pixelIdx) << 2u) );
	float4 row2 = matrixBuf.Load( int(((pixelIdx) << 2u) + 1u) );
	float4 row3 = matrixBuf.Load( int(((pixelIdx) << 2u) + 2u) );
	float4 row4 = matrixBuf.Load( int(((pixelIdx) << 2u) + 3u) );

	return transpose( float4x4( row1, row2, row3, row4 ) );
}

	
float4x3 UNPACK_MAT4x3( Buffer<float4> matrixBuf, uint pixelIdx )
{
	float4 row1 = matrixBuf.Load( int((pixelIdx) << 2u) );
	float4 row2 = matrixBuf.Load( int(((pixelIdx) << 2u) + 1u) );
	float4 row3 = matrixBuf.Load( int(((pixelIdx) << 2u) + 2u) );

	return transpose( float3x4( row1, row2, row3 ) );
}


	// START UNIFORM DECLARATION
	
struct ShadowReceiverData
{
	float4x4 texViewProj;
	float2 shadowDepthRange;
	float2 padding;
	float4 invShadowMapSize;
};

struct Light
{
			float3 position;
		uint lightMask;
		float4 diffuse;		//.w contains numNonCasterDirectionalLights
	float3 specular;
};

#define numNonCasterDirectionalLights lights[0].diffuse.w

#define areaLightDiffuseMipmapStart areaApproxLights[0].diffuse.w
#define areaLightNumMipmapsSpecFactor areaApproxLights[0].specular.w

#define numAreaApproxLights areaApproxLights[0].doubleSided.y
#define numAreaApproxLightsWithMask areaApproxLights[0].doubleSided.z

#define numAreaLtcLights areaLtcLights[0].points[0].w

struct AreaLight
{
			float3 position;
		uint lightMask;
		float4 diffuse;		//[0].w contains diffuse mipmap start
	float4 specular;	//[0].w contains mipmap scale
	float4 attenuation;	//.w contains texture array idx
	//Custom 2D Shape:
	//  direction.xyz direction
	//  direction.w invHalfRectSize.x
	//  tangent.xyz tangent
	//  tangent.w invHalfRectSize.y
	float4 direction;
	float4 tangent;
	float4 doubleSided;	//.y contains numAreaApproxLights
						//.z contains numAreaApproxLightsWithMask
	};

struct AreaLtcLight
{
			float3 position;
		uint lightMask;
		float4 diffuse;			//.w contains attenuation range
	float4 specular;		//.w contains doubleSided
	float4 points[4];		//.w contains numAreaLtcLights
	};



//Uniforms that change per pass
CONST_BUFFER_STRUCT_BEGIN( PassBuffer, 0 )
{
	//Vertex shader (common to both receiver and casters)
	float4x4 viewProj;




	//Vertex shader
		float2 depthRange;


	


	
}
CONST_BUFFER_STRUCT_END( passBuf );

	
		//Uniforms that change per Item/Entity
		CONST_BUFFER( InstanceBuffer, 2 )
		{
			//.x =
			//The lower 9 bits contain the material's start index.
			//The higher 23 bits contain the world matrix start index.
			//
			//.y =
			//shadowConstantBias. Send the bias directly to avoid an
			//unnecessary indirection during the shadow mapping pass.
			//Must be loaded with uintBitsToFloat
			//
			//.z =
			//lightMask. Ogre must have been compiled with OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
			
				uint4 worldMaterialIdx[2];
					};
	
	
	// END UNIFORM DECLARATION

	



struct VS_INPUT
{
	float4 vertex : POSITION;








	uint drawId : DRAWID;
	
};

struct PS_INPUT
{
	
									

	float4 gl_Position: SV_Position;

	
	
	
	
};

// START UNIFORM D3D DECLARATION
Buffer<float4> worldMatBuf : register(t0);
// END UNIFORM D3D DECLARATION

PS_INPUT main( VS_INPUT input )
{
	PS_INPUT outVs;


	
	
	
		ogre_float4x3 worldMat = UNPACK_MAT4x3( worldMatBuf, inVs_drawId );
		

		float4 worldPos = float4( mul(inVs_vertex, worldMat).xyz, 1.0f );
	

	

	
	
	
	//Lighting is in view space
	
	
	
	
        
			outVs_Position = mul( worldPos, passBuf.viewProj );
		
	


	
	
		float shadowConstantBias = uintBitsToFloat( worldMaterialIdx[inVs_drawId].y );

		
		
		
			//We can't make the depth buffer linear without Z out in the fragment shader;
			//however we can use a cheap approximation ("pseudo linear depth")
			//see http://www.yosoygames.com.ar/wp/2014/01/linear-depth-buffer-my-ass/
			
				outVs_Position.z = outVs_Position.z + shadowConstantBias * passBuf.depthRange.y * passBuf.depthRange.y;
					
			

	/// hlms_uv_count will be 0 on shadow caster passes w/out alpha test
	


	


	

	

	

	return outVs;
}
Has anybody encountered the same issue?

Best Regards
Lax
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Tue Jun 11, 2019 5:29 am

Your pixel shader's main function is completely empty ?!?!
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Tue Jun 11, 2019 8:20 pm

Hi,

Yeah, I have no idea, why this is happing. Maybe its a bug in Ogre. I do not know what todo. The shader seems corrupt.
I also updated Ogre 2.2 version and build everything carefully from the scratch, but no improvement :(

Best Regards
Lax
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Thu Jun 13, 2019 6:31 am

Lax wrote:
Tue Jun 11, 2019 8:20 pm
Hi,

Yeah, I have no idea, why this is happing. Maybe its a bug in Ogre. I do not know what todo. The shader seems corrupt.
I also updated Ogre 2.2 version and build everything carefully from the scratch, but no improvement :(

Best Regards
Lax
The direct reason for the empty pixelshader is

Code: Select all

***    hlms_render_depth_only    1
and

Code: Select all

***    hlms_shadowcaster    1
But I don't know why :(
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Thu Jun 13, 2019 6:18 pm

hm, ok so how can I disable "hlms_render_depth_only"?
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Fri Jun 14, 2019 12:55 pm

Lax wrote:
Thu Jun 13, 2019 6:18 pm
hm, ok so how can I disable "hlms_render_depth_only"?
hmmm. I don't think so. It's "passively" defined only when there is NO COLOR ATTACHMENTS in the render pass descriptor, so it is "detected as" render depth only. It is not "actively" set. Can you try to find out why it is so by debugging render pass descriptor setting code.
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Thu Jul 11, 2019 1:33 pm

Hi all,

clones does still not work. Its not possible to clone any datablock.
Could this be tested please for 2.2?
I would like to know, if this is an Ogre bug. Because in Ogre 2.1 the cloning did work perfectly.

Best Regards
Lax
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Thu Jul 11, 2019 5:27 pm

Lax wrote:
Thu Jul 11, 2019 1:33 pm
Could this be tested please for 2.2?
Unfortunately, I don't clone datablocks in my project. Maybe you can try to clone datablocks in a sample (maybe the PbsMaterial sample). If that doesn't work, then great; if the works, then there might be something wrong with your integration code, like the last strange issue you had (can't remember what was that though). Then maybe you can try to simplify your engine code as much as you can, until you're able to post it here
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Fri Jul 12, 2019 9:23 pm

Hi,

yes, I reset reflection by setting an empty string for reflection texture, which caused the ugly behavior. But dark_sylinc fixed that.
Now with the fix of the topic: "Knowing which datablock causes pixelshader error", datablock cloning does not crash anymore.

But as soon as I clone a datablock, like:

Code: Select all

this->originalDatablock = dynamic_cast<Ogre::HlmsPbsDatablock*>(entity->getSubEntity(this->subEntityIndex->getUInt())->getDatablock());
this->originalDataBlockName = *this->originalDatablock->getNameStr();

this->datablock = dynamic_cast<Ogre::HlmsPbsDatablock*>(this->originalDatablock->clone(this->originalDataBlockName
				+ Ogre::StringConverter::toString(this->gameObjectPtr->getId())));
entity->getSubEntity(this->subEntityIndex->getUInt())->setDatablock(this->datablock);
The entity will become just white. No texture is applied.
What could cause this effect?

Best Regards
Lax
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Mon Jul 15, 2019 4:05 am

Lax wrote:
Fri Jul 12, 2019 9:23 pm
The entity will become just white. No texture is applied.
What could cause this effect?
I don't know why, but what if you manually set a diffuse texture (get a texture from original datablock then set to the new one)? does it work?

Also, you can try to export your scene with the SceneFormat component (before and after cloning) and try to look at/compare the exported datablocks. It's a good way to debug, hehe.
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Sat Jul 20, 2019 3:57 pm

I digged deeper into Ogre's cloning and I think, its not adapted to Ogre2.2, because the textures are just referenced. But I think something like this must be done:

Code: Select all

Ogre::TextureGpuManager* hlmsTextureManager = Ogre::Root::getSingletonPtr()->getRenderSystem()->getTextureGpuManager();
				
				Ogre::uint32 textureFlags = Ogre::TextureFlags::AutomaticBatching;

				if (datablock->suggestUsingSRGB(pbsTextureType))
					textureFlags |= Ogre::TextureFlags::PrefersLoadingFromFileAsSRGB;

				Ogre::TextureTypes::TextureTypes internalTextureType = Ogre::TextureTypes::Type2D;
				if (textureType == Ogre::PBSM_REFLECTION)
				{
					internalTextureType = Ogre::TextureTypes::TypeCube;
					textureFlags &= ~Ogre::TextureFlags::AutomaticBatching;
				}

				Ogre::uint32 filters = Ogre::TextureFilter::FilterTypes::TypeGenerateDefaultMipmaps;
				filters |= datablock->suggestFiltersForType(pbsTextureType);

				Ogre::TextureGpu* texture = hlmsTextureManager->createOrRetrieveTexture(attribute->getUserData().first,
					attribute->getUserData().first, Ogre::GpuPageOutStrategy::Discard, textureFlags, internalTextureType,
					Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, filters);

				if (nullptr != texture)
				{
					// Attention: wait here, or before the loop?
					texture->scheduleTransitionTo(Ogre::GpuResidency::Resident);

					if (true == tempTextureName.empty())
					{
						hlmsTextureManager->destroyTexture(texture);
						texture = nullptr;
					}
					datablock->setTexture(pbsTextureType, texture);
When I clone the datablock I get a datablock without textures applied, yet the textures are set in the texture array.
I don't know why, but what if you manually set a diffuse texture (get a texture from original datablock then set to the new one)? does it work?
When I try to re-apply the texture, it will not work because auf this check in "OgreHlmsTextureBaseClass.inl" in function "void OGRE_HLMS_TEXTURE_BASE_CLASS::_setTexture( ... )":

Code: Select all

 if( mTextures[texType] != texture )
Because the texture does exist in the array already.

Hopefully @darks_sylinc can do something to solve the issue.

Best Regards
Lax
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Mon Jul 22, 2019 3:35 am

Lax wrote:
Sat Jul 20, 2019 3:57 pm
Because the texture does exist in the array already.
Hopefully @darks_sylinc can do something to solve the issue.
Is it blocking your way, or you already found workarounds and can continue to migrate to Ogre 2.2?

If you CAN continue to migrate, I would prefer to keep slience and wait for dark_sylinc; otherwise I strongly suggest that you dump your datablock to json and load it to a new datablock 8-) Actually the reason that we never used Ogre's clone datablock functionality is that we have our own material data structure and we're doing datablock clone by doing two conversions: datablock->our_material_datastructure->datablock
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Thu Aug 08, 2019 2:20 pm

Hi rujialiu,

I now have time again for this topic.
dump your datablock to json and load it to a new datablock
How do you do that?
I just found datablock->loadTextures, or hlmsManager->saveMaterials

Best Regards
Lax
0 x

rujialiu
Goblin
Posts: 224
Joined: Mon May 09, 2016 8:21 am
x 20

Re: 2.2 Clone datablock crash

Post by rujialiu » Sat Aug 24, 2019 4:52 am

Hi!
Lax wrote:
Thu Aug 08, 2019 2:20 pm
How do you do that?
I just found datablock->loadTextures, or hlmsManager->saveMaterials
I don't know.... we don't use material jsons...
0 x

Lax
Gnome
Posts: 369
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: 2.2 Clone datablock crash

Post by Lax » Sat Sep 14, 2019 12:35 pm

Finally solved it!

It was just one command, I changed transition from:

Code: Select all

texture->scheduleTransitionTo(Ogre::GpuResidency::Resident);
to:

Code: Select all

texture->scheduleTransitionTo(Ogre::GpuResidency::OnSystemRam);
Now the cloning of datablocks and textures does work again!
0 x

Post Reply