Jump to content

GLSL Shader Crash


photo

Recommended Posts

Hi,
I'm a newbie with GLSL and currently experiencing a crash in a fragment shader on my ATI FirePro V and have no idea why.

 

Are there issues with for loops on ATI cards? Could the vertex shader be the cause of the problem instead?

 

It runs fine on my intel and NVidia cards. Any help would be much appreciated - here's the complete code for both the vertex and fragment shader:

 

 

 

#include <core/shaders/default/common/vertex_base.h>

/*
    Trivial vertex shader for IDW - just passes the uv (representing the vertex position in
    normalised query volume space) along as a varying vec3.
*/

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES

    in float4 s_attribute_0;
    in half4 s_attribute_1;
    in half4 s_attribute_2;

    out vec3 normalisedFragmentLoc;

    void main()
    {
        float4 row_0,row_1,row_2;

        row_0 = s_transform[0];
        row_1 = s_transform[1];
        row_2 = s_transform[2];

        float4 position = float4(s_attribute_0.x,s_attribute_0.y,s_attribute_2.w,1.0f);
        float4 vertex = float4(dot(row_0,position),dot(row_1,position),dot(row_2,position),1.0f);

        gl_Position = getPosition(vertex);
        //normalisedFragmentLoc = s_attribute_1.xyz;
    }

#elif DIRECT3D10 || DIRECT3D11

/******************************************************************************\
*
* DirectX 10/11
*
\******************************************************************************/

#endif

 

 

 

 

 

 

/*
    Not so trivial fragment shader for IDW - for each pixel we find the (inverse distance weighted) interpolated value
     based on nearby measurements.
*/

#include <core/shaders/default/common/fragment_base.h>

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES

in vec3 normalisedFragmentLoc;

uniform sampler2D s_texture_0;      // Drill data measurements. Each texel has the position and value of a down hole measurement, and
                                    // each row contains samples positioned within a cell of a regular lattice spanning the volume of interest.

uniform sampler2D s_texture_1;      // LUT texture to transform from value to color - should be in a seperate pass so that we render *values* in here not the value to color mapping.

// Set from script based on dataset
uniform vec4 volume_range;
uniform vec4 grid_size;

// User controlled parameters
uniform float idw_range;
uniform float idw_rangeMultiplierZ;
uniform float idw_exponent;
uniform float idw_linearFadeFactor;
uniform float idw_ignoreTopDist;
uniform float apply_mapping;

struct Accumulator
{
    float m_sumOfWeightedValues;
    float m_sumOfWeights;
};

float GetWeightedAverage(Accumulator acc)
{
    return acc.m_sumOfWeightedValues / acc.m_sumOfWeights;
}

float worldSpaceDistance(vec3 a, vec3 b )
{
    vec3 v = volume_range.xyz * (a - b );
    v.z *= idw_rangeMultiplierZ;
    return length( v );
}

void Gather(in int row, in int rowLength, inout Accumulator acc)
{
    // First two texels represent the bounding box
    vec4 minV = texelFetch(s_texture_0,ivec2(0,row),0);
    vec4 maxV = texelFetch(s_texture_0,ivec2(1,row),0);

    vec3 closePoint = clamp( normalisedFragmentLoc, minV.xyz, maxV.xyz );
    if( worldSpaceDistance( normalisedFragmentLoc, closePoint ) < idw_range )
    {
        int sampleCount = int(minV.w * rowLength);
        for(int i=0;i<sampleCount;i++)
        {
            vec4 texel = texelFetch(s_texture_0,ivec2(i+2,row),0);

            float d = worldSpaceDistance( normalisedFragmentLoc, texel.xyz );
            if( d < idw_range && texel.z < idw_ignoreTopDist )
            {
                float weight = 1.0f / pow(d,idw_exponent);
                weight *= (1.0f - idw_linearFadeFactor * (d / idw_range));

                acc.m_sumOfWeights += weight;
                acc.m_sumOfWeightedValues += weight * texel.w;
            }
        }
    }
}

void main()
{
    ivec2 encodedSize = textureSize(s_texture_0,0);
   
    Accumulator acc = Accumulator(0.0f,0.0f);

    // Compensate for sqaushed Z
    vec3 radiusNormalised = idw_range / volume_range.xyz;
    radiusNormalised.z /= idw_rangeMultiplierZ;
   
    // Index into the lattice
    ivec3 maxRange = ivec3(grid_size.xyz) - ivec3(1);
    ivec3 minV = clamp( ivec3(floor( (normalisedFragmentLoc - radiusNormalised) * grid_size.xyz )),ivec3(0),maxRange );
    ivec3 maxV = clamp( ivec3(floor( (normalisedFragmentLoc + radiusNormalised) * grid_size.xyz )),ivec3(0),maxRange );

    // For each cell in range
    for(int x=minV.x;x<=maxV.x;x++)
    {
        for(int y=minV.y;y<=maxV.y;y++)
        {
            for(int z=minV.z;z<=maxV.z;z++)
            {
                // Find the row in the texture where all values are encoded for this cell
                int index = int(x + y * grid_size.x + z * (grid_size.x * grid_size.y));
                Gather(index,encodedSize.x,acc);
            }
        }
    }

    // Operate in 2 modes -> either render raw result, or render color mapped result
    if( apply_mapping < 1.0f )
    {
        if( acc.m_sumOfWeights > 0.0f )
        {
            float w = GetWeightedAverage(acc);
            s_frag_color = vec4(vec3(w),1);
        }
        else
        {
            s_frag_color = vec4(0);
        }
    }
    else
    {
        if( acc.m_sumOfWeights > 0.0f )
        {
            // Clamp uv to half texel from edge to avoid interpolation / wrapping.
            float padding = 0.5f / textureSize(s_texture_1,0).x;
            float w = clamp(GetWeightedAverage(acc),padding,1.0f - padding);
            s_frag_color = texture(s_texture_1,vec2(w,0),0);
        }
        else
        {
            discard;
        }
    }
}

