compile error in Direct3D pixel shader Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

compile error in Direct3D pixel shader

Post by jwwalker »

I'm trying to port some code that works on macOS with Metal to run on Win32 with the Direct3D11 RenderSystem. When it tries to render, it gets a compile error in the pixel shader. Here is Ogre.log, scroll to the end to see the exception.

Code: Select all

13:48:41: Creating resource group General
13:48:41: Creating resource group Internal
13:48:41: Creating resource group Autodetect
13:48:41: SceneManagerFactory for type 'DefaultSceneManager' registered.
13:48:41: Registering ResourceManager for type Material
13:48:41: Registering ResourceManager for type Mesh
13:48:41: Registering ResourceManager for type Mesh2
13:48:41: Registering ResourceManager for type OldSkeleton
13:48:41: MovableObjectFactory for type 'ParticleSystem' registered.
13:48:41: ArchiveFactory for archive type FileSystem registered.
13:48:41: ArchiveFactory for archive type Zip registered.
13:48:41: ArchiveFactory for archive type EmbeddedZip registered.
13:48:41: DDS codec registering
13:48:41: FreeImage version: 3.15.3
13:48:41: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
13:48:41: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,jng,koa,iff,lbm,mng,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,gif,hdr,g3,sgi,exr,j2k,j2c,jp2,pfm,pct,pict,pic
13:48:41: ETC codec registering
13:48:41: OITD codec registering
13:48:41: Registering ResourceManager for type HighLevelGpuProgram
13:48:41: MovableObjectFactory for type 'Decal' registered.
13:48:41: MovableObjectFactory for type 'InternalCubemapProbe' registered.
13:48:41: MovableObjectFactory for type 'Entity' registered.
13:48:41: MovableObjectFactory for type 'Item' registered.
13:48:41: MovableObjectFactory for type 'Light' registered.
13:48:41: MovableObjectFactory for type 'Rectangle2Dv2' registered.
13:48:41: MovableObjectFactory for type 'BillboardSet' registered.
13:48:41: MovableObjectFactory for type 'ManualObject2' registered.
13:48:41: MovableObjectFactory for type 'BillboardChain' registered.
13:48:41: MovableObjectFactory for type 'RibbonTrail' registered.
13:48:41: MovableObjectFactory for type 'WireAabb' registered.
13:48:41: *-*-* OGRE Initialising
13:48:41: *-*-* Version 2.4.0unstable (E)
13:48:41: Loading library C:\Program Files\FrameForge Storyboard Studio 4.0\RenderSystem_Direct3D11_d.dll
13:48:41: Installing plugin: D3D11 RenderSystem
13:48:41: D3D11: Direct3D11 Rendering Subsystem created.
13:48:41: D3D11: Driver Detection Starts
13:48:41: D3D11: "NVIDIA GeForce RTX 2060"
13:48:41: D3D11: "Microsoft Basic Render Driver (software)"
13:48:41: D3D11: Driver Detection Ends
13:48:41: Plugin successfully installed
13:48:41: D3D11: RenderSystem Option: sRGB Gamma Conversion = Yes
13:48:41: OverlayElementFactory for type Panel registered.
13:48:41: OverlayElementFactory for type BorderPanel registered.
13:48:41: OverlayElementFactory for type TextArea registered.
13:48:41: Registering ResourceManager for type Font
13:48:41: CPU Identifier & Features
13:48:41: -------------------------
13:48:41:  *   CPU ID: GenuineIntel: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
13:48:41:  *   Logical cores: 8
13:48:41:  *      SSE: yes
13:48:41:  *     SSE2: yes
13:48:41:  *     SSE3: yes
13:48:41:  *      MMX: yes
13:48:41:  *   MMXEXT: yes
13:48:41:  *    3DNOW: no
13:48:41:  * 3DNOWEXT: no
13:48:41:  *     CMOV: yes
13:48:41:  *      TSC: yes
13:48:41:  *      FPU: yes
13:48:41:  *      PRO: yes
13:48:41:  *       HT: no
13:48:41: -------------------------
13:48:41: D3D11: Subsystem Initialising
13:48:41: D3D11: Driver Detection Starts
13:48:41: D3D11: "NVIDIA GeForce RTX 2060"
13:48:41: D3D11: "Microsoft Basic Render Driver (software)"
13:48:41: D3D11: Driver Detection Ends
13:48:41: D3D11: Requested "(default)", selected "NVIDIA GeForce RTX 2060"
13:48:41: D3D11: Device Feature Level 11.1
13:48:41: ***************************************
13:48:41: *** D3D11: Subsystem Initialized OK ***
13:48:41: ***************************************
13:48:41: Added resource location 'C:\Program Files\FrameForge Storyboard Studio 4.0\ogre resources/2.0/scripts/materials/Common' of type 'FileSystem' to resource group 'General'
13:48:41: Added resource location 'C:\Program Files\FrameForge Storyboard Studio 4.0\ogre resources/2.0/scripts/materials/Common/Any' of type 'FileSystem' to resource group 'General'
13:48:41: Added resource location 'C:\Program Files\FrameForge Storyboard Studio 4.0\ogre resources/2.0/scripts/materials/Common/HLSL' of type 'FileSystem' to resource group 'General'
13:48:41: Added resource location 'C:\Program Files\FrameForge Storyboard Studio 4.0\ogre resources/Hlms/Common/Any' of type 'FileSystem' to resource group 'General'
13:48:41: Added resource location 'C:\Program Files\FrameForge Storyboard Studio 4.0\ogre resources/Hlms/Common/HLSL' of type 'FileSystem' to resource group 'General'
13:48:41: Creating resource group Popular
13:48:41: Added resource location 'C:\Program Files\FrameForge Storyboard Studio 4.0\ogre resources/2.0/scripts/Compositors' of type 'FileSystem' to resource group 'Popular'
13:48:41: D3D11RenderSystem::_createRenderWindow "temp", 10x10 windowed  miscParams: externalWindowHandle=1840308 
13:48:41: Registering ResourceManager for type GpuProgram
13:48:41: RenderSystem capabilities
13:48:41: -------------------------
13:48:41: RenderSystem Name: Direct3D11 Rendering Subsystem
13:48:41: GPU Vendor: nvidia
13:48:41: Device Name: NVIDIA GeForce RTX 2060
13:48:41: Driver Version: 30.0.15.1109
13:48:41:  * Fixed function pipeline: no
13:48:41:  * Hardware generation of mipmaps: yes
13:48:41:  * Texture blending: yes
13:48:41:  * Anisotropic texture filtering: yes
13:48:41:  * Dot product texture operation: yes
13:48:41:  * Cube mapping: yes
13:48:41:  * Hardware stencil buffer: yes
13:48:41:    - Stencil depth: 8
13:48:41:    - Two sided stencil support: yes
13:48:41:    - Wrap stencil values: yes
13:48:41:  * Hardware vertex / index buffers: yes
13:48:41:  * 32-bit index buffers: yes
13:48:41:  * Vertex programs: yes
13:48:41:  * Number of floating-point constants for vertex programs: 512
13:48:41:  * Number of integer constants for vertex programs: 16
13:48:41:  * Number of boolean constants for vertex programs: 16
13:48:41:  * Fragment programs: yes
13:48:41:  * Number of floating-point constants for fragment programs: 512
13:48:41:  * Number of integer constants for fragment programs: 16
13:48:41:  * Number of boolean constants for fragment programs: 16
13:48:41:  * Geometry programs: yes
13:48:41:  * Number of floating-point constants for geometry programs: 512
13:48:41:  * Number of integer constants for geometry programs: 16
13:48:41:  * Number of boolean constants for geometry programs: 16
13:48:41:  * Tessellation Hull programs: yes
13:48:41:  * Number of floating-point constants for tessellation hull programs: 512
13:48:41:  * Number of integer constants for tessellation hull programs: 16
13:48:41:  * Number of boolean constants for tessellation hull programs: 16
13:48:41:  * Tessellation Domain programs: yes
13:48:41:  * Number of floating-point constants for tessellation domain programs: 512
13:48:41:  * Number of integer constants for tessellation domain programs: 16
13:48:41:  * Number of boolean constants for tessellation domain programs: 16
13:48:41:  * Compute programs: yes
13:48:41:  * Number of floating-point constants for compute programs: 512
13:48:41:  * Number of integer constants for compute programs: 16
13:48:41:  * Number of boolean constants for compute programs: 16
13:48:41:  * Supported Shader Profiles: cs_5_0 ds_5_0 gs_4_0 gs_4_1 gs_5_0 hlsl hs_5_0 ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3 ps_4_1 ps_5_0 vs_4_0 vs_4_0_level_9_1 vs_4_0_level_9_3 vs_4_1 vs_5_0
13:48:41:  * Texture Compression: yes
13:48:41:    - DXT: yes
13:48:41:    - VTC: no
13:48:41:    - PVRTC: no
13:48:41:    - ATC: no
13:48:41:    - ETC1: no
13:48:41:    - ETC2: no
13:48:41:    - BC4/BC5: yes
13:48:41:    - BC6H/BC7: yes
13:48:41:    - ASTC: no
13:48:41:  * Hardware Occlusion Query: yes
13:48:41:  * User clip planes: yes
13:48:41:  * VET_UBYTE4 vertex element type: yes
13:48:41:  * Infinite far plane projection: yes
13:48:41:  * Hardware render-to-texture: yes
13:48:41:  * Floating point textures: yes
13:48:41:  * Non-power-of-two textures: yes
13:48:41:  * 1d textures: yes
13:48:41:  * Volume textures: yes
13:48:41:  * Max Texture resolution (2D) 16384
13:48:41:  * Max Texture resolution (3D) 2048
13:48:41:  * Max Texture resolution (Cubemaps) 16384
13:48:41:  * Multiple Render Targets: 8
13:48:41:    - With different bit depths: yes
13:48:41:  * Point Sprites: yes
13:48:41:  * Extended point parameters: yes
13:48:41:  * Max Point Size: 256
13:48:41:  * Vertex texture fetch: yes
13:48:41:  * Number of world matrices: 0
13:48:41:  * Number of texture units: 16
13:48:41:  * Stencil buffer depth: 8
13:48:41:  * Number of vertex blend matrices: 0
13:48:41:    - Max vertex textures: 4
13:48:41:    - Vertex textures shared: no
13:48:41:  * Render to Vertex Buffer : yes
13:48:41:  * Hardware Atomic Counters: no
13:48:41:  * Shader 16-bit floating point (half): no
13:48:41:  * Compute max threads per threadgroup per axis: 1024, 1024, 64
13:48:41:  * Compute max threads per threadgroup total: 1024
13:48:41:  * Using Reverse Z: yes
13:48:41: DefaultWorkQueue('Root') initialising on thread main.
13:48:41: Particle Renderer Type 'billboard' registered
13:48:41: [INFO] Texture cache not found at C:\Users\jw\AppData\Local\FrameForge\Ogre-cache\/textureMetadataCache.json
13:48:41: Parsing scripts for resource group Autodetect
13:48:41: Finished parsing scripts for resource group Autodetect
13:48:41: Creating resources for group Autodetect
13:48:41: All done
13:48:41: Parsing scripts for resource group General
13:48:41: Parsing script Quad.program
13:48:42: Parsing script Copyback.material
13:48:42: Parsing script DepthUtils.material
13:48:42: Parsing script DPM.material
13:48:42: Parsing script DPSM.material
13:48:42: Parsing script EsmGaussianBlurLogFilter.material
13:48:42: Parsing script HiddenAreaMeshVr.material
13:48:42: Parsing script PccDepthCompressor.material
13:48:42: Parsing script RadialDensityMask.material
13:48:42: Parsing script Sky.material
13:48:42: Parsing script EsmGaussianBlurLogFilter.material.json
13:48:42: Parsing script Mipmaps.material.json
13:48:42: Finished parsing scripts for resource group General
13:48:42: Creating resources for group General
13:48:42: All done
13:48:42: Parsing scripts for resource group Internal
13:48:42: Finished parsing scripts for resource group Internal
13:48:42: Creating resources for group Internal
13:48:42: All done
13:48:42: Parsing scripts for resource group Popular
13:48:42: Parsing script InstancedStereo.compositor
13:48:42: Parsing script IrradianceFieldRaster.compositor
13:48:42: Parsing script LocalCubemaps.compositor
13:48:42: Parsing script PbsMaterials.compositor
13:48:42: Parsing script PlanarReflections.compositor
13:48:42: Parsing script Refractions.compositor
13:48:42: Parsing script ScreenSpaceReflections.compositor
13:48:42: Parsing script ShadowMapDebugging.compositor
13:48:42: Parsing script StaticShadowMaps.compositor
13:48:42: Parsing script StencilTest.compositor
13:48:42: Parsing script StereoRendering.compositor
13:48:42: Parsing script TutorialSky_Postprocess.compositor
13:48:42: Parsing script TutorialUav01_Setup.compositor
13:48:42: Parsing script TutorialUav02_Setup.compositor
13:48:42: Parsing script Tutorial_DynamicCubemap.compositor
13:48:42: Parsing script Tutorial_OpenVRWorkspace.compositor
13:48:42: Parsing script Tutorial_ReconstructPosFromDepth.compositor
13:48:42: Parsing script Tutorial_Terrain.compositor
13:48:42: Parsing script UvBaking.compositor
13:48:42: Finished parsing scripts for resource group Popular
13:48:42: Creating resources for group Popular
13:48:42: All done
13:48:45: D3D11RenderSystem::_createRenderWindow "foo", 255x138 windowed  miscParams: FSAA=true externalWindowHandle=791170 gamma=true reverse_depth=true vsync=true 
13:48:45: D3D11RenderSystem::_createRenderWindow "foo", 612x612 windowed  miscParams: FSAA=true externalWindowHandle=856564 gamma=true reverse_depth=true vsync=true 
13:48:45: D3D11RenderSystem::_createRenderWindow "foo", 163x163 windowed  miscParams: FSAA=true externalWindowHandle=987766 gamma=true reverse_depth=true vsync=true 
13:48:46: OGRE EXCEPTION(-2147467259:RenderingAPIException): Cannot compile D3D11 high-level shader 100000000PixelShader_ps Errors:
C:\Users\jw\AppData\Local\FrameForge\Ogre-cache\100000000PixelShader_ps.hlsl(665,23): error X3014: incorrect number of arguments to numeric-type constructor
 in D3D11HLSLProgram::compileMicrocode at D:\MoreCode\Ogre\ogre-next-fork\RenderSystems\Direct3D11\src\OgreD3D11HLSLProgram.cpp (line 554)
