2 * Copyright 2014, 2015 Red Hat.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /* the virgl hw tgsi vs what the current gallium want will diverge over time.
25 so add a transform stage to remove things we don't want to send unless
26 the receiver supports it.
28 #include "tgsi/tgsi_transform.h"
29 #include "virgl_context.h"
30 struct virgl_transform_context
{
31 struct tgsi_transform_context base
;
35 virgl_tgsi_transform_declaration(struct tgsi_transform_context
*ctx
,
36 struct tgsi_full_declaration
*decl
)
38 switch (decl
->Declaration
.File
) {
39 case TGSI_FILE_CONSTANT
:
40 if (decl
->Declaration
.Dimension
) {
41 if (decl
->Dim
.Index2D
== 0)
42 decl
->Declaration
.Dimension
= 0;
48 ctx
->emit_declaration(ctx
, decl
);
52 /* for now just strip out the new properties the remote doesn't understand
55 virgl_tgsi_transform_property(struct tgsi_transform_context
*ctx
,
56 struct tgsi_full_property
*prop
)
58 switch (prop
->Property
.PropertyName
) {
59 case TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
:
60 case TGSI_PROPERTY_NUM_CULLDIST_ENABLED
:
61 case TGSI_PROPERTY_NEXT_SHADER
:
64 ctx
->emit_property(ctx
, prop
);
70 virgl_tgsi_transform_instruction(struct tgsi_transform_context
*ctx
,
71 struct tgsi_full_instruction
*inst
)
73 if (inst
->Instruction
.Precise
)
74 inst
->Instruction
.Precise
= 0;
76 for (unsigned i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
77 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
&&
78 inst
->Src
[i
].Register
.Dimension
&&
79 !inst
->Src
[i
].Register
.Indirect
&&
80 inst
->Src
[i
].Dimension
.Index
== 0)
81 inst
->Src
[i
].Register
.Dimension
= 0;
83 ctx
->emit_instruction(ctx
, inst
);
86 struct tgsi_token
*virgl_tgsi_transform(const struct tgsi_token
*tokens_in
)
89 struct virgl_transform_context transform
;
90 const uint newLen
= tgsi_num_tokens(tokens_in
);
91 struct tgsi_token
*new_tokens
;
93 new_tokens
= tgsi_alloc_tokens(newLen
);
97 memset(&transform
, 0, sizeof(transform
));
98 transform
.base
.transform_declaration
= virgl_tgsi_transform_declaration
;
99 transform
.base
.transform_property
= virgl_tgsi_transform_property
;
100 transform
.base
.transform_instruction
= virgl_tgsi_transform_instruction
;
101 tgsi_transform_shader(tokens_in
, new_tokens
, newLen
, &transform
.base
);