mesa/st: Remove TGSI-only shader lowering code.

These are no longer called.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8044>
This commit is contained in:
Eric Anholt 2020-12-10 11:45:39 -08:00 committed by Marge Bot
parent c3001eadcf
commit 6ffdca73d3
7 changed files with 0 additions and 892 deletions

View File

@ -322,14 +322,12 @@ files_libmesa = files(
'state_tracker/st_atom_viewport.c',
'state_tracker/st_cb_bitmap.c',
'state_tracker/st_cb_bitmap.h',
'state_tracker/st_cb_bitmap_shader.c',
'state_tracker/st_cb_clear.c',
'state_tracker/st_cb_clear.h',
'state_tracker/st_cb_copyimage.c',
'state_tracker/st_cb_copyimage.h',
'state_tracker/st_cb_drawpixels.c',
'state_tracker/st_cb_drawpixels.h',
'state_tracker/st_cb_drawpixels_shader.c',
'state_tracker/st_cb_drawtex.c',
'state_tracker/st_cb_drawtex.h',
'state_tracker/st_cb_eglimage.c',
@ -382,8 +380,6 @@ files_libmesa = files(
'state_tracker/st_shader_cache.h',
'state_tracker/st_texture.c',
'state_tracker/st_texture.h',
'state_tracker/st_tgsi_lower_yuv.c',
'state_tracker/st_tgsi_lower_yuv.h',
'state_tracker/st_util.h',
'state_tracker/st_vdpau.c',
'state_tracker/st_vdpau.h',

View File

@ -46,11 +46,6 @@ st_destroy_bitmap(struct st_context *st);
extern void
st_flush_bitmap_cache(struct st_context *st);
extern const struct tgsi_token *
st_get_bitmap_shader(const struct tgsi_token *tokens,
unsigned tex_target, unsigned sampler_index,
bool use_texcoord, bool swizzle_xxxx);
void st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
GLsizei width, GLsizei height,
const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap);

View File

@ -1,151 +0,0 @@
/**************************************************************************
*
* Copyright (C) 2015 Advanced Micro Devices, Inc.
* Copyright 2007 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "main/macros.h"
#include "st_cb_bitmap.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_scan.h"
#include "util/u_debug.h"
struct tgsi_bitmap_transform {
struct tgsi_transform_context base;
struct tgsi_shader_info info;
unsigned sampler_index;
unsigned tex_target;
bool use_texcoord;
bool swizzle_xxxx;
bool first_instruction_emitted;
};
static inline struct tgsi_bitmap_transform *
tgsi_bitmap_transform(struct tgsi_transform_context *tctx)
{
return (struct tgsi_bitmap_transform *)tctx;
}
static void
transform_instr(struct tgsi_transform_context *tctx,
struct tgsi_full_instruction *current_inst)
{
struct tgsi_bitmap_transform *ctx = tgsi_bitmap_transform(tctx);
struct tgsi_full_instruction inst;
unsigned tgsi_tex_target = ctx->tex_target == PIPE_TEXTURE_2D
? TGSI_TEXTURE_2D : TGSI_TEXTURE_RECT;
unsigned i, semantic;
int texcoord_index = -1;
if (ctx->first_instruction_emitted) {
tctx->emit_instruction(tctx, current_inst);
return;
}
ctx->first_instruction_emitted = true;
/* Add TEMP[0] if it's missing. */
if (ctx->info.file_max[TGSI_FILE_TEMPORARY] == -1) {
tgsi_transform_temp_decl(tctx, 0);
}
/* Add TEXCOORD[0] if it's missing. */
semantic = ctx->use_texcoord ? TGSI_SEMANTIC_TEXCOORD :
TGSI_SEMANTIC_GENERIC;
for (i = 0; i < ctx->info.num_inputs; i++) {
if (ctx->info.input_semantic_name[i] == semantic &&
ctx->info.input_semantic_index[i] == 0) {
texcoord_index = i;
break;
}
}
if (texcoord_index == -1) {
texcoord_index = ctx->info.num_inputs;
tgsi_transform_input_decl(tctx, texcoord_index,
semantic, 0, TGSI_INTERPOLATE_PERSPECTIVE);
}
/* Declare the sampler. */
tgsi_transform_sampler_decl(tctx, ctx->sampler_index);
/* Declare the sampler view. */
tgsi_transform_sampler_view_decl(tctx, ctx->sampler_index,
tgsi_tex_target, TGSI_RETURN_TYPE_FLOAT);
/* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */
tgsi_transform_tex_inst(tctx,
TGSI_FILE_TEMPORARY, 0,
TGSI_FILE_INPUT, texcoord_index,
tgsi_tex_target, ctx->sampler_index);
/* KIL if -tmp0 < 0 # texel=0 -> keep / texel=0 -> discard */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_KILL_IF;
inst.Instruction.NumDstRegs = 0;
inst.Instruction.NumSrcRegs = 1;
inst.Src[0].Register.File = TGSI_FILE_TEMPORARY;
inst.Src[0].Register.Index = 0;
inst.Src[0].Register.Negate = 1;
inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
if (ctx->swizzle_xxxx) {
inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
inst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_X;
} else {
inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_Y;
inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_Z;
inst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_W;
}
tctx->emit_instruction(tctx, &inst);
/* And emit the instruction we got. */
tctx->emit_instruction(tctx, current_inst);
}
const struct tgsi_token *
st_get_bitmap_shader(const struct tgsi_token *tokens,
unsigned tex_target, unsigned sampler_index,
bool use_texcoord, bool swizzle_xxxx)
{
struct tgsi_bitmap_transform ctx;
int newlen;
assert(tex_target == PIPE_TEXTURE_2D ||
tex_target == PIPE_TEXTURE_RECT);
memset(&ctx, 0, sizeof(ctx));
ctx.base.transform_instruction = transform_instr;
ctx.tex_target = tex_target;
ctx.sampler_index = sampler_index;
ctx.use_texcoord = use_texcoord;
ctx.swizzle_xxxx = swizzle_xxxx;
tgsi_scan_shader(tokens, &ctx.info);
newlen = tgsi_num_tokens(tokens) + 20;
return tgsi_transform_shader(tokens, newlen, &ctx.base);
}