I gather that's saying that the error was on line 665 of the shader. It's a little hard to be sure exactly where that is, because the pixel shader file has mixed line endings (part CRLF, part LF) but I think it's happening in this area:

Code: Select all

Buffer<uint> f3dGrid : register(t2);
ReadOnlyBuffer( 1, float4, f3dLightList );
Looks like that comes from the hlms_forwardplus property of PixelShader_ps.hlsl, so I'd guess that it has something to do with using Forward3D. But my Win32 build of Sample_Forward3D runs successfully using RenderSystem_Direct3D11, so I'm not sure where to go from here.

P.S. I tried changing all the media files to use LF line breaks. Then the exception seems to say that the error is on line 593, but in the ps.hlsl file, line 593 is in the middle of a run of blank lines.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: compile error in Direct3D pixel shader

Post by dark_sylinc »

Can you upload the shader file?
Thanks
jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: compile error in Direct3D pixel shader

Post by jwwalker »

Here's the pixel shader:

Code: Select all

#if 0
	***	hlms_uv_count0	2
	***	hlms_pose	0
	***	uv_emissive	0
	***	first_valid_detail_map_nm	4
	***	fresnel_scalar	0
	***	envprobe_map_sampler	4
	***	hlms_uv_count	1
	***	uv_detail_nm1	0
	***	two_sided_lighting	1
	***	hlms_forwardplus_debug	0
	***	uv_detail_nm2	0
	***	envMapRegSampler	4
	***	emissive_map_sampler	4
	***	precision_mode	-2126167738
	***	BRDF_Default	1
	***	set0_texture_slot_end	4
	***	uv_specular	0
	***	hlms_disable_stage	0
	***	NumPoseWeightVectors	0
	***	specular_map_sampler	4
	***	texcoord	4
	***	forward_clustered	599612461
	***	fast_shader_build_hack	1
	***	glsl	635204550
	***	f3dGrid	2
	***	NumPoseWeightVectorsB	0
	***	hlms_lights_directional	0
	***	samplerStateStart	4
	***	alpha_test	0
	***	roughness_map_sampler	4
	***	GGX_height_correlated	1
	***	glsles	1070293233
	***	metallic_workflow	0
	***	hw_gamma_write	1
	***	uv_detail_weight	0
	***	detail_map_nm2_sampler	4
	***	hlms_alpha_to_coverage	0
	***	cubemaps_as_diffuse_gi	1
	***	uv_detail_nm3	0
	***	NumPoseWeightVectorsC	0
	***	hlms_pose_normals	0
	***	hlms_pose_half	0
	***	hlms_lights_spot	0
	***	detail_map1_sampler	4
	***	uv_normal	0
	***	relaxed	1726237731
	***	detail_map_nm3_sampler	4
	***	hlms_alphablend	1
	***	f3dLightList	1
	***	MoreThanOnePose	-1
	***	num_textures	1
	***	hlslvk	1841745752
	***	uv_detail3	0
	***	orwardplus_covers_entire_target	1
	***	detail_map3_sampler	4
	***	normal_map	0
	***	NumPoseWeightVectorsA	0
	***	uv_detail1	0
	***	fresnel_workflow	0
	***	full32	-2126167738
	***	forward3d_num_slices	4
	***	perceptual_roughness	1
	***	hlms_forwardplus	-1972038953
	***	alpha_test_shadow_caster_only	0
	***	materials_per_buffer	2
	***	hw_gamma_read	1
	***	hlms_skeleton	0
	***	hlms_pssm_splits_minus_one	-1
	***	midf16	-1978079318
	***	forward3d	-1972038953
	***	partial_pso_clip_distances	0
	***	syntax	-334286542
	***	NeedsMoreThan1BonePerVertex	-1
	***	hlms_lights_point	0
	***	diffuse_map_sampler	4
	***	metal	-1698855755
	***	detail_map_nm1_sampler	4
	***	s_lights_directional_non_caster	0
	***	uv_detail0	0
	***	uv_diffuse	0
	***	diffuse_map	1
	***	uv_detail_nm0	0
	***	detail_weight_map_sampler	4
	***	diffuse_map_idx	0
	***	detail_map_nm0_sampler	4
	***	hlms_render_depth_only	0
	***	normal_map_tex_sampler	4
	***	uv_detail2	0
	***	MoreThanOnePoseWeightVector	-1
	***	detail_map2_sampler	4
	***	full_pso_clip_distances	0
	***	textureMaps0	4
	***	detail_map0_sampler	4
	***	uv_roughness	0
	***	receive_shadows	1
	***	_forward_fade_attenuation_range	1
	***	clear_coat	0
	***	needs_view_dir	1
	***	set1_texture_slot_end	5
	***	use_planar_reflections	0
	***	hlms_normal	1
	***	ltc_texture_available	1
	***	num_samplers	1
	***	glslvk	-338983575
	***	hlsl	-334286542
	***	ambient_fixed	1
	***	normal_weight	0
	***	hlms_vpos	1
	DONE DUMPING PROPERTIES
	DONE DUMPING PIECES
