Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Veldrid shader resource layouts and add header guard #5857

Merged
merged 5 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion osu.Framework/Graphics/OpenGL/Shaders/GLShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ private protected virtual bool CompileInternal()

if (layout.Elements.Any(e => e.Kind == ResourceKind.TextureReadOnly || e.Kind == ResourceKind.TextureReadWrite))
{
var textureElement = layout.Elements.First(e => e.Kind == ResourceKind.TextureReadOnly || e.Kind == ResourceKind.TextureReadWrite);
ResourceLayoutElementDescription textureElement = layout.Elements.First(e => e.Kind == ResourceKind.TextureReadOnly || e.Kind == ResourceKind.TextureReadWrite);

if (layout.Elements.All(e => e.Kind != ResourceKind.Sampler))
throw new ProgramLinkingFailedException(name, $"Texture {textureElement.Name} has no associated sampler.");

textureUniforms.Add(new Uniform<int>(renderer, this, textureElement.Name, GL.GetUniformLocation(this, textureElement.Name))
{
Value = textureIndex++
Expand Down
35 changes: 8 additions & 27 deletions osu.Framework/Graphics/Veldrid/Shaders/VeldridShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,41 +181,22 @@ private void compile()

if (layout.Elements.Any(e => e.Kind == ResourceKind.TextureReadOnly || e.Kind == ResourceKind.TextureReadWrite))
{
// Todo: We should enforce that a texture set contains both a texture and a sampler.
var textureElement = layout.Elements.First(e => e.Kind == ResourceKind.TextureReadOnly || e.Kind == ResourceKind.TextureReadWrite);
var samplerElement = layout.Elements.First(e => e.Kind == ResourceKind.Sampler);

textureLayouts.Add(new VeldridUniformLayout(
set,
renderer.Factory.CreateResourceLayout(
new ResourceLayoutDescription(
new ResourceLayoutElementDescription(
textureElement.Name,
ResourceKind.TextureReadOnly,
ShaderStages.Fragment),
new ResourceLayoutElementDescription(
samplerElement.Name,
ResourceKind.Sampler,
ShaderStages.Fragment)))));
ResourceLayoutElementDescription textureElement = layout.Elements.First(e => e.Kind == ResourceKind.TextureReadOnly || e.Kind == ResourceKind.TextureReadWrite);

if (layout.Elements.All(e => e.Kind != ResourceKind.Sampler))
throw new InvalidOperationException($"Texture {textureElement.Name} has no associated sampler.");

textureLayouts.Add(new VeldridUniformLayout(set, renderer.Factory.CreateResourceLayout(layout)));
}
else if (layout.Elements[0].Kind == ResourceKind.UniformBuffer)
{
uniformLayouts[layout.Elements[0].Name] = new VeldridUniformLayout(
set,
renderer.Factory.CreateResourceLayout(
new ResourceLayoutDescription(
new ResourceLayoutElementDescription(
layout.Elements[0].Name,
ResourceKind.UniformBuffer,
ShaderStages.Fragment | ShaderStages.Vertex))));
}
uniformLayouts[layout.Elements[0].Name] = new VeldridUniformLayout(set, renderer.Factory.CreateResourceLayout(layout));
}

Logger.Log(cached
? $"🖍️ Shader {name} loaded from cache!"
: $"🖍️ Shader {name} compiled!");
}
catch (SpirvCompilationException e)
catch (Exception e)
{
Logger.Error(e, $"🖍️ Failed to initialise shader {name}");
throw;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Automatically included for every fragment shader.

#ifndef INTERNAL_FRAGMENT_OUTPUT_H
#define INTERNAL_FRAGMENT_OUTPUT_H

{{ fragment_output_layout }}

void main()
Expand All @@ -8,4 +11,6 @@ void main()

// Ensure no fragment input is culled out from the shader by passing them in the output.
{{ fragment_output_assignment }}
}
}

#endif