Prefer plain texture2D in legacy es vertex shaders

WebGL supports lod texture funcs only in fragment
shaders but SPIR-V supports only lod texture funcs
in vertex shaders. This reverts calls which were
forced (infered from using a 0 constant) to use
an lod to plain calls in vertex shaders when
using legacy es.
This commit is contained in:
Robert Konrad 2017-03-23 09:55:32 +01:00
parent ecc6ef6937
commit 3f74503aca
5 changed files with 31 additions and 19 deletions

View File

@ -2409,7 +2409,7 @@ void CompilerGLSL::emit_quaternary_func_op(uint32_t result_type, uint32_t result
inherit_expression_dependencies(result_id, op3);
}
string CompilerGLSL::legacy_tex_op(const std::string &op, const SPIRType &imgtype)
string CompilerGLSL::legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t lod)
{
const char *type;
switch (imgtype.image.dim)
@ -2437,22 +2437,32 @@ string CompilerGLSL::legacy_tex_op(const std::string &op, const SPIRType &imgtyp
break;
}
auto *lod_constant = maybe_get<SPIRConstant>(lod);
bool zero_lod = lod_constant && lod_constant->scalar_f32() == 0.0f;
if (op == "textureLod" || op == "textureProjLod")
{
if (is_legacy_es())
if (is_legacy_es() && !zero_lod)
require_extension("GL_EXT_shader_texture_lod");
else if (is_legacy())
else if (is_legacy() && !is_legacy_es())
require_extension("GL_ARB_shader_texture_lod");
}
if (op == "texture")
return join("texture", type);
else if (op == "textureLod")
return join("texture", type, is_legacy_es() ? "LodEXT" : "Lod");
else if (op == "textureLod") {
if (is_legacy_es() && zero_lod)
return join("texture", type);
else
return join("texture", type, is_legacy_es() ? "LodEXT" : "Lod");
}
else if (op == "textureProj")
return join("texture", type, "Proj");
else if (op == "textureProjLod")
return join("texture", type, is_legacy_es() ? "ProjLodEXT" : "ProjLod");
if (is_legacy_es() && zero_lod)
return join("texture", type);
else
return join("texture", type, is_legacy_es() ? "ProjLodEXT" : "ProjLod");
else
{
SPIRV_CROSS_THROW(join("Unsupported legacy texture op: ", op));
@ -2775,7 +2785,7 @@ void CompilerGLSL::emit_texture_op(const Instruction &i)
string expr;
bool forward = false;
expr += to_function_name(img, imgtype, !!fetch, !!gather, !!proj, !!coffsets, (!!coffset || !!offset),
(!!grad_x || !!grad_y), !!lod, !!dref);
(!!grad_x || !!grad_y), !!lod, !!dref, lod);
expr += "(";
expr += to_function_args(img, imgtype, fetch, gather, proj, coord, coord_components, dref, grad_x, grad_y, lod,
coffset, offset, bias, comp, sample, &forward);
@ -2787,7 +2797,7 @@ void CompilerGLSL::emit_texture_op(const Instruction &i)
// Returns the function name for a texture sampling function for the specified image and sampling characteristics.
// For some subclasses, the function is a method on the specified image.
string CompilerGLSL::to_function_name(uint32_t, const SPIRType &imgtype, bool is_fetch, bool is_gather, bool is_proj,
bool has_array_offsets, bool has_offset, bool has_grad, bool has_lod, bool)
bool has_array_offsets, bool has_offset, bool has_grad, bool has_lod, bool, uint32_t lod)
{
string fname;
@ -2812,7 +2822,7 @@ string CompilerGLSL::to_function_name(uint32_t, const SPIRType &imgtype, bool is
if (has_offset)
fname += "Offset";
return is_legacy() ? legacy_tex_op(fname, imgtype) : fname;
return is_legacy() ? legacy_tex_op(fname, imgtype, lod) : fname;
}
// Returns the function args for a texture sampling function for the specified image and sampling characteristics.
@ -2894,9 +2904,14 @@ string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &, bool, bool
if (lod)
{
forward = forward && should_forward(lod);
farg_str += ", ";
farg_str += to_expression(lod);
auto *lod_constant = maybe_get<SPIRConstant>(lod);
bool zero_lod = lod_constant && lod_constant->scalar_f32() == 0.0f;
if (!is_legacy_es() || !zero_lod)
{
forward = forward && should_forward(lod);
farg_str += ", ";
farg_str += to_expression(lod);
}
}
if (coffset)

View File

@ -170,7 +170,7 @@ protected:
virtual std::string to_func_call_arg(uint32_t id);
virtual std::string to_function_name(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
bool is_proj, bool has_array_offsets, bool has_offset, bool has_grad,
bool has_lod, bool has_dref);
bool has_lod, bool has_dref, uint32_t lod);
virtual std::string to_function_args(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
bool is_proj, uint32_t coord, uint32_t coord_components, uint32_t dref,
uint32_t grad_x, uint32_t grad_y, uint32_t lod, uint32_t coffset,
@ -384,7 +384,7 @@ protected:
void replace_fragment_output(SPIRVariable &var);
void replace_fragment_outputs();
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype);
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t lod);
uint32_t indent = 0;

View File

@ -1091,9 +1091,6 @@ void CompilerHLSL::emit_texture_op(const Instruction &i)
if (coffset || offset)
texop += "Offset";
if (is_legacy())
texop = legacy_tex_op(texop, imgtype);
expr += texop;
expr += "(";
expr += to_expression(img);

View File

@ -989,7 +989,7 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, uint64_t)
// Returns the texture sampling function string for the specified image and sampling characteristics.
string CompilerMSL::to_function_name(uint32_t img, const SPIRType &, bool is_fetch, bool is_gather, bool, bool, bool,
bool, bool, bool has_dref)
bool, bool, bool has_dref, uint32_t)
{
// Texture reference
string fname = to_expression(img) + ".";

View File

@ -140,7 +140,7 @@ protected:
std::string to_name(uint32_t id, bool allow_alias = true) const override;
std::string to_function_name(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather, bool is_proj,
bool has_array_offsets, bool has_offset, bool has_grad, bool has_lod,
bool has_dref) override;
bool has_dref, uint32_t lod) override;
std::string to_function_args(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather, bool is_proj,
uint32_t coord, uint32_t coord_components, uint32_t dref, uint32_t grad_x,
uint32_t grad_y, uint32_t lod, uint32_t coffset, uint32_t offset, uint32_t bias,