View File

@ -41,13 +41,6 @@ struct gl_pixelstore_attrib;
extern void
st_destroy_drawpix(struct st_context *st);
extern const struct tgsi_token *
st_get_drawpix_shader(const struct tgsi_token *tokens, bool use_texcoord,
bool scale_and_bias, unsigned scale_const,
unsigned bias_const, bool pixel_maps,
unsigned drawpix_sampler, unsigned pixelmap_sampler,
unsigned texcoord_const, unsigned tex_target);
extern void
st_make_passthrough_vertex_shader(struct st_context *st);

View File

@ -1,245 +0,0 @@
/**************************************************************************
*
* Copyright (C) 2015 Advanced Micro Devices, Inc.
* Copyright 2007 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "main/macros.h"
#include "st_cb_drawpixels.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_scan.h"
struct tgsi_drawpix_transform {
struct tgsi_transform_context base;
struct tgsi_shader_info info;
bool use_texcoord;
bool scale_and_bias;
bool pixel_maps;
bool first_instruction_emitted;
unsigned scale_const;
unsigned bias_const;
unsigned color_temp;
unsigned drawpix_sampler;
unsigned pixelmap_sampler;
unsigned texcoord_const;
unsigned tex_target;
};
static inline struct tgsi_drawpix_transform *
tgsi_drawpix_transform(struct tgsi_transform_context *tctx)
{
return (struct tgsi_drawpix_transform *)tctx;
}
static void
set_src(struct tgsi_full_instruction *inst, unsigned i, unsigned file, unsigned index,
unsigned x, unsigned y, unsigned z, unsigned w)
{
inst->Src[i].Register.File = file;
inst->Src[i].Register.Index = index;
inst->Src[i].Register.SwizzleX = x;
inst->Src[i].Register.SwizzleY = y;
inst->Src[i].Register.SwizzleZ = z;
inst->Src[i].Register.SwizzleW = w;
}
#define SET_SRC(inst, i, file, index, x, y, z, w) \
set_src(inst, i, file, index, TGSI_SWIZZLE_##x, TGSI_SWIZZLE_##y, \
TGSI_SWIZZLE_##z, TGSI_SWIZZLE_##w)
static void
transform_instr(struct tgsi_transform_context *tctx,
struct tgsi_full_instruction *current_inst)
{
struct tgsi_drawpix_transform *ctx = tgsi_drawpix_transform(tctx);
const unsigned tgsi_tex_target = ctx->tex_target == PIPE_TEXTURE_2D
? TGSI_TEXTURE_2D : TGSI_TEXTURE_RECT;
unsigned i, sem_texcoord = ctx->use_texcoord ? TGSI_SEMANTIC_TEXCOORD :
TGSI_SEMANTIC_GENERIC;
int texcoord_index = -1;
if (ctx->first_instruction_emitted)
goto transform_inst;
ctx->first_instruction_emitted = true;
/* Add scale and bias constants. */
if (ctx->scale_and_bias) {
if (ctx->info.const_file_max[0] < (int)ctx->scale_const) {
tgsi_transform_const_decl(tctx, ctx->scale_const, ctx->scale_const);
}
if (ctx->info.const_file_max[0] < (int)ctx->bias_const) {
tgsi_transform_const_decl(tctx, ctx->bias_const, ctx->bias_const);
}
}
if (ctx->info.const_file_max[0] < (int)ctx->texcoord_const) {
tgsi_transform_const_decl(tctx, ctx->texcoord_const, ctx->texcoord_const);
}
/* Add a new temp. */
ctx->color_temp = ctx->info.file_max[TGSI_FILE_TEMPORARY] + 1;
tgsi_transform_temp_decl(tctx, ctx->color_temp);
/* Add TEXCOORD[texcoord_slot] if it's missing. */
for (i = 0; i < ctx->info.num_inputs; i++) {
if (ctx->info.input_semantic_name[i] == sem_texcoord &&
ctx->info.input_semantic_index[i] == 0) {
texcoord_index = i;
break;
}
}
if (texcoord_index == -1) {
texcoord_index = ctx->info.num_inputs;
tgsi_transform_input_decl(tctx, texcoord_index, sem_texcoord, 0,
TGSI_INTERPOLATE_PERSPECTIVE);
}
/* Declare the drawpix sampler if it's missing. */
if (!(ctx->info.samplers_declared & (1 << ctx->drawpix_sampler))) {
tgsi_transform_sampler_decl(tctx, ctx->drawpix_sampler);
/* emit sampler view declaration */
tgsi_transform_sampler_view_decl(tctx, ctx->drawpix_sampler,
tgsi_tex_target, TGSI_RETURN_TYPE_FLOAT);
}
/* Declare the pixel map sampler if it's missing. */
if (ctx->pixel_maps &&
!(ctx->info.samplers_declared & (1 << ctx->pixelmap_sampler))) {
tgsi_transform_sampler_decl(tctx, ctx->pixelmap_sampler);
/* emit sampler view declaration */
tgsi_transform_sampler_view_decl(tctx, ctx->pixelmap_sampler,
TGSI_TEXTURE_2D, TGSI_RETURN_TYPE_FLOAT);
}
/* Get initial pixel color from the texture.
* TEX temp, fragment.texcoord[0], texture[0], 2D;
*/
tgsi_transform_tex_inst(tctx, TGSI_FILE_TEMPORARY, ctx->color_temp,
TGSI_FILE_INPUT, texcoord_index,
tgsi_tex_target, ctx->drawpix_sampler);
/* Apply the scale and bias. */
if (ctx->scale_and_bias) {
/* MAD temp, temp, scale, bias; */
tgsi_transform_op3_inst(tctx, TGSI_OPCODE_MAD,
TGSI_FILE_TEMPORARY, ctx->color_temp,
TGSI_WRITEMASK_XYZW,
TGSI_FILE_TEMPORARY, ctx->color_temp,
TGSI_FILE_CONSTANT, ctx->scale_const,
TGSI_FILE_CONSTANT, ctx->bias_const);
}
if (ctx->pixel_maps) {
/* do four pixel map look-ups with two TEX instructions: */
struct tgsi_full_instruction inst;
/* TEX temp.xy, temp.xyyy, texture[1], 2D; */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_TEX;
inst.Instruction.Texture = 1;
inst.Texture.Texture = TGSI_TEXTURE_2D;
inst.Instruction.NumDstRegs = 1;
inst.Dst[0].Register.File = TGSI_FILE_TEMPORARY;
inst.Dst[0].Register.Index = ctx->color_temp;
inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_XY;
inst.Instruction.NumSrcRegs = 2;
SET_SRC(&inst, 0, TGSI_FILE_TEMPORARY, ctx->color_temp, X, Y, Y, Y);
inst.Src[1].Register.File = TGSI_FILE_SAMPLER;
inst.Src[1].Register.Index = ctx->pixelmap_sampler;
tctx->emit_instruction(tctx, &inst);
/* TEX temp.zw, temp.zwww, texture[1], 2D; */
inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_ZW;
SET_SRC(&inst, 0, TGSI_FILE_TEMPORARY, ctx->color_temp, Z, W, W, W);
tctx->emit_instruction(tctx, &inst);
}
/* Now, "color_temp" should be used in place of IN:COLOR0,
* and CONST[texcoord_slot] should be used in place of IN:TEXCOORD0.
*/
transform_inst:
for (i = 0; i < current_inst->Instruction.NumSrcRegs; i++) {
struct tgsi_full_src_register *src = &current_inst->Src[i];
unsigned reg = src->Register.Index;
if (src->Register.File != TGSI_FILE_INPUT || src->Register.Indirect)
continue;
if (ctx->info.input_semantic_name[reg] == TGSI_SEMANTIC_COLOR &&
ctx->info.input_semantic_index[reg] == 0) {
src->Register.File = TGSI_FILE_TEMPORARY;
src->Register.Index = ctx->color_temp;
} else if (ctx->info.input_semantic_name[reg] == sem_texcoord &&
ctx->info.input_semantic_index[reg] == 0) {
src->Register.File = TGSI_FILE_CONSTANT;
src->Register.Index = ctx->texcoord_const;
src->Register.Dimension = 1;
src->Dimension.Index = 0;
}
}
tctx->emit_instruction(tctx, current_inst);
}
const struct tgsi_token *
st_get_drawpix_shader(const struct tgsi_token *tokens, bool use_texcoord,
bool scale_and_bias, unsigned scale_const,
unsigned bias_const, bool pixel_maps,
unsigned drawpix_sampler, unsigned pixelmap_sampler,
unsigned texcoord_const, unsigned tex_target)
{
struct tgsi_drawpix_transform ctx;
int newlen;
assert(tex_target == PIPE_TEXTURE_2D ||
tex_target == PIPE_TEXTURE_RECT);
memset(&ctx, 0, sizeof(ctx));
ctx.base.transform_instruction = transform_instr;
ctx.use_texcoord = use_texcoord;
ctx.scale_and_bias = scale_and_bias;
ctx.scale_const = scale_const;
ctx.bias_const = bias_const;
ctx.pixel_maps = pixel_maps;
ctx.drawpix_sampler = drawpix_sampler;
ctx.pixelmap_sampler = pixelmap_sampler;
ctx.texcoord_const = texcoord_const;
ctx.tex_target = tex_target;
tgsi_scan_shader(tokens, &ctx.info);
newlen = tgsi_num_tokens(tokens) + 60;
return tgsi_transform_shader(tokens, newlen, &ctx.base);
}