#endif

//#include "SyntaxHighlightingMisc.h"


#define ushort uint
#define ushort3 uint3
#define ushort4 uint4
#define ogre_float4x3 float4x3

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

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

// See CrossPlatformSettings_piece_all.glsl for an explanation

	#define _h(x) (x)

	#define midf float
	#define midf2 float2
	#define midf3 float3
	#define midf4 float4
	#define midf2x2 float2x2
	#define midf3x3 float3x3
	#define midf4x4 float4x4

	#define midf_c float
	#define midf2_c float2
	#define midf3_c float3
	#define midf4_c float4
	#define midf2x2_c float2x2
	#define midf3x3_c float3x3
	#define midf4x4_c float4x4

	#define toMidf3x3( x ) ((float3x3)( x ))
	#define buildMidf3x3( row0, row1, row2 ) transpose( float3x3( row0, row1, row2 ) )

	#define ensureValidRangeF16(x)

#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 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_normal input.normal
#define inVs_tangent input.tangent
#define inVs_binormal input.binormal
#define inVs_blendWeights input.blendWeights
#define inVs_blendIndices input.blendIndices
#define inVs_qtangent input.qtangent
#define inVs_colour input.colour

	#define inVs_drawId input.drawId

#define finalDrawId input.drawId


	#define inVs_uv0 input.uv0
#define outVs_Position outVs.gl_Position
#define outVs_viewportIndex outVs.gl_ViewportIndex
#define outVs_clipDistance0 outVs.gl_ClipDistance0.x

#define gl_SampleMaskIn0 gl_SampleMask
#define interpolateAtSample( interp, subsample ) EvaluateAttributeAtSample( interp, subsample )
#define findLSB firstbitlow
#define findMSB firstbithigh
#define mod( a, b ) (a - b * floor(a / b))

#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_LoadArray2D( tex, iuv, arrayIdx, lod ) tex.Load( int4( iuv, arrayIdx, lod ) )
#define OGRE_Load2DMS( tex, iuv, subsample ) tex.Load( iuv, subsample )

#define OGRE_Load3D( tex, iuv, lod ) tex.Load( int4( iuv, lod ) )

#define OGRE_Load2DF16( tex, iuv, lod ) tex.Load( int3( iuv, lod ) )
#define OGRE_Load2DMSF16( tex, iuv, subsample ) tex.Load( iuv, subsample )
#define OGRE_SampleF16( tex, sampler, uv ) tex.Sample( sampler, uv )
#define OGRE_SampleLevelF16( tex, sampler, uv, lod ) tex.SampleLevel( sampler, uv, lod )
#define OGRE_SampleArray2DF16( tex, sampler, uv, arrayIdx ) tex.Sample( sampler, float3( uv, arrayIdx ) )
#define OGRE_SampleArray2DLevelF16( tex, sampler, uv, arrayIdx, lod ) tex.SampleLevel( sampler, float3( uv, arrayIdx ), lod )
#define OGRE_SampleArrayCubeLevelF16( tex, sampler, uv, arrayIdx, lod ) tex.SampleLevel( sampler, float4( uv, arrayIdx ), lod )
#define OGRE_SampleGradF16( tex, sampler, uv, ddx, ddy ) tex.SampleGrad( sampler, uv, ddx, ddy )
#define OGRE_SampleArray2DGradF16( tex, sampler, uv, arrayIdx, ddx, ddy ) tex.SampleGrad( sampler, float3( uv, arrayIdx ), ddx, ddy )

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

