#include "nil_image.h"
#include "nil_format.h"
-#include "util/u_math.h"
+#include "util/bitpack_helpers.h"
-#include "gallium/drivers/nouveau/nv50/g80_defs.xml.h"
-#include "gallium/drivers/nouveau/nv50/g80_texture.xml.h"
-#include "gallium/drivers/nouveau/nvc0/gm107_texture.xml.h"
+#include "nouveau/nvidia-headers/classes/clb097tex.h"
+#include "nouveau/winsys/drf.h"
+
+ALWAYS_INLINE static void
+__set_u32(uint32_t *o, uint32_t v, unsigned lo, unsigned hi)
+{
+ assert(lo <= hi && (lo / 32) == (hi / 32));
+ o[lo / 32] |= util_bitpack_uint(v, lo % 32, hi % 32);
+}
+
+ALWAYS_INLINE static void
+__set_i32(uint32_t *o, int32_t v, unsigned lo, unsigned hi)
+{
+ assert(lo <= hi && (lo / 32) == (hi / 32));
+ o[lo / 32] |= util_bitpack_sint(v, lo % 32, hi % 32);
+}
+
+ALWAYS_INLINE static void
+__set_bool(uint32_t *o, bool b, unsigned lo, unsigned hi)
+{
+ assert(lo == hi);
+ o[lo / 32] |= util_bitpack_uint(b, lo % 32, hi % 32);
+}
+
+#define MW(x) x
+
+#define TH_SET_U(o, NV, VER, FIELD, val) \
+ __set_u32((o), (val), DRF_LO(NV##_TEXHEAD_##VER##_##FIELD),\
+ DRF_HI(NV##_TEXHEAD_##VER##_##FIELD))
+
+#define TH_SET_I(o, NV, VER, FIELD, val) \
+ __set_i32((o), (val), DRF_LO(NV##_TEXHEAD_##VER##_##FIELD),\
+ DRF_HI(NV##_TEXHEAD_##VER##_##FIELD))
+
+#define TH_SET_B(o, NV, VER, FIELD, b) \
+ __set_bool((o), (b), DRF_LO(NV##_TEXHEAD_##VER##_##FIELD),\
+ DRF_HI(NV##_TEXHEAD_##VER##_##FIELD))
+
+#define TH_SET_E(o, NV, VER, FIELD, E) \
+ TH_SET_U((o), NV, VER, FIELD, NV##_TEXHEAD_##VER##_##FIELD##_##E)
static inline uint32_t
-tic_source(const struct nil_tic_format *fmt,
- enum pipe_swizzle swz, bool is_int)
+nvb097_th_bl_source(const struct nil_tic_format *fmt,
+ enum pipe_swizzle swz, bool is_int)
{
switch (swz) {
case PIPE_SWIZZLE_X: return fmt->src_x;
case PIPE_SWIZZLE_Z: return fmt->src_z;
case PIPE_SWIZZLE_W: return fmt->src_w;
case PIPE_SWIZZLE_0:
- return G80_TIC_SOURCE_ZERO;
+ return NVB097_TEXHEAD_BL_X_SOURCE_IN_ZERO;
case PIPE_SWIZZLE_1:
- return is_int ? G80_TIC_SOURCE_ONE_INT : G80_TIC_SOURCE_ONE_FLOAT;
+ return is_int ? NVB097_TEXHEAD_BL_X_SOURCE_IN_ONE_INT :
+ NVB097_TEXHEAD_BL_X_SOURCE_IN_ONE_FLOAT;
default:
unreachable("Invalid component swizzle");
}
}
static uint32_t
-gm107_tic2_0_format(enum pipe_format format,
- const enum pipe_swizzle swizzle[4])
+nvb097_th_bl_0(enum pipe_format format, const enum pipe_swizzle swizzle[4])
{
const struct nil_tic_format *fmt = nil_tic_format_for_pipe(format);
const bool is_int = util_format_is_pure_integer(format);
uint32_t source[4];
for (unsigned i = 0; i < 4; i++)
- source[i] = tic_source(fmt, swizzle[i], is_int);
-
- uint32_t tic;
- tic = fmt->comp_sizes << GM107_TIC2_0_COMPONENTS_SIZES__SHIFT;
- tic |= fmt->type_r << GM107_TIC2_0_R_DATA_TYPE__SHIFT;
- tic |= fmt->type_g << GM107_TIC2_0_G_DATA_TYPE__SHIFT;
- tic |= fmt->type_b << GM107_TIC2_0_B_DATA_TYPE__SHIFT;
- tic |= fmt->type_a << GM107_TIC2_0_A_DATA_TYPE__SHIFT;
- tic |= source[0] << GM107_TIC2_0_X_SOURCE__SHIFT;
- tic |= source[1] << GM107_TIC2_0_Y_SOURCE__SHIFT;
- tic |= source[2] << GM107_TIC2_0_Z_SOURCE__SHIFT;
- tic |= source[3] << GM107_TIC2_0_W_SOURCE__SHIFT;
-
- return tic;
+ source[i] = nvb097_th_bl_source(fmt, swizzle[i], is_int);
+
+ uint32_t th_0 = 0;
+ TH_SET_U(&th_0, NVB097, BL, COMPONENTS, fmt->comp_sizes);
+ TH_SET_U(&th_0, NVB097, BL, R_DATA_TYPE, fmt->type_r);
+ TH_SET_U(&th_0, NVB097, BL, G_DATA_TYPE, fmt->type_g);
+ TH_SET_U(&th_0, NVB097, BL, B_DATA_TYPE, fmt->type_b);
+ TH_SET_U(&th_0, NVB097, BL, A_DATA_TYPE, fmt->type_a);
+ TH_SET_U(&th_0, NVB097, BL, X_SOURCE, source[0]);
+ TH_SET_U(&th_0, NVB097, BL, Y_SOURCE, source[1]);
+ TH_SET_U(&th_0, NVB097, BL, Z_SOURCE, source[2]);
+ TH_SET_U(&th_0, NVB097, BL, W_SOURCE, source[3]);
+
+ return th_0;
}
static uint32_t
-gm107_tic2_4_view_type(enum nil_view_type type)
+nil_to_nvb097_texture_type(enum nil_view_type type)
{
+#define CASE(NIL, NV) \
+ case NIL_VIEW_TYPE_##NIL: return NVB097_TEXHEAD_BL_TEXTURE_TYPE_##NV;
+
switch (type) {
- case NIL_VIEW_TYPE_1D:
- return GM107_TIC2_4_TEXTURE_TYPE_ONE_D;
- case NIL_VIEW_TYPE_2D:
- return GM107_TIC2_4_TEXTURE_TYPE_TWO_D;
- case NIL_VIEW_TYPE_3D:
- return GM107_TIC2_4_TEXTURE_TYPE_THREE_D;
- case NIL_VIEW_TYPE_CUBE:
- return GM107_TIC2_4_TEXTURE_TYPE_CUBEMAP;
- case NIL_VIEW_TYPE_1D_ARRAY:
- return GM107_TIC2_4_TEXTURE_TYPE_ONE_D_ARRAY;
- case NIL_VIEW_TYPE_2D_ARRAY:
- return GM107_TIC2_4_TEXTURE_TYPE_TWO_D_ARRAY;
- case NIL_VIEW_TYPE_CUBE_ARRAY:
- return GM107_TIC2_4_TEXTURE_TYPE_CUBE_ARRAY;
- default:
- unreachable("Invalid image view type");
+ CASE(1D, ONE_D);
+ CASE(2D, TWO_D);
+ CASE(3D, THREE_D);
+ CASE(CUBE, CUBEMAP);
+ CASE(1D_ARRAY, ONE_D_ARRAY);
+ CASE(2D_ARRAY, TWO_D_ARRAY);
+ CASE(CUBE_ARRAY, CUBEMAP_ARRAY);
+ default: unreachable("Invalid image view type");
}
+
+#undef CASE
}
static uint32_t
-gm107_tic7_4_multi_sample_count(uint32_t samples)
+uint_to_nvb097_multi_sample_count(uint32_t samples)
{
switch (samples) {
- case 1: return GM107_TIC2_7_MULTI_SAMPLE_COUNT_1X1;
- case 2: return GM107_TIC2_7_MULTI_SAMPLE_COUNT_2X1;
- case 4: return GM107_TIC2_7_MULTI_SAMPLE_COUNT_2X2;
- case 8: return GM107_TIC2_7_MULTI_SAMPLE_COUNT_4X2;
- case 16: return GM107_TIC2_7_MULTI_SAMPLE_COUNT_4X4;
+ case 1: return NVB097_TEXHEAD_BL_MULTI_SAMPLE_COUNT_MODE_1X1;
+ case 2: return NVB097_TEXHEAD_BL_MULTI_SAMPLE_COUNT_MODE_2X1;
+ case 4: return NVB097_TEXHEAD_BL_MULTI_SAMPLE_COUNT_MODE_2X2;
+ case 8: return NVB097_TEXHEAD_BL_MULTI_SAMPLE_COUNT_MODE_4X2;
+ case 16: return NVB097_TEXHEAD_BL_MULTI_SAMPLE_COUNT_MODE_4X4;
default:
unreachable("Unsupported sample count");
}
assert(view->base_level + view->num_levels <= image->num_levels);
assert(view->base_array_layer + view->array_len <= image->extent_px.a);
- uint32_t tic[8] = { };
-
- tic[0] = gm107_tic2_0_format(view->format, view->swizzle);
+ uint32_t th[8] = { };
- tic[3] |= GM107_TIC2_3_LOD_ANISO_QUALITY_2;
- tic[4] |= GM107_TIC2_4_SECTOR_PROMOTION_PROMOTE_TO_2_V;
- tic[4] |= GM107_TIC2_4_BORDER_SIZE_SAMPLER_COLOR;
+ th[0] = nvb097_th_bl_0(view->format, view->swizzle);
- if (util_format_is_srgb(view->format))
- tic[4] |= GM107_TIC2_4_SRGB_CONVERSION;
-
- /* TODO: Unnormalized? */
- tic[5] |= GM107_TIC2_5_NORMALIZED_COORDS;
-
- tic[2] |= GM107_TIC2_2_HEADER_VERSION_BLOCKLINEAR;
- assert(image->levels[0].tiling.gob_height_8);
- tic[3] |= (uint32_t)image->levels[0].tiling.y_log2 <<
- GM107_TIC2_3_GOBS_PER_BLOCK_HEIGHT__SHIFT;
- tic[3] |= (uint32_t)image->levels[0].tiling.z_log2 <<
- GM107_TIC2_3_GOBS_PER_BLOCK_DEPTH__SHIFT;
-
- /* There doesn't seem to be a base layer field in TIC */
+ /* There's no base layer field in the texture header */
const uint64_t layer_address =
base_address + view->base_array_layer * image->array_stride_B;
- tic[1] = layer_address;
- tic[2] |= layer_address >> 32;
+ assert((layer_address & BITFIELD_MASK(9)) == 0);
+ TH_SET_U(th, NVB097, BL, ADDRESS_BITS31TO9, (uint32_t)layer_address >> 9);
+ TH_SET_U(th, NVB097, BL, ADDRESS_BITS47TO32, layer_address >> 32);
+
+ TH_SET_E(th, NVB097, BL, HEADER_VERSION, SELECT_BLOCKLINEAR);
- tic[4] |= gm107_tic2_4_view_type(view->type);
+ const struct nil_tiling *tiling = &image->levels[0].tiling;
+ assert(tiling->is_tiled);
+ assert(tiling->gob_height_8);
+ TH_SET_E(th, NVB097, BL, GOBS_PER_BLOCK_WIDTH, ONE_GOB);
+ TH_SET_U(th, NVB097, BL, GOBS_PER_BLOCK_HEIGHT, tiling->y_log2);
+ TH_SET_U(th, NVB097, BL, GOBS_PER_BLOCK_DEPTH, tiling->z_log2);
- /* TODO: NV50_TEXVIEW_FILTER_MSAA8 */
- tic[3] |= GM107_TIC2_3_LOD_ANISO_QUALITY_HIGH |
- GM107_TIC2_3_LOD_ISO_QUALITY_HIGH;
+ TH_SET_B(th, NVB097, BL, LOD_ANISO_QUALITY2, true);
+ TH_SET_E(th, NVB097, BL, LOD_ANISO_QUALITY, LOD_QUALITY_HIGH);
+ TH_SET_E(th, NVB097, BL, LOD_ISO_QUALITY, LOD_QUALITY_HIGH);
+ TH_SET_E(th, NVB097, BL, ANISO_COARSE_SPREAD_MODIFIER, SPREAD_MODIFIER_NONE);
const uint32_t width = image->extent_px.width;
const uint32_t height = image->extent_px.height;
unreachable("Unsupported image view target");
};
- tic[4] |= (width - 1) << GM107_TIC2_4_WIDTH_MINUS_ONE__SHIFT;
- tic[5] |= (height - 1) << GM107_TIC2_5_HEIGHT_MINUS_ONE__SHIFT;
- tic[5] |= (depth - 1) << GM107_TIC2_5_DEPTH_MINUS_ONE__SHIFT;
+ TH_SET_U(th, NVB097, BL, WIDTH_MINUS_ONE, width - 1);
+ TH_SET_U(th, NVB097, BL, HEIGHT_MINUS_ONE, height - 1);
+ TH_SET_U(th, NVB097, BL, DEPTH_MINUS_ONE, depth - 1);
const uint32_t last_level = view->num_levels + view->base_level - 1;
- tic[3] |= last_level << GM107_TIC2_3_MAX_MIP_LEVEL__SHIFT;
+ TH_SET_U(th, NVB097, BL, MAX_MIP_LEVEL, last_level);
- tic[6] |= GM107_TIC2_6_ANISO_FINE_SPREAD_FUNC_TWO;
- tic[6] |= GM107_TIC2_6_ANISO_COARSE_SPREAD_FUNC_ONE;
+ TH_SET_U(th, NVB097, BL, TEXTURE_TYPE,
+ nil_to_nvb097_texture_type(view->type));
- tic[7] |= (last_level << 4) | view->base_level;
- tic[7] |= gm107_tic7_4_multi_sample_count(image->num_samples);
+ TH_SET_B(th, NVB097, BL, S_R_G_B_CONVERSION,
+ util_format_is_srgb(view->format));
- memcpy(desc_out, tic, sizeof(tic));
+ TH_SET_E(th, NVB097, BL, SECTOR_PROMOTION, PROMOTE_TO_2_V);
+ TH_SET_E(th, NVB097, BL, BORDER_SIZE, BORDER_SAMPLER_COLOR);
+
+ /* TODO: Unnormalized? */
+ TH_SET_B(th, NVB097, BL, NORMALIZED_COORDS, true);
+
+ TH_SET_E(th, NVB097, BL, ANISO_FINE_SPREAD_FUNC, SPREAD_FUNC_TWO);
+ TH_SET_E(th, NVB097, BL, ANISO_COARSE_SPREAD_FUNC, SPREAD_FUNC_TWO);
+
+ TH_SET_U(th, NVB097, BL, RES_VIEW_MIN_MIP_LEVEL, view->base_level);
+ TH_SET_U(th, NVB097, BL, RES_VIEW_MAX_MIP_LEVEL, last_level);
+ TH_SET_U(th, NVB097, BL, MULTI_SAMPLE_COUNT,
+ uint_to_nvb097_multi_sample_count(image->num_samples));
+
+ memcpy(desc_out, th, sizeof(th));
}
void
PIPE_SWIZZLE_Z,
PIPE_SWIZZLE_W,
};
- uint32_t tic[8] = { };
+ uint32_t th[8] = { };
assert(!util_format_is_compressed(format));
- tic[0] |= gm107_tic2_0_format(format, identity_swizzle);
- tic[1] |= base_address;
- tic[2] |= base_address >> 32;
- tic[2] |= GM107_TIC2_2_HEADER_VERSION_ONE_D_BUFFER;
- tic[3] |= (num_elements - 1) >> 16;
- tic[4] |= (num_elements - 1) & 0xffff;
- tic[4] |= GM107_TIC2_4_TEXTURE_TYPE_ONE_D_BUFFER;
-
- /* TODO: Do we need these two? */
- tic[4] |= GM107_TIC2_4_SECTOR_PROMOTION_PROMOTE_TO_2_V;
- tic[4] |= GM107_TIC2_4_BORDER_SIZE_SAMPLER_COLOR;
-
- memcpy(desc_out, tic, sizeof(tic));
+ th[0] = nvb097_th_bl_0(format, identity_swizzle);
+
+ TH_SET_U(th, NVB097, 1D, ADDRESS_BITS31TO0, base_address);
+ TH_SET_U(th, NVB097, 1D, ADDRESS_BITS47TO32, base_address >> 32);
+ TH_SET_E(th, NVB097, 1D, HEADER_VERSION, SELECT_ONE_D_BUFFER);
+
+ TH_SET_U(th, NVB097, 1D, WIDTH_MINUS_ONE_BITS15TO0,
+ (num_elements - 1) & 0xffff);
+ TH_SET_U(th, NVB097, 1D, WIDTH_MINUS_ONE_BITS31TO16,
+ (num_elements - 1) >> 16);
+
+ TH_SET_E(th, NVB097, 1D, TEXTURE_TYPE, ONE_D_BUFFER);
+
+ /* TODO: Do we need this? */
+ TH_SET_E(th, NVB097, 1D, SECTOR_PROMOTION, PROMOTE_TO_2_V);
+
+ memcpy(desc_out, th, sizeof(th));
}