View File

@ -1,446 +0,0 @@
/*
* Copyright © 2016 Red Hat
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdbool.h>
#include "st_tgsi_lower_yuv.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_scan.h"
#include "util/u_debug.h"
#include "util/bitscan.h"
struct tgsi_yuv_transform {
struct tgsi_transform_context base;
struct tgsi_shader_info info;
struct tgsi_full_src_register imm[4];
struct {
struct tgsi_full_src_register src;
struct tgsi_full_dst_register dst;
} tmp[2];
#define A 0
#define B 1
/* Maps a primary sampler (used for Y) to the U or UV sampler. In
* case of 3-plane YUV format, the V plane is next sampler after U.
*/
unsigned char sampler_map[PIPE_MAX_SAMPLERS][2];
bool first_instruction_emitted;
unsigned free_slots;
unsigned lower_nv12;
unsigned lower_iyuv;
};
static inline struct tgsi_yuv_transform *
tgsi_yuv_transform(struct tgsi_transform_context *tctx)
{
return (struct tgsi_yuv_transform *)tctx;
}
static void
reg_dst(struct tgsi_full_dst_register *dst,
const struct tgsi_full_dst_register *orig_dst, unsigned wrmask)
{
*dst = *orig_dst;
dst->Register.WriteMask &= wrmask;
assert(dst->Register.WriteMask);
}
static inline void
get_swiz(unsigned *swiz, const struct tgsi_src_register *src)
{
swiz[0] = src->SwizzleX;
swiz[1] = src->SwizzleY;
swiz[2] = src->SwizzleZ;
swiz[3] = src->SwizzleW;
}
static void
reg_src(struct tgsi_full_src_register *src,
const struct tgsi_full_src_register *orig_src,
unsigned sx, unsigned sy, unsigned sz, unsigned sw)
{
unsigned swiz[4];
get_swiz(swiz, &orig_src->Register);
*src = *orig_src;
src->Register.SwizzleX = swiz[sx];
src->Register.SwizzleY = swiz[sy];
src->Register.SwizzleZ = swiz[sz];
src->Register.SwizzleW = swiz[sw];
}
#define TGSI_SWIZZLE__ TGSI_SWIZZLE_X /* don't-care value! */
#define SWIZ(x,y,z,w) TGSI_SWIZZLE_ ## x, TGSI_SWIZZLE_ ## y, \
TGSI_SWIZZLE_ ## z, TGSI_SWIZZLE_ ## w
static inline struct tgsi_full_instruction
tex_instruction(unsigned samp)
{
struct tgsi_full_instruction inst;
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_TEX;
inst.Instruction.Texture = 1;
inst.Texture.Texture = TGSI_TEXTURE_2D;
inst.Instruction.NumDstRegs = 1;
inst.Instruction.NumSrcRegs = 2;
inst.Src[1].Register.File = TGSI_FILE_SAMPLER;
inst.Src[1].Register.Index = samp;
return inst;
}
static inline struct tgsi_full_instruction
mov_instruction(void)
{
struct tgsi_full_instruction inst;
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_MOV;
inst.Instruction.Saturate = 0;
inst.Instruction.NumDstRegs = 1;
inst.Instruction.NumSrcRegs = 1;
return inst;
}
static inline struct tgsi_full_instruction
dp3_instruction(void)
{
struct tgsi_full_instruction inst;
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_DP3;
inst.Instruction.NumDstRegs = 1;
inst.Instruction.NumSrcRegs = 2;
return inst;
}
static void
emit_immed(struct tgsi_transform_context *tctx, int idx,
float x, float y, float z, float w)
{
struct tgsi_yuv_transform *ctx = tgsi_yuv_transform(tctx);
struct tgsi_shader_info *info = &ctx->info;
struct tgsi_full_immediate immed;
immed = tgsi_default_full_immediate();
immed.Immediate.NrTokens = 1 + 4; /* one for the token itself */
immed.u[0].Float = x;
immed.u[1].Float = y;
immed.u[2].Float = z;
immed.u[3].Float = w;
tctx->emit_immediate(tctx, &immed);
ctx->imm[idx].Register.File = TGSI_FILE_IMMEDIATE;
ctx->imm[idx].Register.Index = info->immediate_count + idx;
ctx->imm[idx].Register.SwizzleX = TGSI_SWIZZLE_X;
ctx->imm[idx].Register.SwizzleY = TGSI_SWIZZLE_Y;
ctx->imm[idx].Register.SwizzleZ = TGSI_SWIZZLE_Z;
ctx->imm[idx].Register.SwizzleW = TGSI_SWIZZLE_W;
}
static void
emit_samp(struct tgsi_transform_context *tctx, unsigned samp)
{
tgsi_transform_sampler_decl(tctx, samp);
tgsi_transform_sampler_view_decl(tctx, samp, PIPE_TEXTURE_2D,
TGSI_RETURN_TYPE_FLOAT);
}
/* Emit extra declarations we need:
* + 2 TEMP to hold intermediate results
* + 1 (for 2-plane YUV) or 2 (for 3-plane YUV) extra samplers per
* lowered YUV sampler
* + extra immediates for doing CSC
*/
static void
emit_decls(struct tgsi_transform_context *tctx)
{
struct tgsi_yuv_transform *ctx = tgsi_yuv_transform(tctx);
struct tgsi_shader_info *info = &ctx->info;
unsigned mask, tempbase, i;
struct tgsi_full_declaration decl;
/*
* Declare immediates for CSC conversion:
*/
/* ITU-R BT.601 conversion */
emit_immed(tctx, 0, 1.164f, 0.000f, 1.596f, 0.0f);
emit_immed(tctx, 1, 1.164f, -0.392f, -0.813f, 0.0f);
emit_immed(tctx, 2, 1.164f, 2.017f, 0.000f, 0.0f);
emit_immed(tctx, 3, 0.0625f, 0.500f, 0.500f, 1.0f);
/*
* Declare extra samplers / sampler-views:
*/
mask = ctx->lower_nv12 | ctx->lower_iyuv;
while (mask) {
unsigned extra, y_samp = u_bit_scan(&mask);
extra = u_bit_scan(&ctx->free_slots);
ctx->sampler_map[y_samp][0] = extra;
emit_samp(tctx, extra);
if (ctx->lower_iyuv & (1 << y_samp)) {
extra = u_bit_scan(&ctx->free_slots);
ctx->sampler_map[y_samp][1] = extra;
emit_samp(tctx, extra);
}
}
/*
* Declare extra temp:
*/
tempbase = info->file_max[TGSI_FILE_TEMPORARY] + 1;
for (i = 0; i < 2; i++) {
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_TEMPORARY;
decl.Range.First = decl.Range.Last = tempbase + i;
tctx->emit_declaration(tctx, &decl);
ctx->tmp[i].src.Register.File = TGSI_FILE_TEMPORARY;
ctx->tmp[i].src.Register.Index = tempbase + i;
ctx->tmp[i].src.Register.SwizzleX = TGSI_SWIZZLE_X;
ctx->tmp[i].src.Register.SwizzleY = TGSI_SWIZZLE_Y;
ctx->tmp[i].src.Register.SwizzleZ = TGSI_SWIZZLE_Z;
ctx->tmp[i].src.Register.SwizzleW = TGSI_SWIZZLE_W;
ctx->tmp[i].dst.Register.File = TGSI_FILE_TEMPORARY;
ctx->tmp[i].dst.Register.Index = tempbase + i;
ctx->tmp[i].dst.Register.WriteMask = TGSI_WRITEMASK_XYZW;
}
}
/* call with YUV in tmpA.xyz */
static void
yuv_to_rgb(struct tgsi_transform_context *tctx,
struct tgsi_full_dst_register *dst)
{
struct tgsi_yuv_transform *ctx = tgsi_yuv_transform(tctx);
struct tgsi_full_instruction inst;
/*
* IMM[0] FLT32 { 1.164, 0.000, 1.596, 0.0 }
* IMM[1] FLT32 { 1.164, -0.392, -0.813, 0.0 }
* IMM[2] FLT32 { 1.164, 2.017, 0.000, 0.0 }
* IMM[3] FLT32 { 0.0625, 0.500, 0.500, 1.0 }
*/
/* SUB tmpA.xyz, tmpA, imm[3] */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_ADD;
inst.Instruction.Saturate = 0;
inst.Instruction.NumDstRegs = 1;
inst.Instruction.NumSrcRegs = 2;
reg_dst(&inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_XYZ);
reg_src(&inst.Src[0], &ctx->tmp[A].src, SWIZ(X, Y, Z, _));
reg_src(&inst.Src[1], &ctx->imm[3], SWIZ(X, Y, Z, _));
inst.Src[1].Register.Negate = 1;
tctx->emit_instruction(tctx, &inst);
/* DP3 dst.x, tmpA, imm[0] */
if (dst->Register.WriteMask & TGSI_WRITEMASK_X) {
inst = dp3_instruction();
reg_dst(&inst.Dst[0], dst, TGSI_WRITEMASK_X);
reg_src(&inst.Src[0], &ctx->tmp[A].src, SWIZ(X, Y, Z, W));
reg_src(&inst.Src[1], &ctx->imm[0], SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
}
/* DP3 dst.y, tmpA, imm[1] */
if (dst->Register.WriteMask & TGSI_WRITEMASK_Y) {
inst = dp3_instruction();
reg_dst(&inst.Dst[0], dst, TGSI_WRITEMASK_Y);
reg_src(&inst.Src[0], &ctx->tmp[A].src, SWIZ(X, Y, Z, W));
reg_src(&inst.Src[1], &ctx->imm[1], SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
}
/* DP3 dst.z, tmpA, imm[2] */
if (dst->Register.WriteMask & TGSI_WRITEMASK_Z) {
inst = dp3_instruction();
reg_dst(&inst.Dst[0], dst, TGSI_WRITEMASK_Z);
reg_src(&inst.Src[0], &ctx->tmp[A].src, SWIZ(X, Y, Z, W));
reg_src(&inst.Src[1], &ctx->imm[2], SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
}
/* MOV dst.w, imm[0].x */
if (dst->Register.WriteMask & TGSI_WRITEMASK_W) {
inst = mov_instruction();
reg_dst(&inst.Dst[0], dst, TGSI_WRITEMASK_W);
reg_src(&inst.Src[0], &ctx->imm[3], SWIZ(_, _, _, W));
tctx->emit_instruction(tctx, &inst);
}
}
static void
lower_nv12(struct tgsi_transform_context *tctx,
struct tgsi_full_instruction *originst)
{
struct tgsi_yuv_transform *ctx = tgsi_yuv_transform(tctx);
struct tgsi_full_instruction inst;
struct tgsi_full_src_register *coord = &originst->Src[0];
unsigned samp = originst->Src[1].Register.Index;
/* sample Y:
* TEX tempA.x, coord, texture[samp], 2D;
*/
inst = tex_instruction(samp);
reg_dst(&inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_X);
reg_src(&inst.Src[0], coord, SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
/* sample UV:
* TEX tempB.xy, coord, texture[sampler_map[samp][0]], 2D;
* MOV tempA.yz, tempB._xy_
*/
inst = tex_instruction(ctx->sampler_map[samp][0]);
reg_dst(&inst.Dst[0], &ctx->tmp[B].dst, TGSI_WRITEMASK_XY);
reg_src(&inst.Src[0], coord, SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
inst = mov_instruction();
reg_dst(&inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_YZ);
reg_src(&inst.Src[0], &ctx->tmp[B].src, SWIZ(_, X, Y, _));
tctx->emit_instruction(tctx, &inst);
/* At this point, we have YUV in tempA.xyz, rest is common: */
yuv_to_rgb(tctx, &originst->Dst[0]);
}
static void
lower_iyuv(struct tgsi_transform_context *tctx,
struct tgsi_full_instruction *originst)
{
struct tgsi_yuv_transform *ctx = tgsi_yuv_transform(tctx);
struct tgsi_full_instruction inst;
struct tgsi_full_src_register *coord = &originst->Src[0];
unsigned samp = originst->Src[1].Register.Index;
/* sample Y:
* TEX tempA.x, coord, texture[samp], 2D;
*/
inst = tex_instruction(samp);
reg_dst(&inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_X);
reg_src(&inst.Src[0], coord, SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
/* sample U:
* TEX tempB.x, coord, texture[sampler_map[samp][0]], 2D;
* MOV tempA.y, tempB._x__
*/
inst = tex_instruction(ctx->sampler_map[samp][0]);
reg_dst(&inst.Dst[0], &ctx->tmp[B].dst, TGSI_WRITEMASK_X);
reg_src(&inst.Src[0], coord, SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
inst = mov_instruction();
reg_dst(&inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_Y);
reg_src(&inst.Src[0], &ctx->tmp[B].src, SWIZ(_, X, _, _));
tctx->emit_instruction(tctx, &inst);
/* sample V:
* TEX tempB.x, coord, texture[sampler_map[samp][1]], 2D;
* MOV tempA.z, tempB.__x_
*/
inst = tex_instruction(ctx->sampler_map[samp][1]);
reg_dst(&inst.Dst[0], &ctx->tmp[B].dst, TGSI_WRITEMASK_X);
reg_src(&inst.Src[0], coord, SWIZ(X, Y, Z, W));
tctx->emit_instruction(tctx, &inst);
inst = mov_instruction();
reg_dst(&inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_Z);
reg_src(&inst.Src[0], &ctx->tmp[B].src, SWIZ(_, _, X, _));
tctx->emit_instruction(tctx, &inst);
/* At this point, we have YUV in tempA.xyz, rest is common: */
yuv_to_rgb(tctx, &originst->Dst[0]);
}
static void
transform_instr(struct tgsi_transform_context *tctx,
struct tgsi_full_instruction *inst)
{
struct tgsi_yuv_transform *ctx = tgsi_yuv_transform(tctx);
if (!ctx->first_instruction_emitted) {
emit_decls(tctx);
ctx->first_instruction_emitted = true;
}
switch (inst->Instruction.Opcode) {
/* TODO what other tex opcode's can be used w/ external eglimgs? */
case TGSI_OPCODE_TEX: {
unsigned samp = inst->Src[1].Register.Index;
if (ctx->lower_nv12 & (1 << samp)) {
lower_nv12(tctx, inst);
} else if (ctx->lower_iyuv & (1 << samp)) {
lower_iyuv(tctx, inst);
} else {
goto skip;
}
break;
}
default:
skip:
tctx->emit_instruction(tctx, inst);
return;
}
}
extern const struct tgsi_token *
st_tgsi_lower_yuv(const struct tgsi_token *tokens, unsigned free_slots,
unsigned lower_nv12, unsigned lower_iyuv)
{
struct tgsi_yuv_transform ctx;
int newlen;
assert(!(lower_nv12 & lower_iyuv)); /* bitmasks should be mutually exclusive */
// tgsi_dump(tokens, 0);
// debug_printf("\n");
memset(&ctx, 0, sizeof(ctx));
ctx.base.transform_instruction = transform_instr;
ctx.free_slots = free_slots;
ctx.lower_nv12 = lower_nv12;
ctx.lower_iyuv = lower_iyuv;
tgsi_scan_shader(tokens, &ctx.info);
/* TODO better job of figuring out how many extra tokens we need..
* this is a pain about tgsi_transform :-/
*/
newlen = tgsi_num_tokens(tokens) + 300;
return tgsi_transform_shader(tokens, newlen, &ctx.base);
}

View File

@ -1,34 +0,0 @@
/*
* Copyright © 2016 Red Hat
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ST_TGSI_LOWER_YUV_H
#define ST_TGSI_LOWER_YUV_H
struct tgsi_token;
extern const struct tgsi_token * st_tgsi_lower_yuv(const struct tgsi_token *tokens,
unsigned free_slots,
unsigned lower_nv12,
unsigned lower_iyuv);
#endif /* ST_TGSI_LOWER_YUV_H */