#define structuredBufferFetch( buffer, idx ) buffer[idx]

	#define ReadOnlyBuffer( slot, varType, varName ) StructuredBuffer<varType> varName : register(t##slot)
	#define readOnlyFetch( bufferVar, idx ) bufferVar[idx]
	#define readOnlyFetch1( bufferVar, idx ) bufferVar[idx].x

#define OGRE_Texture3D_float4 Texture3D

#define OGRE_ArrayTex( declType, varName, arrayCount ) declType varName[arrayCount]

#define OGRE_SAMPLER_ARG_DECL( samplerName ) , SamplerState samplerName
#define OGRE_SAMPLER_ARG( samplerName ) , samplerName

#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 OGRE_OUT_REF( declType, variableName ) out declType variableName
#define OGRE_INOUT_REF( declType, variableName ) inout declType variableName

#define OGRE_ARRAY_START( type ) {
#define OGRE_ARRAY_END }


	#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)
	
#undef makeOgreFloat4x3

ogre_float4x3 loadOgreFloat4x3( StructuredBuffer<float4> matrixBuf, uint offsetIdx )
{
	float4 row1 = matrixBuf[int(offsetIdx)];
	float4 row2 = matrixBuf[int(offsetIdx) + 1u];
	float4 row3 = matrixBuf[int(offsetIdx) + 2u];

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

#define makeOgreFloat4x3( row0, row1, row2 ) transpose( float3x4( row0, row1, row2 ) )

#undef UV_DIFFUSE
#define UV_DIFFUSE( p ) mul( float4( (p), 1.0, 0.0 ), makeOgreFloat4x3( material.userValue[0], material.userValue[1], float4(0.0) ) ).xy






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

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

#define lightTexProfileIdx spotDirection.w
};

