2 * Copyright (c) 2016 Etnaviv Project
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Christian Gmeiner <christian.gmeiner@gmail.com>
27 #include "etnaviv_uniforms.h"
29 #include "etnaviv_compiler.h"
30 #include "etnaviv_context.h"
31 #include "etnaviv_util.h"
32 #include "pipe/p_defines.h"
33 #include "util/u_math.h"
36 get_const_idx(const struct etna_context
*ctx
, bool frag
, unsigned samp_id
)
41 return samp_id
+ ctx
->specs
.vertex_sampler_offset
;
45 get_texrect_scale(const struct etna_context
*ctx
, bool frag
,
46 enum etna_immediate_contents contents
, uint32_t data
)
48 unsigned index
= get_const_idx(ctx
, frag
, data
);
49 struct pipe_sampler_view
*texture
= ctx
->sampler_view
[index
];
52 if (contents
== ETNA_IMMEDIATE_TEXRECT_SCALE_X
)
53 dim
= texture
->texture
->width0
;
55 dim
= texture
->texture
->height0
;
57 return fui(1.0f
/ dim
);
61 etna_uniforms_write(const struct etna_context
*ctx
,
62 const struct etna_shader
*sobj
,
63 struct pipe_constant_buffer
*cb
, uint32_t *uniforms
,
66 const struct etna_shader_uniform_info
*uinfo
= &sobj
->uniforms
;
69 if (cb
->user_buffer
) {
70 unsigned size
= MIN2(cb
->buffer_size
, uinfo
->const_count
* 4);
72 memcpy(uniforms
, cb
->user_buffer
, size
);
78 for (uint32_t i
= 0; i
< uinfo
->imm_count
; i
++) {
79 switch (uinfo
->imm_contents
[i
]) {
80 case ETNA_IMMEDIATE_CONSTANT
:
81 uniforms
[i
+ uinfo
->const_count
] = uinfo
->imm_data
[i
];
84 case ETNA_IMMEDIATE_TEXRECT_SCALE_X
:
85 case ETNA_IMMEDIATE_TEXRECT_SCALE_Y
:
86 uniforms
[i
+ uinfo
->const_count
] =
87 get_texrect_scale(ctx
, frag
, uinfo
->imm_contents
[i
], uinfo
->imm_data
[i
]);
90 case ETNA_IMMEDIATE_UNUSED
:
96 *size
= uinfo
->const_count
+ uinfo
->imm_count
;
100 etna_set_shader_uniforms_dirty_flags(struct etna_shader
*sobj
)
104 for (uint32_t i
= 0; i
< sobj
->uniforms
.imm_count
; i
++) {
105 switch (sobj
->uniforms
.imm_contents
[i
]) {
106 case ETNA_IMMEDIATE_UNUSED
:
107 case ETNA_IMMEDIATE_CONSTANT
:
110 case ETNA_IMMEDIATE_TEXRECT_SCALE_X
:
111 case ETNA_IMMEDIATE_TEXRECT_SCALE_Y
:
112 dirty
|= ETNA_DIRTY_SAMPLER_VIEWS
;
117 sobj
->uniforms_dirty_bits
= dirty
;