Package icyllis.arc3d.granite.shading
Class UniformHandler
java.lang.Object
icyllis.arc3d.granite.shading.UniformHandler
Class that builds a uniform block.
The uniform blocks are generally defined as:
// Anonymous block
layout(std140, binding = 0) uniform UniformBlock {
layout(offset = 0) vec4 SV_Projection;
// per-effect uniforms...
}
Per-effect uniforms are updated more frequently (generally, each draw op).
We should limit the UBO size to 128 bytes.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceMarks an integer as an opaque handle to a sampler resource.static @interfaceMarks an integer as an opaque handle to a uniform resource.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe bindings for the input descriptor set.static final intstatic final intBinding a descriptor set invalidates all higher index descriptor sets.intprotected final ShaderCapsstatic final Stringstatic final StringThe non-premultiplied paint color, when it cannot be simplified.static final StringThe 2D orthographic projection matrix has only 4 values (others are identity), so this is a vec4.static final intstatic final intLayouts.static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intaddInputSampler(short swizzle, String name) intaddSampler(byte type, String name, int manglingSuffix) final intaddUniform(int visibility, byte type, String name, int manglingSuffix) Add a uniform variable to the current program, that has visibility in one or more shaders.final intaddUniformArray(int visibility, byte type, String name, int arraySize, int manglingSuffix) Array version ofaddUniform(int, byte, String, int).voidappendSamplerDecls(int visibility, StringBuilder out) booleanappendUniformDecls(int visibility, int binding, String blockName, StringBuilder out) Append one block declaration.voidfinish(boolean reorderUniforms) static intgetAlignedOffset(int offset, byte type, int arraySize, int layout) Given the current offset into the UBO data, calculate the offset for the uniform we're trying to add taking into consideration all alignment requirements.static intgetAlignedStride(byte type, int arraySize, int layout) static intgetAlignmentMask(byte type, boolean nonArray, int layout) Returns the base alignment mask in bytes taken up in UBO for SLTypes.static intgetSize(byte type, int layout) Returns the size in bytes taken up in UBO for SLTypes.final StringgetUniformName(int handle) Shortcut for getUniformVariable(handle).getName()getUniformVariable(int handle) protected StringinputSamplerVariable(int handle) protected intinternalAddUniformArray(int visibility, byte type, String name, int arraySize, int manglingSuffix) intintsamplerVariable(int handle) uniform(int index)
-
Field Details
-
NO_MANGLE_PREFIX
- See Also:
-
PROJECTION_NAME
The 2D orthographic projection matrix has only 4 values (others are identity), so this is a vec4. Projection maps world space into clip space.- See Also:
-
PAINT_COLOR_NAME
The non-premultiplied paint color, when it cannot be simplified. This value is shared between stages and deduplicated when building uniforms.- See Also:
-
Std140Layout
public static final int Std140LayoutLayouts.- See Also:
-
Std430Layout
public static final int Std430Layout- See Also:
-
MAIN_DESC_SET
public static final int MAIN_DESC_SETBinding a descriptor set invalidates all higher index descriptor sets. We must bind in the order of this enumeration. Samplers are after Uniforms because Ops can specify GP textures as dynamic state, meaning they get rebound for each draw in a pipeline while uniforms are bound once before all the draws. We bind input attachments after samplers so those also need to be rebound if we bind new samplers.- See Also:
-
SAMPLER_DESC_SET
public static final int SAMPLER_DESC_SET- See Also:
-
INPUT_DESC_SET
public static final int INPUT_DESC_SET- See Also:
-
INPUT_BINDING
public static final int INPUT_BINDINGThe bindings for the input descriptor set.- See Also:
-
mShaderCaps
-
mUniforms
-
mSamplers
-
mCurrentOffset
public int mCurrentOffset
-
-
Constructor Details
-
UniformHandler
-
-
Method Details
-
addUniform
Add a uniform variable to the current program, that has visibility in one or more shaders. visibility is a bitfield of ShaderFlag values indicating from which shaders the uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not supported at this time. The actual uniform name will be mangled. The final uniform name can be retrieved bygetUniformName(int)with the UniformHandle. Use theaddUniformArray(int, byte, String, int, int)variant to add an array of uniforms.If the name starts with
NO_MANGLE_PREFIX, the uniform will be assigned to Render Block rather than Effect Block, which may be shared across stages and pipelines. Also, the UniformHandle and its data manager may be only visible and internally handled by implementations.- Parameters:
visibility- combination of ShaderFlags can be zero as placeholdertype- seeSLDataTypename- the raw name (pre-mangling), cannot be null or empty- Returns:
- UniformHandle either from Render Block or Effect Block
-
addUniformArray
public final int addUniformArray(int visibility, byte type, String name, int arraySize, int manglingSuffix) Array version ofaddUniform(int, byte, String, int).- Parameters:
visibility- combination of ShaderFlags, can be zero as placeholdertype- seeSLDataTypename- the raw name (pre-mangling), cannot be null or emptyarraySize- the number of elements, cannot be zero- Returns:
- UniformHandle either from Render Block or Effect Block
-
getUniformVariable
- Parameters:
handle- UniformHandle from Effect Block
-
getUniformName
Shortcut for getUniformVariable(handle).getName()- Parameters:
handle- UniformHandle from Effect Block
-
numUniforms
public int numUniforms() -
numSamplers
public int numSamplers() -
uniform
-
internalAddUniformArray
protected int internalAddUniformArray(int visibility, byte type, String name, int arraySize, int manglingSuffix) -
addSampler
-
samplerVariable
-
addInputSampler
-
inputSamplerVariable
-
finish
public void finish(boolean reorderUniforms) -
appendUniformDecls
Append one block declaration.- Parameters:
visibility- one of ShaderFlags- Returns:
- true if block is not empty
-
appendSamplerDecls
- Parameters:
visibility- one of ShaderFlags
-
getAlignmentMask
public static int getAlignmentMask(byte type, boolean nonArray, int layout) Returns the base alignment mask in bytes taken up in UBO for SLTypes.- Parameters:
type- seeSLDataTypenonArray- true for a single scalar or vector, false for an array of scalars or vectorslayout- 1 for std430 layout, 0 for std140 layout- Returns:
- base alignment mask
-
getSize
public static int getSize(byte type, int layout) Returns the size in bytes taken up in UBO for SLTypes. This includes paddings between components, but does not include paddings at the end of the element.- Parameters:
type- seeSLDataTypelayout- 1 for std430 layout, 0 for std140 layout- Returns:
- size in bytes
- See Also:
-
getAlignedOffset
public static int getAlignedOffset(int offset, byte type, int arraySize, int layout) Given the current offset into the UBO data, calculate the offset for the uniform we're trying to add taking into consideration all alignment requirements. Use aligned offset plusgetAlignedStride(byte, int, int)to get the offset to the end of the new uniform.- Parameters:
offset- the current offsettype- seeSLDataTypearraySize- seeShaderVarlayout- 1 for std430 layout, 0 for std140 layout- Returns:
- the aligned offset for the new uniform
-
getAlignedStride
public static int getAlignedStride(byte type, int arraySize, int layout) - See Also:
-