#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
#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
							//points[1].w, points[2].w, points[3].w contain obbFadeFactorLtc.xyz
	};





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

	float4x4 viewProj;




	//Vertex shader
	float4x4 view;
	
	
	//-------------------------------------------------------------------------

	//Pixel shader
	float3x3 invViewMatCubemap;

	float padding; //Compatibility with GLSL

	float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps;

	float4 aspectRatio_planarReflNumMips_unused2;

	float2 invWindowRes;
	float2 windowResolution;


	float4 ambientUpperHemi;





			// !use_light_buffers



	//Forward3D
	//f3dData.x = minDistance;
	//f3dData.y = invMaxDistance;
	//f3dData.z = f3dNumSlicesSub1;
	//f3dData.w = uint cellsPerTableOnGrid0 (floatBitsToUint);

	//Clustered Forward:
	//f3dData.x = minDistance;
	//f3dData.y = invExponentK;
	//f3dData.z = f3dNumSlicesSub1;
	//f3dData.w = renderWindow->getHeight();
	float4 f3dData;
	
		float4 f3dGridHWW[4];
		float4 f3dViewportOffset;
		
	


	
	

	

#define pccVctMinDistance		pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps.x
#define invPccVctInvDistance	pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps.y
#define rightEyePixelStartX		pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps.z
#define envMapNumMipmaps		pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps.w

#define aspectRatio			aspectRatio_planarReflNumMips_unused2.x
#define planarReflNumMips	aspectRatio_planarReflNumMips_unused2.y
}
CONST_BUFFER_STRUCT_END( passBuf );


#define light0Buf		passBuf
#define light1Buf		passBuf
#define light2Buf		passBuf

// use_light_buffers


				
//Uniforms that change per Item/Entity, but change very infrequently
struct Material
{
	/* kD is already divided by PI to make it energy conserving.
	  (formula is finalDiffuse = NdotL * surfaceDiffuse / PI)
	*/
	float4 bgDiffuse;
	float4 kD; //kD.w is alpha_test_threshold
	float4 kS; //kS.w is roughness
	//Fresnel coefficient, may be per colour component (float3) or scalar (float)
	//F0.w is transparency
	float4 F0;
	float4 normalWeights;
	float4 cDetailWeights;
	float4 detailOffsetScale[4];
	float4 emissive;		//emissive.w contains mNormalMapWeight.
	float refractionStrength;
	float clearCoat;
	float clearCoatRoughness;
	float _padding1;
	float4 userValue[3];

	
		uint4 indices0_3;
		uint4 indices4_7;
	
	
};
	
	
		CONST_BUFFER( MaterialBuf, 1 )
		{
			Material materialArray[2];
		};
	
		
		//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

	
		#define float_fresnel midf
		#define make_float_fresnel( x ) midf_c( x )
	
	
			#define OGRE_DEPTH_CMP_GE( a, b ) (a) <= (b)
		#define OGRE_DEPTH_DEFAULT_CLEAR 0.0
	

			#define PASSBUF_ARG_DECL
		#define PASSBUF_ARG
	
	
	struct PixelData
	{
		
			midf3 normal;
							#define geomNormal normal
						midf4	diffuse;
			midf3	specular;

			
			midf	perceptualRoughness;
			midf	roughness;
			float_fresnel	F0;

			
				midf3	viewDir;
				midf	NdotV;
			
					
		
	};

	#define SampleDetailWeightMap( tex, sampler, uv, arrayIdx ) OGRE_SampleArray2DF16( tex, sampler, uv, arrayIdx )
		
		#define SampleDiffuse( tex, sampler, uv, arrayIdx ) OGRE_SampleArray2DF16( tex, sampler, uv, arrayIdx ) 					
	
	
	
	
		

		
