mesa/st: Move the dword slot counting function to glsl_types as well.
To implement NIR-to-TGSI, we need to be able to get the size of the uniform variable for the TGSI declaration, not just the .driver_location. With its location in mesa/st, drivers couldn't link to it from nir-to-tgsi. This feels like a common enough function to want, so let's share it in the core compiler. Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3297>
This commit is contained in:
@@ -2517,6 +2517,58 @@ glsl_type::count_vec4_slots(bool is_gl_vertex_input, bool is_bindless) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
glsl_type::count_dword_slots(bool is_bindless) const
|
||||
{
|
||||
switch (this->base_type) {
|
||||
case GLSL_TYPE_UINT:
|
||||
case GLSL_TYPE_INT:
|
||||
case GLSL_TYPE_FLOAT:
|
||||
case GLSL_TYPE_BOOL:
|
||||
return this->components();
|
||||
case GLSL_TYPE_UINT16:
|
||||
case GLSL_TYPE_INT16:
|
||||
case GLSL_TYPE_FLOAT16:
|
||||
return DIV_ROUND_UP(this->components(), 2);
|
||||
case GLSL_TYPE_UINT8:
|
||||
case GLSL_TYPE_INT8:
|
||||
return DIV_ROUND_UP(this->components(), 4);
|
||||
case GLSL_TYPE_IMAGE:
|
||||
case GLSL_TYPE_SAMPLER:
|
||||
if (!is_bindless)
|
||||
return 0;
|
||||
/* FALLTHROUGH */
|
||||
case GLSL_TYPE_DOUBLE:
|
||||
case GLSL_TYPE_UINT64:
|
||||
case GLSL_TYPE_INT64:
|
||||
return this->components() * 2;
|
||||
case GLSL_TYPE_ARRAY:
|
||||
return this->fields.array->count_dword_slots(is_bindless) *
|
||||
this->length;
|
||||
|
||||
case GLSL_TYPE_STRUCT: {
|
||||
unsigned size = 0;
|
||||
for (unsigned i = 0; i < this->length; i++) {
|
||||
size += this->fields.structure[i].type->count_dword_slots(is_bindless);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
case GLSL_TYPE_ATOMIC_UINT:
|
||||
return 0;
|
||||
case GLSL_TYPE_SUBROUTINE:
|
||||
return 1;
|
||||
case GLSL_TYPE_VOID:
|
||||
case GLSL_TYPE_ERROR:
|
||||
case GLSL_TYPE_INTERFACE:
|
||||
case GLSL_TYPE_FUNCTION:
|
||||
default:
|
||||
unreachable("invalid type in st_glsl_type_dword_size()");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glsl_type::coordinate_components() const
|
||||
{
|
||||
|
@@ -481,6 +481,14 @@ public:
|
||||
*/
|
||||
unsigned count_vec4_slots(bool is_gl_vertex_input, bool bindless) const;
|
||||
|
||||
/**
|
||||
* Calculate the number of vec4 slots required to hold this type.
|
||||
*
|
||||
* This is the underlying recursive type_size function for
|
||||
* gallium's PIPE_CAP_PACKED_UNIFORMS case.
|
||||
*/
|
||||
unsigned count_dword_slots(bool bindless) const;
|
||||
|
||||
/**
|
||||
* Calculate the number of attribute slots required to hold this type
|
||||
*
|
||||
|
@@ -159,6 +159,12 @@ glsl_count_vec4_slots(const struct glsl_type *type,
|
||||
return type->count_vec4_slots(is_gl_vertex_input, is_bindless);
|
||||
}
|
||||
|
||||
unsigned
|
||||
glsl_count_dword_slots(const struct glsl_type *type, bool is_bindless)
|
||||
{
|
||||
return type->count_dword_slots(is_bindless);
|
||||
}
|
||||
|
||||
unsigned
|
||||
glsl_count_attribute_slots(const struct glsl_type *type,
|
||||
bool is_gl_vertex_input)
|
||||
|
@@ -82,6 +82,7 @@ unsigned glsl_get_aoa_size(const struct glsl_type *type);
|
||||
|
||||
unsigned glsl_count_vec4_slots(const struct glsl_type *type,
|
||||
bool is_gl_vertex_input, bool is_bindless);
|
||||
unsigned glsl_count_dword_slots(const struct glsl_type *type, bool is_bindless);
|
||||
unsigned glsl_count_attribute_slots(const struct glsl_type *type,
|
||||
bool is_gl_vertex_input);
|
||||
unsigned glsl_get_component_slots(const struct glsl_type *type);
|
||||
|
@@ -534,8 +534,6 @@ STATETRACKER_FILES = \
|
||||
state_tracker/st_glsl_to_tgsi_private.h \
|
||||
state_tracker/st_glsl_to_tgsi_temprename.cpp \
|
||||
state_tracker/st_glsl_to_tgsi_temprename.h \
|
||||
state_tracker/st_glsl_types.cpp \
|
||||
state_tracker/st_glsl_types.h \
|
||||
state_tracker/st_manager.c \
|
||||
state_tracker/st_manager.h \
|
||||
state_tracker/st_mesa_to_tgsi.c \
|
||||
|
@@ -578,8 +578,6 @@ files_libmesa_gallium = files(
|
||||
'state_tracker/st_glsl_to_tgsi_private.h',
|
||||
'state_tracker/st_glsl_to_tgsi_temprename.cpp',
|
||||
'state_tracker/st_glsl_to_tgsi_temprename.h',
|
||||
'state_tracker/st_glsl_types.cpp',
|
||||
'state_tracker/st_glsl_types.h',
|
||||
'state_tracker/st_manager.c',
|
||||
'state_tracker/st_manager.h',
|
||||
'state_tracker/st_mesa_to_tgsi.c',
|
||||
|
@@ -40,7 +40,6 @@
|
||||
|
||||
#include "main/shaderobj.h"
|
||||
#include "st_context.h"
|
||||
#include "st_glsl_types.h"
|
||||
#include "st_program.h"
|
||||
#include "st_shader_cache.h"
|
||||
|
||||
@@ -897,6 +896,12 @@ st_nir_lower_samplers(struct pipe_screen *screen, nir_shader *nir,
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
st_packed_uniforms_type_size(const struct glsl_type *type, bool bindless)
|
||||
{
|
||||
return glsl_count_dword_slots(type, bindless);
|
||||
}
|
||||
|
||||
static int
|
||||
st_unpacked_uniforms_type_size(const struct glsl_type *type, bool bindless)
|
||||
{
|
||||
@@ -907,7 +912,8 @@ void
|
||||
st_nir_lower_uniforms(struct st_context *st, nir_shader *nir)
|
||||
{
|
||||
if (st->ctx->Const.PackedDriverUniformStorage) {
|
||||
NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
|
||||
NIR_PASS_V(nir, nir_lower_io, nir_var_uniform,
|
||||
st_packed_uniforms_type_size,
|
||||
(nir_lower_io_options)0);
|
||||
NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
|
||||
} else {
|
||||
|
@@ -49,7 +49,6 @@
|
||||
#include "tgsi/tgsi_info.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "st_glsl_types.h"
|
||||
#include "st_program.h"
|
||||
#include "st_mesa_to_tgsi.h"
|
||||
#include "st_format.h"
|
||||
|
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
|
||||
* Copyright (C) 2008 VMware, Inc. All Rights Reserved.
|
||||
* Copyright © 2010 Intel Corporation
|
||||
* Copyright © 2011 Bryan Cain
|
||||
*
|
||||
* 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 "st_glsl_types.h"
|
||||
|
||||
int
|
||||
st_glsl_type_dword_size(const struct glsl_type *type, bool bindless)
|
||||
{
|
||||
unsigned int size, i;
|
||||
|
||||
switch (type->base_type) {
|
||||
case GLSL_TYPE_UINT:
|
||||
case GLSL_TYPE_INT:
|
||||
case GLSL_TYPE_FLOAT:
|
||||
case GLSL_TYPE_BOOL:
|
||||
return type->components();
|
||||
case GLSL_TYPE_UINT16:
|
||||
case GLSL_TYPE_INT16:
|
||||
case GLSL_TYPE_FLOAT16:
|
||||
return DIV_ROUND_UP(type->components(), 2);
|
||||
case GLSL_TYPE_UINT8:
|
||||
case GLSL_TYPE_INT8:
|
||||
return DIV_ROUND_UP(type->components(), 4);
|
||||
case GLSL_TYPE_IMAGE:
|
||||
case GLSL_TYPE_SAMPLER:
|
||||
if (!bindless)
|
||||
return 0;
|
||||
case GLSL_TYPE_DOUBLE:
|
||||
case GLSL_TYPE_UINT64:
|
||||
case GLSL_TYPE_INT64:
|
||||
return type->components() * 2;
|
||||
case GLSL_TYPE_ARRAY:
|
||||
return st_glsl_type_dword_size(type->fields.array, bindless) *
|
||||
type->length;
|
||||
case GLSL_TYPE_STRUCT:
|
||||
size = 0;
|
||||
for (i = 0; i < type->length; i++) {
|
||||
size += st_glsl_type_dword_size(type->fields.structure[i].type,
|
||||
bindless);
|
||||
}
|
||||
return size;
|
||||
case GLSL_TYPE_ATOMIC_UINT:
|
||||
return 0;
|
||||
case GLSL_TYPE_SUBROUTINE:
|
||||
return 1;
|
||||
case GLSL_TYPE_VOID:
|
||||
case GLSL_TYPE_ERROR:
|
||||
case GLSL_TYPE_INTERFACE:
|
||||
case GLSL_TYPE_FUNCTION:
|
||||
default:
|
||||
unreachable("invalid type in st_glsl_type_dword_size()");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
|
||||
* Copyright (C) 2008 VMware, Inc. All Rights Reserved.
|
||||
* Copyright © 2010 Intel Corporation
|
||||
* Copyright © 2011 Bryan Cain
|
||||
*
|
||||
* 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_GLSL_TYPES_H__
|
||||
#define __ST_GLSL_TYPES_H__
|
||||
|
||||
#include "compiler/glsl_types.h"
|
||||
#include "compiler/nir/nir.h"
|
||||
#include "compiler/nir_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int st_glsl_type_dword_size(const struct glsl_type *type, bool bindless);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ST_GLSL_TYPES_H__ */
|
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
|
||||
#include "tgsi/tgsi_from_mesa.h"
|
||||
#include "st_glsl_types.h"
|
||||
#include "st_nir.h"
|
||||
|
||||
#include "compiler/nir/nir_builder.h"
|
||||
|
Reference in New Issue
Block a user