Open ghost opened 7 years ago
glslc now supports -fauto-bind-uniforms, which automatically assigns bindings to uniform variables that don't have an explicit binding. This applies to textures, images, and samplers.
An example integration test is in https://github.com/google/shaderc/blob/master/glslc/test/option_fauto_bind_uniforms.py
That shows that the sampler gets a binding assigned to it.
Does this satisfy your need?
I forgot you mentioned OpenGL. Use --target-env=opengl to target OpenGL.
Example: x.vert is:
#version 450
buffer B
{ int x; int y; } my_buf;
void main() {
int x = my_buf.x;
}
Then glslc -S -o - --target-env=opengl x.vert
produces:
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main" %gl_VertexID %gl_InstanceID
OpSource GLSL 450
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpName %main "main"
OpName %x "x"
OpName %B "B"
OpMemberName %B 0 "x"
OpMemberName %B 1 "y"
OpName %my_buf "my_buf"
OpName %gl_VertexID "gl_VertexID"
OpName %gl_InstanceID "gl_InstanceID"
OpMemberDecorate %B 0 Offset 0
OpMemberDecorate %B 1 Offset 4
OpDecorate %B BufferBlock
OpDecorate %my_buf DescriptorSet 0
OpDecorate %gl_VertexID BuiltIn VertexId
OpDecorate %gl_InstanceID BuiltIn InstanceId
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%B = OpTypeStruct %int %int
%_ptr_Uniform_B = OpTypePointer Uniform %B
%my_buf = OpVariable %_ptr_Uniform_B Uniform
%int_0 = OpConstant %int 0
%_ptr_Uniform_int = OpTypePointer Uniform %int
%_ptr_Input_int = OpTypePointer Input %int
%gl_VertexID = OpVariable %_ptr_Input_int Input
%gl_InstanceID = OpVariable %_ptr_Input_int Input
%main = OpFunction %void None %3
%5 = OpLabel
%x = OpVariable %_ptr_Function_int Function
%14 = OpAccessChain %_ptr_Uniform_int %my_buf %int_0
%15 = OpLoad %int %14
OpStore %x %15
OpReturn
OpFunctionEnd
You can see that my_buf has a DescriptorSet decoration, but no Binding decoration.
Is that what you mean?
I mean bindless textures
Yes. Sorry I was confused. You mean support for this extension: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_bindless_texture.txt
Shaderc depends on github.com/KhronosGroup/glslang for core compilation features for GLSL. So the functionality has to be added there. If I read glslang's test code, bindless textures are not supported. I see you already asked in that project, in https://github.com/KhronosGroup/glslang/issues/497
In this case, the underlying functionality would have to be made available both in SPIR-V (what operations are used in SPIR-V), and in the target environment (does OpenGL with SPIR-V extensions support it; or does Vulkan support this). I believe there is no way in SPIR-V to produce an image object from a 64bit handle. So as describe in the glslang bug, first SPIR-V extension would need to be written to add that functionality, and a corresponding extension to the client API to enable that SPIR-V.
I ask another question. How to bind array of 256 textures with different sizes and formats?
I assume you mean for Vulkan? That's a Vulkan question.
The closest thing would be a texture array, but those must share a common format.
For example, see https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt or you can infer it from the Vulkan specification.
We preparing to support SPIR-V, but I want ask question. Will shaderc and SPV support bindless texture? When I tried to compile, I got errors that extension not support.