//Default BRDF
INLINE midf3 BRDF( midf3 lightDir, midf3 lightDiffuse, midf3 lightSpecular, PixelData pixelData )
{
	midf3 halfWay = normalize( lightDir + pixelData.viewDir );
	midf NdotL = saturate( dot( pixelData.normal, lightDir ) );
	midf NdotH = saturate( dot( pixelData.normal, halfWay ) );
	midf VdotH = saturate( dot( pixelData.viewDir, halfWay ) );

	midf sqR = pixelData.roughness * pixelData.roughness;

	//Geometric/Visibility term (Smith GGX Height-Correlated)

	midf Lambda_GGXV = NdotL * sqrt( (-pixelData.NdotV * sqR + pixelData.NdotV) * pixelData.NdotV + sqR );
	midf Lambda_GGXL = pixelData.NdotV * sqrt( (-NdotL * sqR + NdotL) * NdotL + sqR );

	midf G = _h( 0.5 ) / (( Lambda_GGXV + Lambda_GGXL + _h( 1e-6f ) ) * _h( 3.141592654 ));


	//Roughness/Distribution/NDF term (GGX)
	//Formula:
	//	Where alpha = roughness
	//	R = alpha^2 / [ PI * [ ( NdotH^2 * (alpha^2 - 1) ) + 1 ]^2 ]
	const midf f = ( NdotH * sqR - NdotH ) * NdotH + _h( 1.0 );
	midf R = sqR / (f * f); // f is guaranteed to not be 0 because we clamped pixelData.roughness

	const midf RG = R * G;

	//Formula:
	//	fresnelS = lerp( (1 - V*H)^5, 1, F0 )
    float_fresnel fresnelS = pixelData.F0 + pow( _h( 1.0 ) - VdotH, _h( 5.0 ) ) * (_h( 1.0 ) - pixelData.F0);

	//We should divide Rs by PI, but it was done inside G for performance
	midf3 Rs = ( fresnelS * RG ) * pixelData.specular.xyz;

	//Diffuse BRDF (*Normalized* Disney, see course_notes_moving_frostbite_to_pbr.pdf
	//"Moving Frostbite to Physically Based Rendering" Sebastien Lagarde & Charles de Rousiers)
	midf energyBias	= pixelData.perceptualRoughness * _h( 0.5 );
	midf energyFactor	= lerp( _h( 1.0 ), _h( 1.0 / 1.51 ), pixelData.perceptualRoughness );
	midf fd90			= energyBias + _h( 2.0 ) * VdotH * VdotH * pixelData.perceptualRoughness;
	midf lightScatter	= _h( 1.0 ) + (fd90 - _h( 1.0 )) * pow( _h( 1.0 ) - NdotL, _h( 5.0 ) );
	midf viewScatter	= _h( 1.0 ) + (fd90 - _h( 1.0 )) * pow( _h( 1.0 ) - pixelData.NdotV, _h( 5.0 ) );

    		midf fresnelD = _h( 1.0f ) - fresnelS;
    
	//We should divide Rd by PI, but it is already included in kD
	midf3 Rd = (lightScatter * viewScatter * energyFactor * fresnelD) * pixelData.diffuse.xyz;

			return NdotL * (Rs * lightSpecular + Rd * lightDiffuse);
	}

		
		
	
	
	
	
	
	





struct PS_INPUT
{

			
			FLAT_INTERPOLANT( ushort drawId, 0 );
			
	
		
			INTERPOLANT( float3 pos, 1 );
			INTERPOLANT( midf3 normal, 2 );
							
			INTERPOLANT( float2 uv0, 3 );
		
					
				
				

};




		






    Buffer<uint> f3dGrid : register(t2);
    ReadOnlyBuffer( 1, float4, f3dLightList );



	Texture2DArray textureMaps0 : register(t4);


	SamplerState samplerState4 : register(s4);














	struct PS_OUTPUT
	{
		
			
				float4 colour0 : SV_Target0;
					
		
					
	};




