Fix case where samplerBuffer is emitted without combined sampler.

This commit is contained in:
Hans-Kristian Arntzen 2017-04-02 10:54:11 +02:00
Родитель ae8de51138
Коммит 543e380d90
6 изменённых файлов: 91 добавлений и 7 удалений

Просмотреть файл

@ -0,0 +1,20 @@
#version 450
layout(rgba32f) uniform writeonly imageBuffer RWTex;
uniform samplerBuffer Tex;
layout(location = 0) out vec4 _entryPointOutput;
vec4 _main()
{
vec4 storeTemp = vec4(1.0, 2.0, 3.0, 4.0);
imageStore(RWTex, 20, storeTemp);
return texelFetch(Tex, 10);
}
void main()
{
vec4 _28 = _main();
_entryPointOutput = _28;
}

Просмотреть файл

@ -0,0 +1,59 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 1
; Bound: 36
; Schema: 0
OpCapability Shader
OpCapability SampledBuffer
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %_entryPointOutput
OpExecutionMode %main OriginUpperLeft
OpName %main "main"
OpName %_main_ "@main("
OpName %storeTemp "storeTemp"
OpName %RWTex "RWTex"
OpName %Tex "Tex"
OpName %_entryPointOutput "@entryPointOutput"
OpDecorate %RWTex DescriptorSet 0
OpDecorate %Tex DescriptorSet 0
OpDecorate %_entryPointOutput Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%8 = OpTypeFunction %v4float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%13 = OpConstant %float 1
%14 = OpConstant %float 2
%15 = OpConstant %float 3
%16 = OpConstant %float 4
%17 = OpConstantComposite %v4float %13 %14 %15 %16
%18 = OpTypeImage %float Buffer 0 0 0 2 Rgba32f
%_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
%RWTex = OpVariable %_ptr_UniformConstant_18 UniformConstant
%int = OpTypeInt 32 1
%23 = OpConstant %int 20
%25 = OpTypeImage %float Buffer 0 0 0 1 Rgba32f
%_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
%Tex = OpVariable %_ptr_UniformConstant_25 UniformConstant
%29 = OpConstant %int 10
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_entryPointOutput = OpVariable %_ptr_Output_v4float Output
%main = OpFunction %void None %3
%5 = OpLabel
%35 = OpFunctionCall %v4float %_main_
OpStore %_entryPointOutput %35
OpReturn
OpFunctionEnd
%_main_ = OpFunction %v4float None %8
%10 = OpLabel
%storeTemp = OpVariable %_ptr_Function_v4float Function
OpStore %storeTemp %17
%21 = OpLoad %18 %RWTex
%24 = OpLoad %v4float %storeTemp
OpImageWrite %21 %23 %24
%28 = OpLoad %25 %Tex
%30 = OpImageFetch %v4float %28 %29
OpReturnValue %30
OpFunctionEnd

Просмотреть файл

@ -1411,7 +1411,6 @@ void Compiler::parse(const Instruction &instruction)
break;
}
// Not really used.
case OpTypeSampler:
{
uint32_t id = ops[0];

Просмотреть файл

@ -996,7 +996,8 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var)
attr.push_back(ssbo_is_std430_packing(type) ? "std430" : "std140");
// For images, the type itself adds a layout qualifer.
if (type.basetype == SPIRType::Image)
// Only emit the format for storage images.
if (type.basetype == SPIRType::Image && type.image.sampled == 2)
{
const char *fmt = format_to_glsl(type.image.format);
if (fmt)
@ -1597,9 +1598,11 @@ void CompilerGLSL::emit_resources()
// If we're remapping separate samplers and images, only emit the combined samplers.
if (skip_separate_image_sampler)
{
// Sampler buffers are always used without a sampler, and they will also work in regular GL.
bool sampler_buffer = type.basetype == SPIRType::Image && type.image.dim == DimBuffer;
bool separate_image = type.basetype == SPIRType::Image && type.image.sampled == 1;
bool separate_sampler = type.basetype == SPIRType::Sampler;
if (separate_image || separate_sampler)
if (!sampler_buffer && (separate_image || separate_sampler))
continue;
}
@ -5918,7 +5921,13 @@ string CompilerGLSL::image_type_glsl(const SPIRType &type)
// If we're emulating subpassInput with samplers, force sampler2D
// so we don't have to specify format.
if (type.basetype == SPIRType::Image && type.image.dim != DimSubpassData)
res += type.image.sampled == 2 ? "image" : "texture";
{
// Sampler buffers are always declared as samplerBuffer even though they might be separate images in the SPIR-V.
if (type.image.dim == DimBuffer && type.image.sampled == 1)
res += "sampler";
else
res += type.image.sampled == 2 ? "image" : "texture";
}
else
res += "sampler";
@ -5992,7 +6001,6 @@ string CompilerGLSL::type_to_glsl(const SPIRType &type)
return image_type_glsl(type);
case SPIRType::Sampler:
// Not really used.
return "sampler";
case SPIRType::Void:

Просмотреть файл

@ -61,7 +61,6 @@ string CompilerHLSL::type_to_glsl(const SPIRType &type)
return image_type_glsl(type);
case SPIRType::Sampler:
// Not really used.
return "sampler";
case SPIRType::Void:

Просмотреть файл

@ -1851,7 +1851,6 @@ string CompilerMSL::type_to_glsl(const SPIRType &type)
return image_type_glsl(type);
case SPIRType::Sampler:
// Not really used.
return "sampler";
case SPIRType::Void: