Comments (9)
So as example, my extension methods for setting uniforms are as follows:
public enum OGLShaderUniformRequirementPolicy
{
/// <summary>
/// Uniform is always required. Error out if missing.
/// </summary>
REQUIRED,
/// <summary>
/// Uniform can be skipped if missing. Don't error out.
/// </summary>
OPTIONAL
}
public static (int Ok, ExecutionErrorReport Err) GetUniformLocation(this OGLShader me, string uniform_name, OGLShaderUniformRequirementPolicy requirement_policy)
{
try
{
// Context is just a property to GL variable stored in OGLShader.
var location = me.Context.GetUniformLocation(me.ID, uniform_name);
var errCode = me.Context.GetError();
if (errCode != GLEnum.NoError)
return (location, new() { ErrorMessage = $"*** GetUniformLocation() failed with error: {errCode}", ErrorType = ExecutionErrorType.Exit });
if (requirement_policy == OGLShaderUniformRequirementPolicy.OPTIONAL) return (location, new());
else
{
return location.Equals((int)GLEnum.InvalidIndex)
? (location, new() { ErrorMessage = $"*** {uniform_name} uniform not found on shader {me.ID}", ErrorType = ExecutionErrorType.Exit })
: (location, new());
}
}
catch (Exception e)
{ return ((int)GLEnum.InvalidIndex, new() { ErrorMessage = e.Message, ErrorType = ExecutionErrorType.Exception }); }
}
public unsafe static ExecutionErrorReport SetUniform(this OGLShader me, string uniform_name, float value)
{
try
{
var (location, err) = me.GetUniformLocation(uniform_name, OGLShaderUniformRequirementPolicy.REQUIRED);
if (err.ErrorType != ExecutionErrorType.None) return err;
me.Context.Uniform1(location, value);
var errCode = me.Context.GetError();
return errCode != GLEnum.NoError
? new() { ErrorMessage = $"*** Uniform1() failed with error: {errCode}", ErrorType = ExecutionErrorType.Exit }
: new();
}
catch (Exception e)
{ return new() { ErrorMessage = e.Message, ErrorType = ExecutionErrorType.Exception }; }
}
public unsafe static ExecutionErrorReport SetNearPlane(this OGLShader me, float value)
=> me.SetUniform(OGLShaderUniformNames.NEAR_PLANE, value);
public unsafe static ExecutionErrorReport SetFarPlane(this OGLShader me, float value)
=> me.SetUniform(OGLShaderUniformNames.FAR_PLANE, value);
public unsafe static ExecutionErrorReport SetClippingPlanes(this OGLShader me, float near, float far)
{
var err = me.SetNearPlane(near);
if (err.ErrorType != ExecutionErrorType.None) return err;
return me.SetFarPlane(far);
}
For now all methods use OGLShaderUniformRequirementPolicy::REQUIRED, so they error out if location is -1
. It doesn't matter what combination I use, just GetUniformLocation(), SetUniform() or one of the tailored methods for setting planes, they all return -1
on NVidia.
And this fails only for those two uniforms, NEAR_PLANE
& FAR_PLANE
.
But setting those uniforms directly, without querying their locations, and passing layout(location = 3)
and layout(location = 4)
with this method:
public unsafe static ExecutionErrorReport SetUniform(this OGLShader me, int uniform_location, float value)
{
try
{
me.Context.Uniform1(uniform_location, value);
var errCode = me.Context.GetError();
return errCode != GLEnum.NoError
? new() { ErrorMessage = $"*** Uniform1() failed with error: {errCode}", ErrorType = ExecutionErrorType.Exit }
: new();
}
catch (Exception e)
{ return new() { ErrorMessage = e.Message, ErrorType = ExecutionErrorType.Exception }; }
}
will work and uniforms are changing in shader.
from silk.net.
The pipeline layout of OGL should be fixed in the code rather than obtained through querying. This approach is also in line with the modern programming style of graphic libraries.
from silk.net.
I'm building engine at this point, so not many standarized things there yet. Just adding viewport gizmos.
So what, GetUniformLocation() is deprecated in Core and it can return wrong value?
from silk.net.
I'm building engine at this point, so not many standarized things there yet. Just adding viewport gizmos.
So what, GetUniformLocation() is deprecated in Core and it can return wrong value?
I have encountered similar issues with shaders compiled using OGL 4.6 + SPV on Intel and AMD GPUs, where querying would indeed return -1.
from silk.net.
Have you tried to check the output of something like this:
gl.GetProgram(program, GLEnum.ActiveUniforms, out var activeUniforms);
for (var i = 0; i < activeUniforms; i++)
{
var name = GetActiveUniform(program, (uint)i, out var size, out var type);
Console.WriteLine($"Uniform {i} - Name: {name} - Size: {size} - Type: {type}");
}
from silk.net.
On Intel iGPU prints:
Uniform 0 - Name: PROJECTION - Size: 1 - Type: FloatMat4
Uniform 1 - Name: VIEW - Size: 1 - Type: FloatMat4
Uniform 2 - Name: FAR_PLANE - Size: 1 - Type: Float
Uniform 3 - Name: NEAR_PLANE - Size: 1 - Type: Float
Uniform 4 - Name: VIEW_POS - Size: 1 - Type: FloatVec3
Uniform 5 - Name: gridAxis - Size: 1 - Type: Int
Uniform 6 - Name: gridCellSize - Size: 1 - Type: Float
Uniform 7 - Name: gridOpacity - Size: 1 - Type: Float
Uniform 8 - Name: gl_DepthRange.near - Size: 1 - Type: Float
Uniform 9 - Name: gl_DepthRange.far - Size: 1 - Type: Float
Uniform 10 - Name: gl_DepthRange.diff - Size: 1 - Type: Float
If I force RTX 3050, it prints:
Uniform 0 - Name: PROJECTION - Size: 1 - Type: FloatMat4
Uniform 1 - Name: VIEW - Size: 1 - Type: FloatMat4
Uniform 2 - Name: VIEW_POS - Size: 1 - Type: FloatVec3
Uniform 3 - Name: gridAxis - Size: 1 - Type: Int
Uniform 4 - Name: gridCellSize - Size: 1 - Type: Float
Uniform 5 - Name: gridOpacity - Size: 1 - Type: Float
Uniform 6 - Name: gl_DepthRange.diff - Size: 1 - Type: Float
Uniform 7 - Name: gl_DepthRange.near - Size: 1 - Type: Float
from silk.net.
Interesting... Perhaps try adjusting the previous code:
Console.WriteLine($"Uniform {i} - Name: {name} - Size: {size} - Type: {type} - Location: {gl.GetUniformLocation(program, name)}");
To see whether there's a noticeable gap in the location indices.
Also make sure you're checking the compile/link status, and retrieving the info logs in any case. There may be more info therein.
Note you can also use BindAttribLocation
before calling LinkProgram
to set an attribute location. Really the one in the shader text should be respected and will take precedence over the one specified in BindAttribLocation
, but I'm wondering whether this would force it to pop up.
from silk.net.
Intel iGPU:
Uniform 0 - Name: PROJECTION - Size: 1 - Type: FloatMat4 - Location: 1
Uniform 1 - Name: VIEW - Size: 1 - Type: FloatMat4 - Location: 0
Uniform 2 - Name: FAR_PLANE - Size: 1 - Type: Float - Location: 4
Uniform 3 - Name: NEAR_PLANE - Size: 1 - Type: Float - Location: 3
Uniform 4 - Name: VIEW_POS - Size: 1 - Type: FloatVec3 - Location: 2
Uniform 5 - Name: gridAxis - Size: 1 - Type: Int - Location: 5
Uniform 6 - Name: gridCellSize - Size: 1 - Type: Float - Location: 6
Uniform 7 - Name: gridOpacity - Size: 1 - Type: Float - Location: 7
Uniform 8 - Name: gl_DepthRange.near - Size: 1 - Type: Float - Location: -1
Uniform 9 - Name: gl_DepthRange.far - Size: 1 - Type: Float - Location: -1
Uniform 10 - Name: gl_DepthRange.diff - Size: 1 - Type: Float - Location: -1
RTX 3050:
Uniform 0 - Name: PROJECTION - Size: 1 - Type: FloatMat4 - Location: 1
Uniform 1 - Name: VIEW - Size: 1 - Type: FloatMat4 - Location: 0
Uniform 2 - Name: VIEW_POS - Size: 1 - Type: FloatVec3 - Location: 2
Uniform 3 - Name: gridAxis - Size: 1 - Type: Int - Location: 5
Uniform 4 - Name: gridCellSize - Size: 1 - Type: Float - Location: 6
Uniform 5 - Name: gridOpacity - Size: 1 - Type: Float - Location: 7
Uniform 6 - Name: gl_DepthRange.diff - Size: 1 - Type: Float - Location: -1
Uniform 7 - Name: gl_DepthRange.near - Size: 1 - Type: Float - Location: -1
As for the BindAttribLocation()
, it is for attribs, not for uniforms. So it did nothing.
from silk.net.
Ah yeah my bad, forgot about that. It seems like 3 and 4 are being kept free. Have you tried with other names just in case it's a weird driver quirk?
Assuming that there was no extra info in the link/compile logs, I also recommend using RenderDoc to see if you can see what RenderDoc recognises the shader as.
Failing all of that, I recommend reporting this to NVIDIA and finding a workaround e.g. using a uniform block or SSBO instead. There is ample evidence here that this is not a Silk.NET issue.
from silk.net.
Related Issues (20)
- Desktop macOS binaries in the Silk.NET.MoltenVK.Native package HOT 2
- Make Silk.NET buildable on Linux (by loosening .NET workload requirements)
- Build shaderc, SPIRV-Cross, and SPIRV-Reflect native packages for `linux-arm` HOT 3
- Create a build script for OpenAL Soft native binaries HOT 1
- Make WindowOptions a class HOT 1
- Re-enable ANGLE native builds HOT 1
- Build Assimp with Draco support HOT 1
- Input related callbacks in GLFW cause an AccessViolationException HOT 2
- Build SwiftShader native package for `win-arm64` HOT 4
- Build Vulkan Loader native package for `win-arm64` HOT 8
- Build Vkd3d shader compiler native package for `linux-arm` and `linux-arm64`
- OpenGL glTextureParameteri symbol not found on macOS HOT 1
- Silk.NET.Core.Loader.DefaultPathResolver does not check the directory of its own assembly HOT 1
- Build DXVK native package for `linux-arm`, `linux-arm64`, and `win-arm64`
- Hi, is NV_DX_interop2 missing for WGL.Extensions? HOT 16
- Silk.NET is awesome, but no CUDA? HOT 1
- SDL2 gone on publish HOT 5
- Add MeshOptimizer Bindings HOT 1
- Error when trying to use TextureStorage3D on Android HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from silk.net.