Bug 1624396 - add missing texture rectangle support to SWGL. r=jrmuizel

Depends on D67959

Differential Revision: https://phabricator.services.mozilla.com/D67960

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Lee Salzman 2020-03-24 03:41:38 +00:00
Родитель 7fe8ae3ba8
Коммит 358c8f7c7c
3 изменённых файлов: 44 добавлений и 4 удалений

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

@ -3374,14 +3374,14 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
"texture",
None,
Type::new(Vec4),
vec![Type::new(Sampler2D), Type::new(Vec3)],
vec![Type::new(Sampler2D), Type::new(Vec2)],
);
declare_function(
state,
"texture",
None,
Type::new(Vec4),
vec![Type::new(Sampler2D), Type::new(Vec2)],
vec![Type::new(Sampler2DRect), Type::new(Vec2)],
);
declare_function(
state,
@ -3411,6 +3411,13 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(IVec2),
vec![Type::new(Sampler2D), Type::new(Int)],
);
declare_function(
state,
"textureSize",
None,
Type::new(IVec2),
vec![Type::new(Sampler2DRect), Type::new(Int)],
);
declare_function(
state,

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

@ -319,6 +319,7 @@ fn write_program_samplers(state: &mut OutputState, uniform_indices: &UniformIndi
for (name, (_, tk, storage)) in uniform_indices.iter() {
match tk {
hir::TypeKind::Sampler2D
| hir::TypeKind::Sampler2DRect
| hir::TypeKind::ISampler2D
| hir::TypeKind::Sampler2DArray => {
write!(state, " ");
@ -344,6 +345,7 @@ fn write_program_samplers(state: &mut OutputState, uniform_indices: &UniformIndi
for (name, (index, tk, _)) in uniform_indices.iter() {
match tk {
hir::TypeKind::Sampler2D
| hir::TypeKind::Sampler2DRect
| hir::TypeKind::ISampler2D
| hir::TypeKind::Sampler2DArray => {
write!(state, " case {}:\n", index);
@ -370,7 +372,8 @@ fn write_bind_textures(state: &mut OutputState, uniforms: &[hir::SymRef]) {
hir::SymDecl::Global(hir::StorageClass::Sampler(_format), _, ty, _) => {
let name = sym.name.as_str();
match ty.kind {
hir::TypeKind::Sampler2D => write!(state,
hir::TypeKind::Sampler2D
| hir::TypeKind::Sampler2DRect => write!(state,
" self->{0} = lookup_sampler(&prog->samplers.{0}_impl, prog->samplers.{0}_slot);\n",
name),
hir::TypeKind::ISampler2D => write!(state,
@ -2678,7 +2681,8 @@ fn define_texel_fetch_ptr(
show_indent(state);
if let hir::SymDecl::Global(_, _, ty, _) = &sampler_sym.decl {
match ty.kind {
hir::TypeKind::Sampler2D => {
hir::TypeKind::Sampler2D
| hir::TypeKind::Sampler2DRect => {
write!(
state,
"vec4_scalar* {}_{}_fetch = ",

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

@ -427,6 +427,10 @@ vec2_scalar make_vec2(float n) { return vec2_scalar{n, n}; }
vec2_scalar make_vec2(float x, float y) { return vec2_scalar{x, y}; }
vec2_scalar make_vec2(int32_t x, int32_t y) {
return vec2_scalar{float(x), float(y)};
}
template <typename N>
vec2 make_vec2(const N& n) {
return vec2(n);
@ -1763,6 +1767,9 @@ typedef isampler2D_impl* isampler2D;
struct isampler2DRGBA32I_impl : isampler2D_impl {};
typedef isampler2DRGBA32I_impl* isampler2DRGBA32I;
struct sampler2DRect_impl : samplerCommon, samplerFilter {};
typedef sampler2DRect_impl* sampler2DRect;
struct mat4_scalar;
struct mat2_scalar {
@ -2270,6 +2277,13 @@ vec4_scalar texelFetch(sampler2DR8 sampler, ivec2_scalar P, int lod) {
0.0f, 0.0f};
}
vec4 texelFetch(sampler2DRect sampler, ivec2 P) {
P = clamp2D(P, sampler);
assert(sampler->format == TextureFormat::RGBA8);
I32 offset = P.x + P.y * sampler->stride;
return fetchOffsetsRGBA8(sampler, offset);
}
vec4 texelFetch(sampler2DArray sampler, ivec3 P, int lod) {
P = clamp2DArray(P, sampler);
if (sampler->format == TextureFormat::RGBA32F) {
@ -2643,6 +2657,17 @@ vec4 texture(sampler2D sampler, vec2 P) {
}
}
vec4 texture(sampler2DRect sampler, vec2 P) {
assert(sampler->format == TextureFormat::RGBA8);
if (sampler->filter == TextureFilter::LINEAR) {
return textureLinearRGBA8(sampler,
P * vec2_scalar{1.0f / sampler->width, 1.0f / sampler->height});
} else {
ivec2 coord(roundto(P.x, 1.0f), roundto(P.y, 1.0f));
return texelFetch(sampler, coord);
}
}
vec4 texture(sampler2DArray sampler, vec3 P, Float layer) {
assert(0);
return vec4();
@ -2682,6 +2707,10 @@ ivec2_scalar textureSize(sampler2D sampler, int) {
return ivec2_scalar{int32_t(sampler->width), int32_t(sampler->height)};
}
ivec2_scalar textureSize(sampler2DRect sampler) {
return ivec2_scalar{int32_t(sampler->width), int32_t(sampler->height)};
}
ivec4 ivec2::sel(XYZW c1, XYZW c2, XYZW c3, XYZW c4) {
return ivec4(select(c1), select(c2), select(c3), select(c4));
}