1
/**************************************************************************
3
* Copyright 2010-2021 VMware, Inc.
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
* USE OR OTHER DEALINGS IN THE SOFTWARE.
22
* The above copyright notice and this permission notice (including the
23
* next paragraph) shall be included in all copies or substantial portions
26
**************************************************************************/
29
#include "pipe/p_config.h"
31
#include "util/u_math.h"
32
#include "util/u_cpu_detect.h"
33
#include "util/u_pack_color.h"
34
#include "util/u_surface.h"
35
#include "util/u_sse.h"
40
#include "lp_state_fs.h"
41
#include "lp_linear_priv.h"
44
#if defined(PIPE_ARCH_SSE)
47
/* This file contains various special-case fastpaths which implement
48
* the entire linear pipeline in a single funciton.
50
* These include simple blits and some debug code.
52
* These functions fully implement the linear path and do not need to
53
* be combined with blending, interpolation or sampling routines.
56
/* Linear shader which implements the BLIT_RGBA shader with the
57
* additional constraints imposed by lp_setup_is_blit().
60
lp_linear_blit_rgba_blit(const struct lp_rast_state *state,
61
unsigned x, unsigned y,
62
unsigned width, unsigned height,
64
const float (*dadx)[4],
65
const float (*dady)[4],
69
const struct lp_jit_context *context = &state->jit_context;
70
const struct lp_jit_texture *texture = &context->textures[0];
75
LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
79
if (a0[0][3] != 1.0 ||
84
src_x = x + util_iround(a0[1][0]*texture->width - 0.5f);
85
src_y = y + util_iround(a0[1][1]*texture->height - 0.5f);
88
src_stride = texture->row_stride[0];
90
/* Fall back to blit_rgba() if clamping required:
94
src_x + width > texture->width ||
95
src_y + height > texture->height)
98
util_copy_rect(color, PIPE_FORMAT_B8G8R8A8_UNORM, stride,
108
/* Linear shader which implements the BLIT_RGB1 shader, with the
109
* additional constraints imposed by lp_setup_is_blit().
112
lp_linear_blit_rgb1_blit(const struct lp_rast_state *state,
113
unsigned x, unsigned y,
114
unsigned width, unsigned height,
115
const float (*a0)[4],
116
const float (*dadx)[4],
117
const float (*dady)[4],
121
const struct lp_jit_context *context = &state->jit_context;
122
const struct lp_jit_texture *texture = &context->textures[0];
127
LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
131
if (a0[0][3] != 1.0 ||
136
color += x * 4 + y * stride;
138
src_x = x + util_iround(a0[1][0]*texture->width - 0.5f);
139
src_y = y + util_iround(a0[1][1]*texture->height - 0.5f);
142
src_stride = texture->row_stride[0];
144
src += src_y * src_stride;
148
src_x + width > texture->width ||
149
src_y + height > texture->height)
152
for (y = 0; y < height; y++) {
153
const uint32_t *src_row = (const uint32_t *)src;
154
uint32_t *dst_row = (uint32_t *)color;
156
for (x = 0; x < width; x++) {
157
*dst_row++ = *src_row++ | 0xff000000;
167
/* Linear shader which always emits purple. Used for debugging.
170
lp_linear_purple(const struct lp_rast_state *state,
171
unsigned x, unsigned y,
172
unsigned width, unsigned height,
173
const float (*a0)[4],
174
const float (*dadx)[4],
175
const float (*dady)[4],
181
util_pack_color_ub(0xff, 0, 0xff, 0xff,
182
PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
184
util_fill_rect(color,
185
PIPE_FORMAT_B8G8R8A8_UNORM,
196
/* Examine the fragment shader varient and determine whether we can
197
* substitute a fastpath linear shader implementation.
200
lp_linear_check_fastpath(struct lp_fragment_shader_variant *variant)
202
struct lp_sampler_static_state *samp0 = lp_fs_variant_key_sampler_idx(&variant->key, 0);
207
enum pipe_format tex_format = samp0->texture_state.format;
208
if (variant->shader->kind == LP_FS_KIND_BLIT_RGBA &&
209
tex_format == PIPE_FORMAT_B8G8R8A8_UNORM &&
210
is_nearest_clamp_sampler(samp0) &&
212
variant->jit_linear_blit = lp_linear_blit_rgba_blit;
215
if (variant->shader->kind == LP_FS_KIND_BLIT_RGB1 &&
217
(tex_format == PIPE_FORMAT_B8G8R8A8_UNORM ||
218
tex_format == PIPE_FORMAT_B8G8R8X8_UNORM) &&
219
is_nearest_clamp_sampler(samp0)) {
220
variant->jit_linear_blit = lp_linear_blit_rgb1_blit;
224
variant->jit_linear = lp_linear_purple;
228
/* Stop now if jit_linear has been initialized. Otherwise keep
229
* searching - even if jit_linear_blit has been instantiated.
231
return variant->jit_linear != NULL;
235
lp_linear_check_fastpath(struct lp_fragment_shader_variant *variant)