fxc.exe throws error when running on wine - hlsl

I have this fxc.exe which is copied from a working windows SDK. It does everything properly on a windows machine. However when I transported it to my linux machine and ran it in wine with the exact same arguments, it did not work.
The output of it (including wine messages):
0100:fixme:d3dcompiler:D3DCompile2 Ignoring flags 0x5.
Z:\home\sunnymonster\dev\DestinyEngine\DestinyEngine\assets\shaders\hlsl\test_shader_vs.hlsl:28:2: E5017: Aborting due to
not yet implemented feature: Call to user-defined function "vert_main".
compilation failed; no code produced
and the command that I ran:
vendor/shader-compiling/fxc.exe /nologo /Emain /Tvs_5_0 /Od /Zi /Fo assets/shaders/hlsl/thing_vs.cso assets/shaders/hlsl/test_shader_vs.hlsl
The source code of my shader (it is generated by another program):
static float4 gl_Position;
static float3 f_Colour;
static float3 a_Colour;
static float2 a_Pos;
struct SPIRV_Cross_Input
{
float2 a_Pos : POSITION;
float3 a_Colour : COLOR0;
};
struct SPIRV_Cross_Output
{
float3 f_Colour : TEXCOORD10;
float4 gl_Position : SV_Position;
};
void vert_main()
{
f_Colour = a_Colour;
gl_Position = float4(a_Pos, 1.0f, 1.0f);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
a_Colour = stage_input.a_Colour;
a_Pos = stage_input.a_Pos;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output.f_Colour = f_Colour;
return stage_output;
}
Any ideas on why this is happening?

Related

How to compile from shader assembler code in DirectX 11?

D3DXAssembleShader function was used in DirectX 9 for compiling shaders from Assembly. It's not supported in DirectX 11. Is there any alternative to create shaders from Assembler code?
I am aware of compiling from fx or hlsl files but for my project purposes, I should compile only using assembly.
The following code was used in DirectX 9:
static const char VertexShaderCode[] = \
"vs.3.0\n"
"dcl_position v0\n"
"dcl_position o0\n"
"mov o0, v0\n";
D3DXAssembleShader(VertexShaderCode,sizeof(VertexShaderCode), 0,0, DLL, &VSBuffer, 0);
I am looking for an alternative to the above code in DirectX11 using D3D11 dll's.
I want to modify my asm file like below and create vertex and pixel shaders:
dcl_output o0.xyzw -> dcl_output.o0.zw
Will I be able to do the same in fx or hlsl file?
FX file:
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
}
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS( float4 Pos : POSITION, float4 Color : COLOR )
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.Pos = mul( Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Color = Color;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( VS_OUTPUT input ) : SV_Target
{
return input.Color;
}
Compiling from HLSL shader assembly isn't officially supported for Shader Model 4.0, 4.1, 5.0, or 5.1.
When you build with fxc.exe you get disassembly for debugging & optimization purposes

Error: Invalid vs_2_0 output semantic

Its says: Invalid vs_2_0 output semantic SV_Target.
So for some reason Visual Studio 2017 is compiling my pixel shader as if it is a vertex shader. But in the properties panel I specified it to be a ps_5_0. Is there something I'm missing that should be specified?
Vertex shader:-
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
}
struct Input {
float3 Pos : POSITION;
float4 Color: COLOR;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
VS_OUTPUT main(Input input)
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.Pos = mul(input.Pos, World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);
output.Color = input.Color;
return output;
}
Pixel shader:-
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
float4 main(VS_OUTPUT input) : SV_Target
{
return input.Color;
}
And here are my settings for the pixel shader.
I hope someone can help me.
Open the Property page for the .hlsl file, and in HLSL Compiler/General/Shader Type select Pixel Shader.
And don't forget to set this propertie for debug and release.
You can resolve the issue by modifying the shader property
properties -> HLSL Compiler -> General -> Shader Type -> Pixel Shader (/ps)
OR
Configuration properties -> General -> Excluded from Build = Yes.

Interpret the HLSL Shader Compiler Macro code

