Path: blob/21.2-virgl/src/gallium/drivers/virgl/virgl_tgsi.c
4570 views
/*1* Copyright 2014, 2015 Red Hat.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223/* the virgl hw tgsi vs what the current gallium want will diverge over time.24so add a transform stage to remove things we don't want to send unless25the receiver supports it.26*/2728#include "tgsi/tgsi_transform.h"29#include "tgsi/tgsi_info.h"30#include "virgl_context.h"31#include "virgl_screen.h"3233struct virgl_transform_context {34struct tgsi_transform_context base;35bool cull_enabled;36bool has_precise;37bool fake_fp64;38};3940static void41virgl_tgsi_transform_declaration(struct tgsi_transform_context *ctx,42struct tgsi_full_declaration *decl)43{44switch (decl->Declaration.File) {45case TGSI_FILE_CONSTANT:46if (decl->Declaration.Dimension) {47if (decl->Dim.Index2D == 0)48decl->Declaration.Dimension = 0;49}50break;51default:52break;53}54ctx->emit_declaration(ctx, decl);5556}5758/* for now just strip out the new properties the remote doesn't understand59yet */60static void61virgl_tgsi_transform_property(struct tgsi_transform_context *ctx,62struct tgsi_full_property *prop)63{64struct virgl_transform_context *vtctx = (struct virgl_transform_context *)ctx;65switch (prop->Property.PropertyName) {66case TGSI_PROPERTY_NUM_CLIPDIST_ENABLED:67case TGSI_PROPERTY_NUM_CULLDIST_ENABLED:68if (vtctx->cull_enabled)69ctx->emit_property(ctx, prop);70break;71case TGSI_PROPERTY_NEXT_SHADER:72break;73default:74ctx->emit_property(ctx, prop);75break;76}77}7879static void80virgl_tgsi_transform_instruction(struct tgsi_transform_context *ctx,81struct tgsi_full_instruction *inst)82{83struct virgl_transform_context *vtctx = (struct virgl_transform_context *)ctx;84if (vtctx->fake_fp64 &&85(tgsi_opcode_infer_src_type(inst->Instruction.Opcode, 0) == TGSI_TYPE_DOUBLE ||86tgsi_opcode_infer_dst_type(inst->Instruction.Opcode, 0) == TGSI_TYPE_DOUBLE)) {87debug_printf("VIRGL: ARB_gpu_shader_fp64 is exposed but not supported.");88return;89}9091if (!vtctx->has_precise && inst->Instruction.Precise)92inst->Instruction.Precise = 0;9394for (unsigned i = 0; i < inst->Instruction.NumSrcRegs; i++) {95if (inst->Src[i].Register.File == TGSI_FILE_CONSTANT &&96inst->Src[i].Register.Dimension &&97inst->Src[i].Dimension.Index == 0)98inst->Src[i].Register.Dimension = 0;99}100ctx->emit_instruction(ctx, inst);101}102103struct tgsi_token *virgl_tgsi_transform(struct virgl_screen *vscreen, const struct tgsi_token *tokens_in)104{105struct virgl_transform_context transform;106const uint newLen = tgsi_num_tokens(tokens_in);107struct tgsi_token *new_tokens;108109new_tokens = tgsi_alloc_tokens(newLen);110if (!new_tokens)111return NULL;112113memset(&transform, 0, sizeof(transform));114transform.base.transform_declaration = virgl_tgsi_transform_declaration;115transform.base.transform_property = virgl_tgsi_transform_property;116transform.base.transform_instruction = virgl_tgsi_transform_instruction;117transform.cull_enabled = vscreen->caps.caps.v1.bset.has_cull;118transform.has_precise = vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_TGSI_PRECISE;119transform.fake_fp64 =120vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_FAKE_FP64;121tgsi_transform_shader(tokens_in, new_tokens, newLen, &transform.base);122123return new_tokens;124}125126127