Opened 6 years ago
Last modified 6 years ago
#6 accepted 작업
SPIRV 리플랙션 / texture
Reported by: | Hongtae Kim | Owned by: | Hongtae Kim |
---|---|---|---|
Priority: | 사소 | Milestone: | pipelineReflection |
Component: | Graphics/Compute Pipeline | Version: | 2.0 |
Keywords: | Cc: |
Description
GLSL
vertex shader
#version 450 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_420pack : enable layout (location = 0) in vec3 inPos; layout (location = 1) in vec2 inUV; layout (location = 2) in vec3 inNormal; layout (binding = 0) uniform UBO { mat4 projection; mat4 model; vec4 viewPos; float lodBias; } ubo; layout (location = 0) out vec2 outUV; layout (location = 1) out float outLodBias; layout (location = 2) out vec3 outNormal; layout (location = 3) out vec3 outViewVec; layout (location = 4) out vec3 outLightVec; out gl_PerVertex { vec4 gl_Position; }; void main() { outUV = inUV; outLodBias = ubo.lodBias; vec3 worldPos = vec3(ubo.model * vec4(inPos, 1.0)); gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); vec4 pos = ubo.model * vec4(inPos, 1.0); outNormal = mat3(inverse(transpose(ubo.model))) * inNormal; vec3 lightPos = vec3(0.0); vec3 lPos = mat3(ubo.model) * lightPos.xyz; outLightVec = lPos - pos.xyz; outViewVec = ubo.viewPos.xyz - pos.xyz; }
fragment shader
#version 450 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_420pack : enable layout (binding = 1) uniform sampler2D samplerColor; layout (location = 0) in vec2 inUV; layout (location = 1) in float inLodBias; layout (location = 2) in vec3 inNormal; layout (location = 3) in vec3 inViewVec; layout (location = 4) in vec3 inLightVec; layout (location = 0) out vec4 outFragColor; void main() { vec4 color = texture(samplerColor, inUV, inLodBias); vec3 N = normalize(inNormal); vec3 L = normalize(inLightVec); vec3 V = normalize(inViewVec); vec3 R = reflect(-L, N); vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0); float specular = pow(max(dot(R, V), 0.0), 16.0) * color.a; outFragColor = vec4(diffuse * color.rgb + specular, 1.0); }
Change History (8)
comment:1 Changed 6 years ago by
comment:2 Changed 6 years ago by
Apple Metal
MTLRenderPipelineReflection
RenderPipelineReflection: <MTLRenderPipelineReflectionInternal: 0x604000084380> Vertex Arguments: argumentsCount = 2 Argument 0: <MTLBufferArgument: 0x6040000855a0> Name = vertexBuffer.0 Type = MTLArgumentTypeBuffer Access = MTLArgumentAccessReadOnly LocationIndex = 30 IsActive = 1 ArrayLength = 1 TypeInfo = DataType = MTLDataTypePointer ElementType = MTLDataTypeStruct Access = MTLArgumentAccessReadOnly Alignment = 4 DataSize = 32 Alignment = 4 DataSize = 32 DataType = MTLDataTypeStruct Argument 1: <MTLBufferArgument: 0x604000085aa0> Name = ubo Type = MTLArgumentTypeBuffer Access = MTLArgumentAccessReadOnly LocationIndex = 0 IsActive = 1 ArrayLength = 1 TypeInfo = DataType = MTLDataTypePointer ElementType = MTLDataTypeStruct ElementTypeDescription = <MTLStructTypeInternal: 0x604000244020> DataType = MTLDataTypeStruct 0 <MTLStructMemberInternal: 0x604000086cc0> Name = projection Offset = 0 DataType = MTLDataTypeFloat4x4 ArgumentIndex = 0 TypeInfo = nil 1 <MTLStructMemberInternal: 0x604000086090> Name = model Offset = 64 DataType = MTLDataTypeFloat4x4 ArgumentIndex = 0 TypeInfo = nil 2 <MTLStructMemberInternal: 0x604000086ef0> Name = viewPos Offset = 128 DataType = MTLDataTypeFloat4 ArgumentIndex = 0 TypeInfo = nil 3 <MTLStructMemberInternal: 0x604000087030> Name = lodBias Offset = 144 DataType = MTLDataTypeFloat ArgumentIndex = 0 TypeInfo = nil Access = MTLArgumentAccessReadOnly Alignment = 256 DataSize = 160 Alignment = 256 DataSize = 160 DataType = MTLDataTypeStruct Fragment Arguments: argumentsCount = 2 Argument 0: <MTLTextureArgument: 0x604000087580> Name = samplerColor Type = MTLArgumentTypeTexture Access = MTLArgumentAccessReadOnly LocationIndex = 1 IsActive = 1 ArrayLength = 1 TypeInfo = DataType = MTLDataTypeTexture TextureDataType = MTLDataTypeFloat TextureType = MTLTextureType2D Access = MTLArgumentAccessReadOnly IsDepthTexture = 0 TextureType = MTLTextureType2D TextureDataType = MTLDataTypeFloat IsDepthTexture = 0 Argument 1: <MTLArgumentInternal: 0x604000272380> Name = samplerColorSmplr Type = MTLArgumentTypeSampler Access = MTLArgumentAccessReadOnly LocationIndex = 1 IsActive = 1 ArrayLength = 1
comment:3 Changed 6 years ago by
DKGL (mac)
Vertex Stage-Input Attributes
TestApp1_macOS[85247:19036511] [V] VertexFunction.VertexAttributes: 3 TestApp1_macOS[85247:19036511] [V] --> VertexAttribute[0]: "inPos" (location:0) TestApp1_macOS[85247:19036511] [V] --> VertexAttribute[1]: "inUV" (location:1) TestApp1_macOS[85247:19036511] [V] --> VertexAttribute[2]: "inNormal" (location:2)
PipelineReflection?
TestApp1_macOS[85247:19036511] [V] PipelineReflection.VertexResources: 1 TestApp1_macOS[85247:19036511] [I] ShaderResource: ubo (set=0, binding=0) TestApp1_macOS[85247:19036511] [I] +Type:Buffer, Access:ReadOnly, Enabled:1 Alignment:256, Size:160 TestApp1_macOS[85247:19036511] [I] +TypeKey: ubo (struct) TestApp1_macOS[85247:19036511] [I] + projection (Float4x4, Offset: 0, Size: 24640) TestApp1_macOS[85247:19036511] [I] + model (Float4x4, Offset: 64, Size: 24640) TestApp1_macOS[85247:19036511] [I] + viewPos (Float4, Offset: 128, Size: 24640) TestApp1_macOS[85247:19036511] [I] + lodBias (Float, Offset: 144, Size: 24640) TestApp1_macOS[85247:19036511] [V] PipelineReflection.FragmentResources: 2 TestApp1_macOS[85247:19036511] [I] ShaderResource: samplerColor (set=0, binding=1) TestApp1_macOS[85247:19036511] [I] +Type:Texture, Access:ReadOnly, Enabled:1 Alignment:494728, Size:24640 TestApp1_macOS[85247:19036511] [I] ShaderResource: samplerColorSmplr (set=0, binding=1) TestApp1_macOS[85247:19036511] [I] +Type:Sampler, Access:ReadOnly, Enabled:1 Alignment:494728, Size:24640
comment:4 Changed 6 years ago by
DKGL (windows)
Vertex Stage-Input Attributes
[35228:47172 V] VertexFunction.VertexAttributes: 3 [35228:47172 V] --> VertexAttribute[0]: "inUV" (location:1) [35228:47172 V] --> VertexAttribute[1]: "inPos" (location:0) [35228:47172 V] --> VertexAttribute[2]: "inNormal" (location:2)
PipelineReflection?
[35228:47172 V] PipelineReflection.VertexResources: 1 [35228:47172 I] ShaderResource: ubo (set=0, binding=0) [35228:47172 I] +Type:Buffer, Access:ReadOnly, Enabled:1 Alignment:0, Size:148 [35228:47172 I] +TypeKey: ubo (struct) [35228:47172 I] + projection (Float4x4, Offset: 0, Size: 64) [35228:47172 I] + model (Float4x4, Offset: 64, Size: 64) [35228:47172 I] + viewPos (Float4, Offset: 128, Size: 16) [35228:47172 I] + lodBias (Float, Offset: 144, Size: 4) [35228:47172 V] PipelineReflection.FragmentResources: 1 [35228:47172 I] ShaderResource: samplerColor (set=0, binding=1) [35228:47172 I] +Type:Texture, Access:ReadOnly, Enabled:1 Alignment:0, Size:0
comment:5 Changed 6 years ago by
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER 는 Apple Metal 에서 어떻게 처리를 해야 하나..
comment:6 Changed 6 years ago by
The VkDescriptorSetLayoutBinding::binding members of the elements of the pBindings array must each have different values.
https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf (page 62)
- Vulkan 에서는 VkDescriptorType? 과 관계없이 binding 은 고유해야 함.
- Apple Metal 에서는 buffer, sampler, texture 타입 내에서만 고유해야 함. 서로 다른 타입이면 index 가 중복이 가능.
TODO
Metal 에서 중복된 인덱스의 Sampler / Texture 경우엔 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER 으로 처리
comment:7 Changed 6 years ago by
DKShaderResource::TypeSampledTexture? 타입 추가.
Metal 에서는 sampler 와 texture 가 동일한 binding 일 경우에 COMBINED_IMAGE_SAMPLER (SampledImage?) 로 간주.
comment:8 Changed 6 years ago by
Priority: | 치명적 → 사소 |
---|---|
Status: | assigned → accepted |
Note: See
TracTickets for help on using
tickets.
Apple Metal
Vertex Shader
Fragment Shader