/******************************************************************************\
*
* DirectX 10/11
*
\******************************************************************************/

#elif DIRECT3D10 || DIRECT3D11

#endif

Link to comment

Hi,

 

ok - so, in an effort to get a scene happening with the vertex and fragment shaders I have tried to apply them to an object in a scene in the unigine editor.

 

Unfortunately I'm getting the following error:

 

D3D11Shader::loadFragment(): error in "core/shaders/rtvis_idw_fragment.shader" f
ile
defines: UNKNOWN,QUALITY_LOW,QUALITY_MEDIUM,MULTISAMPLE_0,USE_INSTANCING,USE_TES
SELLATION,USE_GEOMETRY_SHADER,USE_TEXTURE_3D,USE_TEXTURE_ARRAY,USE_ALPHA_FADE,US
E_REFLECTION,USE_DEFERRED,USE_PARALLAX,HAS_DEFERRED_COLOR,HAS_DEFERRED_NORMAL,HA
S_DEFERRED_PARALLAX,USE_RGB10A2,USE_PHONG_RIM,USE_ENVIRONMENT,USE_NORMALIZATION,
USE_DIRECTIONAL_LIGHTMAPS,USE_SHADOW_KERNEL,DIRECT3D11,HAS_FEATURE_LEVEL_10_0,US
E_FEATURE_LEVEL_11_0,USE_FEATURE_LEVEL_10_1,USE_COMPUTE_SHADER_10_0,USE_COMPUTE_
SHADER_11_0,USE_ALPHA_TEST_LEVEL_10_1
error X3501: 'main': entrypoint not found

 

 

Not sure why - I changed the renderer to OpnGL in the editor settings but the problem is still occuring.

 

Any ideas why this might be happening?  I've attached the scripts in question

 

Thanks,

Simon

rtvis_idw_fragment.shader

rtvis_idw_vertex.shader

Link to comment

Hi, Simon.

 

Thanks for the code! I had a look at it and to me it looks just normal.

 

Have you tried to pass proper video_app parameter on startup arguments? Switching renderer during runtime is not possible.

 

I guess that's what happened:

 

1) You launched binary with -video_app direct3d11 or -video_app direct3d9 as a start agrument;

2) In the app you switched it to OpenGL in Unigine's system menu (I believe you a popup with "You must restart Unigine to apply this settings" appeared), that set video_app to OpenGL;

3) Launched it again with the same binary with Direct3D start argument.

Link to comment

Hi,

 

Yes I did try it and managed to get the shader to compile - thanks.  

 

Unfortunately I couldn't get it to crash the way it was in my original application.  The code is too tightly coupled to the application and it's very hard (and time consuming) to isolate it completely.   I can only reproduce it on AMD graphics cards for some reason.  

 

We're using Unigine from around April 2013 BTW.

 

Thanks,

Simon

Link to comment

Simon,

 

I have a few suggestions:

 

1) If it's possible, you can detach shader from your app and test it in a clean separate app or put it in a shader tool;

2) There might be one more thing which may be important: script flush function. If you're running multi-threaded physics then flush is running in parallel with render and it might be unsafe to change material parameters or geometry, create or delete meshes and textures in flush function. So please check this.

Link to comment

Hi,

 

It looks like flush is being called (although we don't use an physics in our software anyway).

 

Now, as I said I have an older version of unigine installed (mid 2013) and had opengl 4.4 installed and it was crashing.  I then reverted to OpenGL 4.2 and it seems to have fixed the problem.

 

Does this sound logical?  Could older versions of unigine crash with later versions of opengl/gfx drivers?  Do you have any minimum specifications for older unigine versions?

 

Thanks,

Simon

Link to comment

Hi Simon,

 

Could older versions of unigine crash with later versions of opengl/gfx drivers?

GPU drivers indeed can cause crash. However, we can't really say for now what is the cause of such behavior - driver issue or shader code from April, 2013 SDK.

 

Do you have any minimum specifications for older unigine versions?

Minimum system requirements - GPU with DX9+ support and latest GPU driver. Assuming that you are using old SDK you can use latest drivers available in 2013.

 

Sorry for the inconvenience.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Ok silent, thanks for the info.

 

So just to confirm - Unigine 2.0 will (officially) support GPUs from all manufacturers and their associated graphics drivers up to 2015?

 

Also, is there any estimation for the "official" release date of Unigine 2.0 yet?  We have to decide whether to update to the latest 2014 release or wait for 2.0. 

 

If 2.0 is pegged for the end of this year then we will most likely have to update to the latest 1.x in the mean time.

 

Thanks,

Simon

Link to comment

Hi Simon,
 

So just to confirm - Unigine 2.0 will (officially) support GPUs from all manufacturers and their associated graphics drivers up to 2015?

 

Unigine 2.0 requires GPU with OpenGL 4.4+ and DirectX11+. Updated list of supported GPUs available here: https://developer.unigine.com/en/docs/1.0/start/hardware

 

 

Also, is there any estimation for the "official" release date of Unigine 2.0 yet?  We have to decide whether to update to the latest 2014 release or wait for 2.0. 

 
If 2.0 is pegged for the end of this year then we will most likely have to update to the latest 1.x in the mean time.

 
We plan to release stable Unigine 2.0 in Q1, 2015.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...