PS_OUTPUT main
(
	PS_INPUT inPs
	, float4 gl_FragCoord : SV_Position	, bool gl_FrontFacing : SV_IsFrontFace	)
{
	PS_OUTPUT outPs;
	
	
		
	
		PixelData pixelData;

		
	
		
            ushort materialId	= worldMaterialIdx[inPs.drawId].x & 0x1FFu;
            #define material materialArray[materialId]
			
		
					ushort texIndex_diffuseIdx			= material.indices0_3.x & 0x0000FFFFu;											
		
																				
		
		

		
	

		
	/// Sample detail maps and weight them against the weight map in the next foreach loop.
	

		
			
	/// DIFFUSE MAP
	
		pixelData.diffuse = SampleDiffuse( textureMaps0,
										   samplerState4,
										   UV_DIFFUSE( inPs.uv0.xy ),
										   texIndex_diffuseIdx );
	
	/// Blend the detail diffuse maps with the main diffuse.
	
	/// Apply the material's diffuse over the textures
	pixelData.diffuse.xyz *= midf3_c( material.kD.xyz );
	
	
		
		
	/// SPECUlAR MAP
	pixelData.specular.xyz = midf3_c( material.kS.xyz );
	
		pixelData.F0 = make_float_fresnel( material.F0.x );
						
		
		
	/// ROUGHNESS MAP
	pixelData.perceptualRoughness = midf_c( material.kS.w );
	

	
		pixelData.roughness = max( pixelData.perceptualRoughness * pixelData.perceptualRoughness, _h( 0.001f ) );
	


		

		
			
	
		// Geometric normal
		pixelData.normal = normalize( inPs.normal ) * (gl_FrontFacing ? 1.0 : -1.0);
	
			
	/// If there is no normal map, the first iteration must
	/// initialize pixelData.normal instead of try to merge with it.
						
	
	
	/// Blend the detail normal maps with the main normal.
		

			

			

			
			

		
		
			
	//Everything's in Camera space
	
		
			pixelData.viewDir	= midf3_c( normalize( -inPs.pos ) );
				pixelData.NdotV		= saturate( dot( pixelData.normal, pixelData.viewDir ) );
	
			midf3 finalColour = midf3_c( passBuf.ambientUpperHemi.xyz ) * pixelData.diffuse.xyz;
	
	
	
	
	


			

			
				
		
	
			
			
			
	
			
	

			
			

			
	
		
	
		#define FWDPLUS_APPLY_OFFSET_Y(v) (v)
		#define FWDPLUS_APPLY_OFFSET_X(v) (v)
	
			#define fwdFragCoord gl_FragCoord
	
	
		float f3dMinDistance	= passBuf.f3dData.x;
		float f3dInvMaxDistance	= passBuf.f3dData.y;
		float f3dNumSlicesSub1	= passBuf.f3dData.z;
		uint cellsPerTableOnGrid0= floatBitsToUint( passBuf.f3dData.w );

		// See C++'s Forward3D::getSliceAtDepth
		/*float fSlice = 1.0 - saturate( (-inPs.pos.z + f3dMinDistance) * f3dInvMaxDistance );
		fSlice = (fSlice * fSlice) * (fSlice * fSlice);
		fSlice = (fSlice * fSlice);
		fSlice = floor( (1.0 - fSlice) * f3dNumSlicesSub1 );*/
		float fSlice = saturate( (-inPs.pos.z + f3dMinDistance) * f3dInvMaxDistance );
		fSlice = floor( fSlice * f3dNumSlicesSub1 );
		uint slice = uint( fSlice );

		//TODO: Profile performance: derive this mathematically or use a lookup table?
		uint offset = cellsPerTableOnGrid0 * (((1u << (slice << 1u)) - 1u) / 3u);

		float lightsPerCell = passBuf.f3dGridHWW[0].w;

		
		//passBuf.f3dGridHWW[slice].x = grid_w
I just noticed that it ends without a closing brace. That seems like a clear problem.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: compile error in Direct3D pixel shader

Post by dark_sylinc »

There is a:

Code: Select all

#undef UV_DIFFUSE
#define UV_DIFFUSE( p ) mul( float4( (p), 1.0, 0.0 ), makeOgreFloat4x3( material.userValue[0], material.userValue[1], float4(0.0) ) ).xy
That's not part of vanilla Ogre code.
If I have to guess, that float4(0.0) should be float4(0.0, 0.0, 0.0, 0.0).

Btw about the line number:
You may have noticed the file starts with:

Code: Select all

#if 0
	***	hlms_uv_count0	2
....
#endif
That is part is added to the dump for debugging but it is not actually part of the shader. Thus stripping it will get you the right line of code.

If you want it off by default you can call Hlms::setDebugOutputPath( enableDebugOutput, outputProperties = false, ... ) (outputProperties being false is what matters)
jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

Re: compile error in Direct3D pixel shader

Post by jwwalker »

You're right! Apparently, abbreviating float4(0.0, 0.0, 0.0, 0.0) as float4(0.0) is legal in Metal (and I think in GLSL, if memory serves) but not in HLSL. And thanks for explaining about the line numbers.