1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2022 Imagination Technologies Ltd.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
5bf215546Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal
6bf215546Sopenharmony_ci * in the Software without restriction, including without limitation the rights
7bf215546Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8bf215546Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is
9bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18bf215546Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef PVR_TEX_STATE_H
25bf215546Sopenharmony_ci#define PVR_TEX_STATE_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include <stdint.h>
28bf215546Sopenharmony_ci#include <vulkan/vulkan.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "hwdef/rogue_hw_defs.h"
31bf215546Sopenharmony_ci#include "pvr_private.h"
32bf215546Sopenharmony_ci#include "pvr_types.h"
33bf215546Sopenharmony_ci#include "util/macros.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci/**
36bf215546Sopenharmony_ci * Texture requires 32bit index lookups instead of texture coordinate access.
37bf215546Sopenharmony_ci */
38bf215546Sopenharmony_ci#define PVR_TEXFLAGS_INDEX_LOOKUP BITFIELD_BIT(0U)
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci/** Texture has border texels present. */
41bf215546Sopenharmony_ci#define PVR_TEXFLAGS_BORDER BITFIELD_BIT(1U)
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci/**
44bf215546Sopenharmony_ci * Resource is actually a buffer, not a texture, and therefore LOD is ignored.
45bf215546Sopenharmony_ci * Coordinates are integers.
46bf215546Sopenharmony_ci */
47bf215546Sopenharmony_ci#define PVR_TEXFLAGS_BUFFER BITFIELD_BIT(2U)
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci/** Parameters for #pvr_pack_tex_state(). */
50bf215546Sopenharmony_cistruct pvr_texture_state_info {
51bf215546Sopenharmony_ci   VkFormat format;
52bf215546Sopenharmony_ci   enum pvr_memlayout mem_layout;
53bf215546Sopenharmony_ci   uint32_t flags;
54bf215546Sopenharmony_ci   VkImageViewType type;
55bf215546Sopenharmony_ci   bool is_cube;
56bf215546Sopenharmony_ci   enum pvr_texture_state tex_state_type;
57bf215546Sopenharmony_ci   VkExtent3D extent;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   /**
60bf215546Sopenharmony_ci    * For array textures, this holds the array dimension, in elements. This can
61bf215546Sopenharmony_ci    * be zero if texture is not an array.
62bf215546Sopenharmony_ci    */
63bf215546Sopenharmony_ci   uint32_t array_size;
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci   /** Base mipmap level. This is the miplevel you want as the top level. */
66bf215546Sopenharmony_ci   uint32_t base_level;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   /**
69bf215546Sopenharmony_ci    * Number of mipmap levels that should be accessed by HW. This is not
70bf215546Sopenharmony_ci    * necessarily the number of levels that are in memory. (See
71bf215546Sopenharmony_ci    * mipmaps_present)
72bf215546Sopenharmony_ci    */
73bf215546Sopenharmony_ci   uint32_t mip_levels;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   /**
76bf215546Sopenharmony_ci    * True if the texture is mipmapped.
77bf215546Sopenharmony_ci    * Note: This is based on the number of mip levels the texture contains, not
78bf215546Sopenharmony_ci    * on the mip levels that are being used i.e. mip_levels.
79bf215546Sopenharmony_ci    */
80bf215546Sopenharmony_ci   bool mipmaps_present;
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci   /**
83bf215546Sopenharmony_ci    * Number of samples per texel for multisampling. This should be 1 for none
84bf215546Sopenharmony_ci    * multisampled textures.
85bf215546Sopenharmony_ci    */
86bf215546Sopenharmony_ci   uint32_t sample_count;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   /** Stride, in pixels. Only valid if mem_layout is stride or tiled. */
89bf215546Sopenharmony_ci   uint32_t stride;
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci   /**
92bf215546Sopenharmony_ci    * For buffers, where TPU_BUFFER_LOOKUP is present, this defines
93bf215546Sopenharmony_ci    * the offset for the buffer, in texels.
94bf215546Sopenharmony_ci    */
95bf215546Sopenharmony_ci   uint32_t offset;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   /**
98bf215546Sopenharmony_ci    * Precomputed (composed from createinfo->components and format swizzle)
99bf215546Sopenharmony_ci    * swizzles to pass in to the texture state.
100bf215546Sopenharmony_ci    */
101bf215546Sopenharmony_ci   uint8_t swizzle[4];
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   /** Address of texture, which must be aligned to at least 32bits. */
104bf215546Sopenharmony_ci   pvr_dev_addr_t addr;
105bf215546Sopenharmony_ci};
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ciVkResult
108bf215546Sopenharmony_cipvr_pack_tex_state(struct pvr_device *device,
109bf215546Sopenharmony_ci                   struct pvr_texture_state_info *info,
110bf215546Sopenharmony_ci                   uint64_t state[static const ROGUE_NUM_TEXSTATE_IMAGE_WORDS]);
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci#endif /* PVR_TEX_STATE_H */
113