mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-09 22:00:05 +00:00
HLSL: Add test for passing down separate image and samplers to functions.
This commit is contained in:
parent
f081fe1125
commit
59ad08429b
@ -0,0 +1,40 @@
|
||||
Texture2D<float4> uDepth;
|
||||
SamplerComparisonState uSampler;
|
||||
SamplerState uSampler1;
|
||||
|
||||
static float FragColor;
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
float samp2(Texture2D<float4> t, SamplerComparisonState s)
|
||||
{
|
||||
return t.SampleCmp(s, float3(1.0f, 1.0f, 1.0f).xy, float3(1.0f, 1.0f, 1.0f).z);
|
||||
}
|
||||
|
||||
float samp3(Texture2D<float4> t, SamplerState s)
|
||||
{
|
||||
return t.Sample(s, float2(1.0f, 1.0f)).x;
|
||||
}
|
||||
|
||||
float samp(Texture2D<float4> t, SamplerComparisonState s, SamplerState s1)
|
||||
{
|
||||
float r0 = samp2(t, s);
|
||||
float r1 = samp3(t, s1);
|
||||
return r0 + r1;
|
||||
}
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
FragColor = samp(uDepth, uSampler, uSampler1);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main()
|
||||
{
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
29
shaders-hlsl/frag/combined-texture-sampler-shadow.frag
Normal file
29
shaders-hlsl/frag/combined-texture-sampler-shadow.frag
Normal file
@ -0,0 +1,29 @@
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(set = 0, binding = 0) uniform mediump samplerShadow uSampler;
|
||||
layout(set = 0, binding = 1) uniform mediump sampler uSampler1;
|
||||
layout(set = 0, binding = 2) uniform texture2D uDepth;
|
||||
layout(location = 0) out float FragColor;
|
||||
|
||||
float samp2(texture2D t, mediump samplerShadow s)
|
||||
{
|
||||
return texture(sampler2DShadow(t, s), vec3(1.0));
|
||||
}
|
||||
|
||||
float samp3(texture2D t, mediump sampler s)
|
||||
{
|
||||
return texture(sampler2D(t, s), vec2(1.0)).x;
|
||||
}
|
||||
|
||||
float samp(texture2D t, mediump samplerShadow s, mediump sampler s1)
|
||||
{
|
||||
float r0 = samp2(t, s);
|
||||
float r1 = samp3(t, s1);
|
||||
return r0 + r1;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = samp(uDepth, uSampler, uSampler1);
|
||||
}
|
@ -43,7 +43,39 @@ static bool opcode_is_sign_invariant(Op opcode)
|
||||
}
|
||||
}
|
||||
|
||||
string CompilerHLSL::image_type_hlsl(const SPIRType &type)
|
||||
string CompilerHLSL::image_type_hlsl_modern(const SPIRType &type)
|
||||
{
|
||||
auto &imagetype = get<SPIRType>(type.image.type);
|
||||
const char *dim = nullptr;
|
||||
switch (type.image.dim)
|
||||
{
|
||||
case Dim1D:
|
||||
dim = "1D";
|
||||
break;
|
||||
case Dim2D:
|
||||
dim = "2D";
|
||||
break;
|
||||
case Dim3D:
|
||||
dim = "3D";
|
||||
break;
|
||||
case DimCube:
|
||||
dim = "Cube";
|
||||
break;
|
||||
case DimRect:
|
||||
SPIRV_CROSS_THROW("Rectangle texture support is not yet implemented for HLSL"); // TODO
|
||||
case DimBuffer:
|
||||
// Buffer/RWBuffer.
|
||||
SPIRV_CROSS_THROW("Buffer/RWBuffer support is not yet implemented for HLSL"); // TODO
|
||||
case DimSubpassData:
|
||||
// This should be implemented same way as desktop GL. Fetch on a 2D texture based on int2(SV_Position).
|
||||
SPIRV_CROSS_THROW("Subpass data support is not yet implemented for HLSL"); // TODO
|
||||
}
|
||||
uint32_t components = 4;
|
||||
const char *arrayed = type.image.arrayed ? "Array" : "";
|
||||
return join("Texture", dim, arrayed, "<", type_to_glsl(imagetype), components, ">");
|
||||
}
|
||||
|
||||
string CompilerHLSL::image_type_hlsl_legacy(const SPIRType &type)
|
||||
{
|
||||
auto &imagetype = get<SPIRType>(type.image.type);
|
||||
string res;
|
||||
@ -105,17 +137,21 @@ string CompilerHLSL::image_type_hlsl(const SPIRType &type)
|
||||
if (type.image.ms)
|
||||
res += "MS";
|
||||
if (type.image.arrayed)
|
||||
{
|
||||
if (is_legacy_desktop())
|
||||
require_extension("GL_EXT_texture_array");
|
||||
res += "Array";
|
||||
}
|
||||
if (type.image.depth)
|
||||
res += "Shadow";
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
string CompilerHLSL::image_type_hlsl(const SPIRType &type)
|
||||
{
|
||||
if (options.shader_model <= 30)
|
||||
return image_type_hlsl_legacy(type);
|
||||
else
|
||||
return image_type_hlsl_modern(type);
|
||||
}
|
||||
|
||||
string CompilerHLSL::type_to_glsl(const SPIRType &type)
|
||||
{
|
||||
// Ignore the pointer type since GLSL doesn't have pointers.
|
||||
@ -134,7 +170,7 @@ string CompilerHLSL::type_to_glsl(const SPIRType &type)
|
||||
return image_type_hlsl(type);
|
||||
|
||||
case SPIRType::Sampler:
|
||||
return "sampler";
|
||||
return type.image.depth ? "SamplerComparisonState" : "SamplerState";
|
||||
|
||||
case SPIRType::Void:
|
||||
return "void";
|
||||
@ -1459,34 +1495,7 @@ void CompilerHLSL::emit_modern_uniform(const SPIRVariable &var)
|
||||
case SPIRType::SampledImage:
|
||||
case SPIRType::Image:
|
||||
{
|
||||
auto &imagetype = get<SPIRType>(type.image.type);
|
||||
string dim;
|
||||
switch (type.image.dim)
|
||||
{
|
||||
case Dim1D:
|
||||
dim = "1D";
|
||||
break;
|
||||
case Dim2D:
|
||||
dim = "2D";
|
||||
break;
|
||||
case Dim3D:
|
||||
dim = "3D";
|
||||
break;
|
||||
case DimCube:
|
||||
dim = "Cube";
|
||||
break;
|
||||
case DimRect:
|
||||
SPIRV_CROSS_THROW("Rectangle texture support is not yet implemented for HLSL"); // TODO
|
||||
case DimBuffer:
|
||||
// Buffer/RWBuffer.
|
||||
SPIRV_CROSS_THROW("Buffer/RWBuffer support is not yet implemented for HLSL"); // TODO
|
||||
case DimSubpassData:
|
||||
// This should be implemented same way as desktop GL. Fetch on a 2D texture based on int2(SV_Position).
|
||||
SPIRV_CROSS_THROW("Subpass data support is not yet implemented for HLSL"); // TODO
|
||||
}
|
||||
string arrayed = type.image.arrayed ? "Array" : "";
|
||||
uint32_t components = imagetype.image.depth ? 1 : 4;
|
||||
statement("Texture", dim, arrayed, "<", type_to_glsl(imagetype), components, "> ", to_name(var.self), ";");
|
||||
statement(image_type_hlsl_modern(type), " ", to_name(var.self), ";");
|
||||
|
||||
if (type.basetype == SPIRType::SampledImage)
|
||||
{
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
private:
|
||||
std::string type_to_glsl(const SPIRType &type) override;
|
||||
std::string image_type_hlsl(const SPIRType &type);
|
||||
std::string image_type_hlsl_modern(const SPIRType &type);
|
||||
std::string image_type_hlsl_legacy(const SPIRType &type);
|
||||
void emit_function_prototype(SPIRFunction &func, uint64_t return_flags) override;
|
||||
void emit_hlsl_entry_point();
|
||||
void emit_header() override;
|
||||
|
Loading…
Reference in New Issue
Block a user