Profile:
WiN7 Prof SP1
Directx11
Development IDE: VS 2015
Program Language: C#
Application Type: 3D Rendering
Directx11 Wrapper: SLimDX
In my C# project I have a 3D renderer that is working.
I want to integrate a third Party HLSL Shader Code.
I have translated the code for Directx11 Feature level and it compiles with fxc.exe without errors or warnings.
The shader is loaded by my C# application and I can access all shader variables and set values of them.
Problem:
When I try to get a reference in my C# Code to access the first pass of the first technique of the Shader I get a SlimDX runtime Error.
I can reference the first technique of the shader with no runtime error but the obtained object has a flag is_valid = false showing the technique was not referenced correctly.
Clarification: I don't try to make a draw call but in preparation of the draw call I have to get a reference to the relevant pass.
Question:
I can't understand what the last compiler directives about the techniques mean exactly.
Can someone translate which HLSL Code will eventually produced from the compiler directive?
I mean the beginning from :
#define OBJECT_TEC(name, mmdpass) \
#include "../ray.conf"
#include "../ray_advanced.conf"
#include "../shader/math.fxsub"
#include "../shader/common.fxsub"
#include "../shader/gbuffer.fxsub"
#include "../shader/lighting.fxsub"
float3 LightDirection : DIRECTION < string Object = "Light"; >;
float3 LightSpecular : SPECULAR < string Object = "Light"; >;
bool ExistRay : CONTROLOBJECT<string name = "ray.x";>;
texture DiffuseMap: MATERIALTEXTURE;
sampler DiffuseMapSamp = sampler_state
{
texture = <DiffuseMap>;
MINFILTER = ANISOTROPIC;
MAGFILTER = ANISOTROPIC;
MIPFILTER = POINT;
MAXANISOTROPY = 16;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
};
float4 GetTextureColor(float4 albedo, float2 uv)
{
if (use_texture)
{
float4 TexColor = tex2D(DiffuseMapSamp, uv);
TexColor.rgb = lerp(1, TexColor * TextureMulValue + TextureAddValue, TextureMulValue.a + TextureAddValue.a).rgb;
albedo *= TexColor;
}
return srgb2linear(albedo);
}
void DrawObjectVS(
in float4 Position : POSITION,
in float3 Normal : NORMAL,
in float4 Texcoord : TEXCOORD0,
out float4 oTexcoord : TEXCOORD0,
out float3 oNormal : TEXCOORD1,
out float3 oViewdir : TEXCOORD2,
out float4 oPosition : SV_Position)
{
oNormal = Normal;
oTexcoord = Texcoord;
oViewdir = CameraPosition - Position.xyz;
oPosition = mul(Position, matWorldViewProject);
}
float4 DrawObjectPS(float4 texcoord : TEXCOORD0, float3 normal : TEXCOORD1, float3 viewdir : TEXCOORD2) : SV_Target
{
#if EXIST_RAY
#if DISCARD_ALPHA_ENABLE
float alpha = MaterialDiffuse.a;
#if DISCARD_ALPHA_MAP_ENABLE
if (use_texture) alpha *= tex2D(DiffuseMapSamp, texcoord.xy).a;
#endif
clip(alpha - DiscardAlphaThreshold);
#endif
return 0;
#else
if (ExistRay)
{
#if DISCARD_ALPHA_ENABLE
float alpha = MaterialDiffuse.a;
#if DISCARD_ALPHA_MAP_ENABLE
if (use_texture) alpha *= tex2D(DiffuseMapSamp, texcoord.xy).a;
#endif
clip(alpha - DiscardAlphaThreshold);
#endif
return 0;
}
else
{
float4 albedo = GetTextureColor(MaterialDiffuse, texcoord.xy);
float3 L = normalize(-LightDirection);
float3 V = normalize(viewdir);
float3 N = normalize(normal);
float MaterialRoughness = SmoothnessToRoughness(ShininessToSmoothness(MaterialPower));
float4 lighting = albedo;
lighting.rgb *= DiffuseBRDF(N, L, V, MaterialRoughness);
lighting.rgb += SpecularBRDF_GGX(N, L, V, MaterialRoughness, 0.04, 1.0);
lighting.rgb *= LightSpecular;
return linear2srgb(lighting);
}
#endif
}
#define OBJECT_TEC(name, mmdpass) \
technique name < string MMDPass = mmdpass;\
> { \
pass DrawObject { \
AlphaTestEnable = FALSE; AlphaBlendEnable = FALSE; \
VertexShader = compile vs_3_0 DrawObjectVS(); \
PixelShader = compile ps_3_0 DrawObjectPS(); \
} \
}
OBJECT_TEC(MainTec0, "object")
OBJECT_TEC(MainTecBS0, "object_ss")
technique EdgeTec < string MMDPass = "edge"; > {}
technique ShadowTech < string MMDPass = "shadow"; > {}
technique ZplotTec < string MMDPass = "zplot"; > {}

HLSL error X3000: unrecognized identifier

I don't have any experience with hlsl and can't figure out how to fix this error. Here is my SimpleVertexShader.hlsl file
cbuffer PerApplication : register (b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register (b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register (b2)
{
matrix worldMatrix;
}
struct AppData
{
float3 position : POSITION;
float3 color : COLOR;
};
struct VertexShaderOuput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
VertexShaderOuput SimpleVertexShader(AppData IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.position = mul(mvp, float4(IN.position, 1.0f));
OUT.color = float4(IN.color, 1.0f);
return OUT;
}
I get an error X3000: unrecognized identifier 'VertexShaderOutput' as well as unrecognized identifier 'OUT'. I am using Visual Studio 2013. And under the Properties for this file I have these settings:
HLSL Compiler>Entrypoint Name: SimpleVertexShader
Shader Type: Vertex Shader (/vs)
Shader Model: Shader Model 4 (/4_0).
HLSL Compiler>Output Files>Header Variable Name: g_vs
Object File Name: $(OutDir)%(Filename)_d.cso.
(the _d is only under the Debug configuration.)

HLSL Pixel Shader 5.0 NdotL lighting sample

I am going through a tutorial for Pixel Shader 5.0 using directX. I was doing fine until I got to the fourth lesson, which has me create a PixelShader.hlsl file with the following code:
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Proj;
float4 vLightDir[2];
float4 vLightColor[2];
float4 vOutputColor;
}
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 Norm : TEXCOORD0;
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 main( PS_INPUT input) : SV_Target
{
float4 finalColor = 0;
//do NdotL lighting for 2 lights
for(int i=0; i<2; i=""
{
finalColor += "saturate"( dot=""( (float3)vLightDir=""[i=""],input.Norm="") * vLightColor=""[i=""
}
finalColor.a = "1"
return="" finalColor="";
}
The for loop at the end of the file has me confused. Int i is being initialized to a constant string, and there is no closing parenthesis.
Similarly, the code within the for loop looks incorrect as well. The float4 struct appears to have a string "saturate" being appended to it, which is also a function? A function without proper closing braces and no semicolon no less.
It looks like there are some typos in the sample code, and I'm struggling to fix them. Any thoughts as to what should be written here?
When I try to compile the code in VS2012, I get the following error: error X3017: cannot implicitly convert from 'const string' to 'int'
I tried fixing the for loop code by changing it to
for(int i=0, i<2, i++)
and I get a different error for the code within the for loop: error X3022: scalar, vector, or matrix expected
Thanks in advance for your help
I finally got a response from the site author. Turns out an XML converter auto-formatted the code sample and messed some things up. Here is the proper code:
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Proj;
float4 vLightDir[2];
float4 vLightColor[2];
float4 vOutputColor;
}
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 Norm : TEXCOORD0;
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 main( PS_INPUT input) : SV_Target
{
float4 finalColor = 0;
//do NdotL lighting for 2 lights
for(int i=0; i<2; i++)
{
finalColor += saturate( dot( (float3)vLightDir[i],input.Norm) * vLightColor[i] );
}
finalColor.a = 1;
return finalColor;
}