#define VK_PROTOTYPES
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_intel.h>
-#include <vulkan/vk_wsi_lunarg.h>
+#include <vulkan/vk_ext_khr_swapchain.h>
+#include <vulkan/vk_ext_khr_device_swapchain.h>
#include "anv_entrypoints.h"
extern "C" {
#endif
+#define ICD_LOADER_MAGIC 0x01CDC0DE
+
+typedef union _VK_LOADER_DATA {
+ uintptr_t loaderMagic;
+ void *loaderData;
+} VK_LOADER_DATA;
+
#define anv_noreturn __attribute__((__noreturn__))
#define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
(b) = __builtin_ffs(__dword) - 1, __dword; \
__dword &= ~(1 << (b)))
+#define typed_memcpy(dest, src, count) ({ \
+ static_assert(sizeof(*src) == sizeof(*dest), ""); \
+ memcpy((dest), (src), (count) * sizeof(*(src))); \
+})
+
/* Define no kernel as 1, since that's an illegal offset for a kernel */
#define NO_KERNEL 1
* propagating errors. Might be useful to plug in a stack trace here.
*/
-static inline VkResult
-vk_error(VkResult error)
-{
+VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
+
#ifdef DEBUG
- fprintf(stderr, "vk_error: %x\n", error);
+#define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
+#define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
+#else
+#define vk_error(error) error
+#define vk_errorf(error, format, ...) error
#endif
- return error;
-}
-
void __anv_finishme(const char *file, int line, const char *format, ...)
anv_printflike(3, 4);
void anv_loge(const char *format, ...) anv_printflike(1, 2);
#define anv_assert(x)
#endif
+/**
+ * If a block of code is annotated with anv_validate, then the block runs only
+ * in debug builds.
+ */
+#ifdef DEBUG
+#define anv_validate if (1)
+#else
+#define anv_validate if (0)
+#endif
+
void anv_abortf(const char *format, ...) anv_noreturn anv_printflike(1, 2);
void anv_abortfv(const char *format, va_list va) anv_noreturn;
return (queue->head - queue->tail) / queue->element_size;
}
+static inline void *
+anv_vector_head(struct anv_vector *vector)
+{
+ assert(vector->tail < vector->head);
+ return (void *)((char *)vector->data +
+ ((vector->head - vector->element_size) &
+ (vector->size - 1)));
+}
+
+static inline void *
+anv_vector_tail(struct anv_vector *vector)
+{
+ return (void *)((char *)vector->data + (vector->tail & (vector->size - 1)));
+}
+
static inline void
anv_vector_finish(struct anv_vector *queue)
{
struct anv_bo {
int gem_handle;
+
+ /* Index into the current validation list. This is used by the
+ * validation list building alrogithm to track which buffers are already
+ * in the validation list so that we can ensure uniqueness.
+ */
uint32_t index;
+
+ /* Last known offset. This value is provided by the kernel when we
+ * execbuf and is used as the presumed offset for the next bunch of
+ * relocations.
+ */
uint64_t offset;
+
uint64_t size;
void *map;
};
*/
union anv_free_list {
struct {
- uint32_t offset;
+ int32_t offset;
/* A simple count that is incremented every time the head changes. */
uint32_t count;
struct anv_device *device;
struct anv_bo bo;
+
+ /* The offset from the start of the bo to the "center" of the block
+ * pool. Pointers to allocated blocks are given by
+ * bo.map + center_bo_offset + offsets.
+ */
+ uint32_t center_bo_offset;
+
+ /* Current memory map of the block pool. This pointer may or may not
+ * point to the actual beginning of the block pool memory. If
+ * anv_block_pool_alloc_back has ever been called, then this pointer
+ * will point to the "center" position of the buffer and all offsets
+ * (negative or positive) given out by the block pool alloc functions
+ * will be valid relative to this pointer.
+ *
+ * In particular, map == bo.map + center_offset
+ */
void *map;
int fd;
union anv_free_list free_list;
struct anv_block_state state;
+
+ union anv_free_list back_free_list;
+ struct anv_block_state back_state;
};
+/* Block pools are backed by a fixed-size 2GB memfd */
+#define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
+
+/* The center of the block pool is also the middle of the memfd. This may
+ * change in the future if we decide differently for some reason.
+ */
+#define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
+
static inline uint32_t
anv_block_pool_size(struct anv_block_pool *pool)
{
- return pool->state.end;
+ return pool->state.end + pool->back_state.end;
}
struct anv_state {
- uint32_t offset;
+ int32_t offset;
uint32_t alloc_size;
void *map;
};
void anv_block_pool_init(struct anv_block_pool *pool,
struct anv_device *device, uint32_t block_size);
void anv_block_pool_finish(struct anv_block_pool *pool);
-uint32_t anv_block_pool_alloc(struct anv_block_pool *pool);
-void anv_block_pool_free(struct anv_block_pool *pool, uint32_t offset);
+int32_t anv_block_pool_alloc(struct anv_block_pool *pool);
+int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool);
+void anv_block_pool_free(struct anv_block_pool *pool, int32_t offset);
void anv_state_pool_init(struct anv_state_pool *pool,
struct anv_block_pool *block_pool);
void anv_state_pool_finish(struct anv_state_pool *pool);
VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo);
void anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo);
+
+void *anv_resolve_entrypoint(uint32_t index);
+
+extern struct anv_dispatch_table dtable;
+
+#define ANV_CALL(func) ({ \
+ if (dtable.func == NULL) { \
+ size_t idx = offsetof(struct anv_dispatch_table, func) / sizeof(void *); \
+ dtable.entrypoints[idx] = anv_resolve_entrypoint(idx); \
+ } \
+ dtable.func; \
+})
+
+
struct anv_physical_device {
+ VK_LOADER_DATA _loader_data;
+
struct anv_instance * instance;
uint32_t chipset_id;
const char * path;
const char * name;
const struct brw_device_info * info;
uint64_t aperture_size;
+ struct brw_compiler * compiler;
};
+bool anv_is_scalar_shader_stage(const struct brw_compiler *compiler,
+ VkShaderStage stage);
+
struct anv_instance {
+ VK_LOADER_DATA _loader_data;
+
void * pAllocUserData;
PFN_vkAllocFunction pfnAlloc;
PFN_vkFreeFunction pfnFree;
uint32_t apiVersion;
- uint32_t physicalDeviceCount;
+ int physicalDeviceCount;
struct anv_physical_device physicalDevice;
+
+ struct anv_wsi_implementation * wsi_impl[VK_PLATFORM_NUM_KHR];
};
+VkResult anv_init_wsi(struct anv_instance *instance);
+void anv_finish_wsi(struct anv_instance *instance);
+
struct anv_meta_state {
struct {
- VkPipeline pipeline;
+ struct anv_pipeline *color_pipeline;
+ struct anv_pipeline *depth_only_pipeline;
+ struct anv_pipeline *stencil_only_pipeline;
+ struct anv_pipeline *depthstencil_pipeline;
} clear;
struct {
- VkPipeline pipeline;
+ VkRenderPass render_pass;
+
+ /** Pipeline that blits from a 2D image. */
+ VkPipeline pipeline_2d_src;
+
+ /** Pipeline that blits from a 3D image. */
+ VkPipeline pipeline_3d_src;
+
VkPipelineLayout pipeline_layout;
VkDescriptorSetLayout ds_layout;
} blit;
-
- struct {
- VkDynamicRasterState rs_state;
- VkDynamicColorBlendState cb_state;
- VkDynamicDepthStencilState ds_state;
- } shared;
};
struct anv_queue {
+ VK_LOADER_DATA _loader_data;
+
struct anv_device * device;
struct anv_state_pool * pool;
-
- /**
- * Serial number of the most recently completed batch executed on the
- * engine.
- */
- struct anv_state completed_serial;
-
- /**
- * The next batch submitted to the engine will be assigned this serial
- * number.
- */
- uint32_t next_serial;
-
- uint32_t last_collected_serial;
};
struct anv_device {
+ VK_LOADER_DATA _loader_data;
+
struct anv_instance * instance;
uint32_t chipset_id;
struct brw_device_info info;
struct anv_block_pool scratch_block_pool;
- struct anv_compiler * compiler;
pthread_mutex_t mutex;
};
+void *
+anv_instance_alloc(struct anv_instance * instance,
+ size_t size,
+ size_t alignment,
+ VkSystemAllocType allocType);
+
+void
+anv_instance_free(struct anv_instance * instance,
+ void * mem);
+
void *
anv_device_alloc(struct anv_device * device,
size_t size,
/* Bytes actually consumed in this batch BO */
size_t length;
+ /* Last seen surface state block pool bo offset */
+ uint32_t last_ss_pool_bo_offset;
+
struct anv_reloc_list relocs;
};
const struct anv_address address, uint32_t delta)
{
if (address.bo == NULL) {
- return delta;
+ return address.offset + delta;
} else {
assert(batch->start <= location && location < batch->end);
static const struct GEN7_MEMORY_OBJECT_CONTROL_STATE GEN7_MOCS = {
.GraphicsDataTypeGFDT = 0,
.LLCCacheabilityControlLLCCC = 0,
- .L3CacheabilityControlL3CC = 0
+ .L3CacheabilityControlL3CC = 1
};
#define GEN8_MOCS { \
void * map;
};
-struct anv_dynamic_vp_state {
- struct anv_state sf_clip_vp;
- struct anv_state cc_vp;
- struct anv_state scissor;
+/**
+ * Header for Vertex URB Entry (VUE)
+ */
+struct anv_vue_header {
+ uint32_t Reserved;
+ uint32_t RTAIndex; /* RenderTargetArrayIndex */
+ uint32_t ViewportIndex;
+ float PointWidth;
};
-struct anv_dynamic_rs_state {
- struct {
- uint32_t sf[GEN7_3DSTATE_SF_length];
- } gen7;
+struct anv_descriptor_set_binding_layout {
+ /* Number of array elements in this binding */
+ uint16_t array_size;
- struct {
- uint32_t sf[GEN8_3DSTATE_SF_length];
- uint32_t raster[GEN8_3DSTATE_RASTER_length];
- } gen8;
-};
+ /* Index into the flattend descriptor set */
+ uint16_t descriptor_index;
-struct anv_dynamic_ds_state {
- struct {
- uint32_t depth_stencil_state[GEN7_DEPTH_STENCIL_STATE_length];
- uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
- } gen7;
+ /* Index into the dynamic state array for a dynamic buffer */
+ int16_t dynamic_offset_index;
struct {
- uint32_t wm_depth_stencil[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
- uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
- } gen8;
-};
-
-struct anv_dynamic_cb_state {
- uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
+ /* Index into the binding table for the associated surface */
+ int16_t surface_index;
-};
+ /* Index into the sampler table for the associated sampler */
+ int16_t sampler_index;
+ } stage[VK_SHADER_STAGE_NUM];
-struct anv_descriptor_slot {
- int8_t dynamic_slot;
- uint8_t index;
+ /* Immutable samplers (or NULL if no immutable samplers) */
+ struct anv_sampler **immutable_samplers;
};
struct anv_descriptor_set_layout {
- struct {
- uint32_t surface_count;
- struct anv_descriptor_slot *surface_start;
- uint32_t sampler_count;
- struct anv_descriptor_slot *sampler_start;
- } stage[VK_SHADER_STAGE_NUM];
+ /* Number of bindings in this descriptor set */
+ uint16_t binding_count;
+
+ /* Total size of the descriptor set with room for all array entries */
+ uint16_t size;
+
+ /* Shader stages affected by this descriptor set */
+ uint16_t shader_stages;
+
+ /* Number of dynamic offsets used by this descriptor set */
+ uint16_t dynamic_offset_count;
- uint32_t count;
- uint32_t num_dynamic_buffers;
- uint32_t shader_stages;
- struct anv_descriptor_slot entries[0];
+ /* Bindings in this descriptor set */
+ struct anv_descriptor_set_binding_layout binding[0];
};
struct anv_descriptor {
- struct anv_sampler *sampler;
- struct anv_surface_view *view;
+ VkDescriptorType type;
+
+ union {
+ struct {
+ union {
+ struct anv_image_view *image_view;
+ };
+ struct anv_sampler *sampler;
+ };
+
+ struct {
+ struct anv_buffer *buffer;
+ uint64_t offset;
+ uint64_t range;
+ };
+ };
};
struct anv_descriptor_set {
+ const struct anv_descriptor_set_layout *layout;
struct anv_descriptor descriptors[0];
};
anv_descriptor_set_destroy(struct anv_device *device,
struct anv_descriptor_set *set);
-#define MAX_VBS 32
-#define MAX_SETS 8
-#define MAX_RTS 8
+#define MAX_VBS 32
+#define MAX_SETS 8
+#define MAX_RTS 8
+#define MAX_VIEWPORTS 16
+#define MAX_SCISSORS 16
+#define MAX_PUSH_CONSTANTS_SIZE 128
+#define MAX_DYNAMIC_BUFFERS 16
+#define MAX_IMAGES 8
+
+struct anv_pipeline_binding {
+ /* The descriptor set this surface corresponds to */
+ uint16_t set;
+
+ /* Offset into the descriptor set */
+ uint16_t offset;
+};
struct anv_pipeline_layout {
struct {
struct anv_descriptor_set_layout *layout;
- uint32_t surface_start[VK_SHADER_STAGE_NUM];
- uint32_t sampler_start[VK_SHADER_STAGE_NUM];
+ uint32_t dynamic_offset_start;
+ struct {
+ uint32_t surface_start;
+ uint32_t sampler_start;
+ } stage[VK_SHADER_STAGE_NUM];
} set[MAX_SETS];
uint32_t num_sets;
struct {
+ bool has_dynamic_offsets;
uint32_t surface_count;
+ struct anv_pipeline_binding *surface_to_descriptor;
uint32_t sampler_count;
+ struct anv_pipeline_binding *sampler_to_descriptor;
} stage[VK_SHADER_STAGE_NUM];
+
+ struct anv_pipeline_binding entries[0];
};
struct anv_buffer {
VkDeviceSize offset;
};
-#define ANV_CMD_BUFFER_PIPELINE_DIRTY (1 << 0)
-#define ANV_CMD_BUFFER_RS_DIRTY (1 << 2)
-#define ANV_CMD_BUFFER_DS_DIRTY (1 << 3)
-#define ANV_CMD_BUFFER_CB_DIRTY (1 << 4)
-#define ANV_CMD_BUFFER_VP_DIRTY (1 << 5)
-#define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY (1 << 6)
+enum anv_cmd_dirty_bits {
+ ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
+ ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
+ ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
+ ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
+ ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
+ ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
+ ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
+ ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
+ ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
+ ANV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
+ ANV_CMD_DIRTY_PIPELINE = 1 << 9,
+ ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
+};
+typedef uint32_t anv_cmd_dirty_mask_t;
struct anv_vertex_binding {
struct anv_buffer * buffer;
VkDeviceSize offset;
};
-struct anv_descriptor_set_binding {
- struct anv_descriptor_set * set;
- uint32_t dynamic_offsets[128];
+struct anv_push_constants {
+ /* Current allocated size of this push constants data structure.
+ * Because a decent chunk of it may not be used (images on SKL, for
+ * instance), we won't actually allocate the entire structure up-front.
+ */
+ uint32_t size;
+
+ /* Push constant data provided by the client through vkPushConstants */
+ uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
+
+ /* Our hardware only provides zero-based vertex and instance id so, in
+ * order to satisfy the vulkan requirements, we may have to push one or
+ * both of these into the shader.
+ */
+ uint32_t base_vertex;
+ uint32_t base_instance;
+
+ /* Offsets and ranges for dynamically bound buffers */
+ struct {
+ uint32_t offset;
+ uint32_t range;
+ } dynamic[MAX_DYNAMIC_BUFFERS];
+
+ /* Image data for image_load_store on pre-SKL */
+ struct brw_image_param images[MAX_IMAGES];
+};
+
+struct anv_dynamic_state {
+ struct {
+ uint32_t count;
+ VkViewport viewports[MAX_VIEWPORTS];
+ } viewport;
+
+ struct {
+ uint32_t count;
+ VkRect2D scissors[MAX_SCISSORS];
+ } scissor;
+
+ float line_width;
+
+ struct {
+ float bias;
+ float clamp;
+ float slope_scaled;
+ } depth_bias;
+
+ float blend_constants[4];
+
+ struct {
+ float min;
+ float max;
+ } depth_bounds;
+
+ struct {
+ uint32_t front;
+ uint32_t back;
+ } stencil_compare_mask;
+
+ struct {
+ uint32_t front;
+ uint32_t back;
+ } stencil_write_mask;
+
+ struct {
+ uint32_t front;
+ uint32_t back;
+ } stencil_reference;
};
+extern const struct anv_dynamic_state default_dynamic_state;
+
+void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
+ const struct anv_dynamic_state *src,
+ uint32_t copy_mask);
+
/** State required while building cmd buffer */
struct anv_cmd_state {
uint32_t current_pipeline;
uint32_t vb_dirty;
- uint32_t dirty;
- uint32_t compute_dirty;
- uint32_t descriptors_dirty;
+ anv_cmd_dirty_mask_t dirty;
+ anv_cmd_dirty_mask_t compute_dirty;
+ VkShaderStageFlags descriptors_dirty;
+ VkShaderStageFlags push_constants_dirty;
uint32_t scratch_size;
struct anv_pipeline * pipeline;
struct anv_pipeline * compute_pipeline;
struct anv_framebuffer * framebuffer;
struct anv_render_pass * pass;
struct anv_subpass * subpass;
- struct anv_dynamic_rs_state * rs_state;
- struct anv_dynamic_ds_state * ds_state;
- struct anv_dynamic_vp_state * vp_state;
- struct anv_dynamic_cb_state * cb_state;
uint32_t state_vf[GEN8_3DSTATE_VF_length];
struct anv_vertex_binding vertex_bindings[MAX_VBS];
- struct anv_descriptor_set_binding descriptors[MAX_SETS];
+ struct anv_descriptor_set * descriptors[MAX_SETS];
+ struct anv_push_constants * push_constants[VK_SHADER_STAGE_NUM];
+ struct anv_dynamic_state dynamic;
struct {
struct anv_buffer * index_buffer;
- uint32_t index_type;
+ uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
uint32_t index_offset;
} gen7;
};
};
struct anv_cmd_buffer {
+ VK_LOADER_DATA _loader_data;
+
struct anv_device * device;
struct list_head pool_link;
* These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
*/
struct list_head batch_bos;
- struct list_head surface_bos;
- uint32_t surface_next;
enum anv_cmd_buffer_exec_mode exec_mode;
/* A vector of anv_batch_bo pointers for every batch or surface buffer
*/
struct anv_vector seen_bbos;
+ /* A vector of int32_t's for every block of binding tables.
+ *
+ * initialized by anv_cmd_buffer_init_batch_bo_chain()
+ */
+ struct anv_vector bt_blocks;
+ uint32_t bt_next;
+ struct anv_reloc_list surface_relocs;
+
/* Information needed for execbuf
*
* These fields are generated by anv_cmd_buffer_prepare_execbuf().
void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer *cmd_buffer,
struct anv_subpass *subpass);
-struct anv_bo *
-anv_cmd_buffer_current_surface_bo(struct anv_cmd_buffer *cmd_buffer);
-struct anv_reloc_list *
-anv_cmd_buffer_current_surface_relocs(struct anv_cmd_buffer *cmd_buffer);
+struct anv_address
+anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
struct anv_state
-anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer,
- uint32_t size, uint32_t alignment);
+anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
+ uint32_t entries, uint32_t *state_offset);
+struct anv_state
+anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
struct anv_state
anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
uint32_t size, uint32_t alignment);
-VkResult anv_cmd_buffer_new_surface_state_bo(struct anv_cmd_buffer *cmd_buffer);
+VkResult
+anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
+
+void anv_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
+void anv_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer *cmd_buffer,
struct anv_subpass *subpass);
+struct anv_state
+anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
+ VkShaderStage stage);
+
void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
struct anv_render_pass *pass,
const VkClearValue *clear_values);
+const struct anv_image_view *
+anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
bool ready;
};
+struct nir_shader;
+
struct anv_shader_module {
+ struct nir_shader * nir;
+
uint32_t size;
char data[0];
};
struct anv_pipeline {
struct anv_device * device;
struct anv_batch batch;
- uint32_t batch_data[256];
+ uint32_t batch_data[512];
struct anv_reloc_list batch_relocs;
- struct anv_shader * shaders[VK_SHADER_STAGE_NUM];
+ uint32_t dynamic_state_mask;
+ struct anv_dynamic_state dynamic_state;
+
struct anv_pipeline_layout * layout;
bool use_repclear;
uint32_t nr_gs_entries;
} urb;
- uint32_t active_stages;
+ VkShaderStageFlags active_stages;
struct anv_state_stream program_stream;
struct anv_state blend_state;
uint32_t vs_simd8;
const VkGraphicsPipelineCreateInfo *pCreateInfo,
const struct anv_graphics_pipeline_create_info *extra);
+VkResult
+anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
+ const VkComputePipelineCreateInfo *info,
+ struct anv_shader *shader);
+
VkResult
anv_graphics_pipeline_create(VkDevice device,
const VkGraphicsPipelineCreateInfo *pCreateInfo,
const VkComputePipelineCreateInfo *pCreateInfo,
VkPipeline *pPipeline);
-struct anv_compiler *anv_compiler_create(struct anv_device *device);
-void anv_compiler_destroy(struct anv_compiler *compiler);
-int anv_compiler_run(struct anv_compiler *compiler, struct anv_pipeline *pipeline);
-void anv_compiler_free(struct anv_pipeline *pipeline);
-
struct anv_format {
const VkFormat vk_format;
const char *name;
uint16_t surface_format; /**< RENDER_SURFACE_STATE.SurfaceFormat */
- uint8_t cpp; /**< Bytes-per-pixel of anv_format::surface_format. */
+ uint8_t bs; /**< Block size (in bytes) of anv_format::surface_format. */
uint8_t num_channels;
uint16_t depth_format; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
bool has_stencil;
bool is_cube:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
};
-const struct anv_image_view_info *
+struct anv_image_view_info
anv_image_view_info_for_vk_image_view_type(VkImageViewType type);
/**
VkExtent3D extent;
uint32_t levels;
uint32_t array_size;
+ VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
VkDeviceSize size;
uint32_t alignment;
struct anv_bo *bo;
VkDeviceSize offset;
- struct anv_swap_chain *swap_chain;
-
- /** RENDER_SURFACE_STATE.SurfaceType */
- uint8_t surf_type;
-
- /** Primary surface is either color or depth. */
- struct anv_surface primary_surface;
+ uint8_t surface_type; /**< RENDER_SURFACE_STATE.SurfaceType */
- /** Stencil surface is optional. */
- struct anv_surface stencil_surface;
-};
+ bool needs_nonrt_surface_state:1;
+ bool needs_color_rt_surface_state:1;
-struct anv_surface_view {
- struct anv_state surface_state; /**< RENDER_SURFACE_STATE */
- struct anv_bo *bo;
- uint32_t offset; /**< VkBufferCreateInfo::offset */
- uint32_t range; /**< VkBufferCreateInfo::range */
- const struct anv_format *format; /**< VkBufferCreateInfo::format */
-};
+ /**
+ * Image subsurfaces
+ *
+ * For each foo, anv_image::foo_surface is valid if and only if
+ * anv_image::format has a foo aspect.
+ *
+ * The hardware requires that the depth buffer and stencil buffer be
+ * separate surfaces. From Vulkan's perspective, though, depth and stencil
+ * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
+ * allocate the depth and stencil buffers as separate surfaces in the same
+ * bo.
+ */
+ union {
+ struct anv_surface color_surface;
-struct anv_buffer_view {
- struct anv_surface_view view;
+ struct {
+ struct anv_surface depth_surface;
+ struct anv_surface stencil_surface;
+ };
+ };
};
struct anv_image_view {
- struct anv_surface_view view;
- VkExtent3D extent;
-};
-
-enum anv_attachment_view_type {
- ANV_ATTACHMENT_VIEW_TYPE_COLOR,
- ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL,
-};
-
-struct anv_attachment_view {
- enum anv_attachment_view_type attachment_type;
- VkExtent3D extent;
-};
-
-struct anv_color_attachment_view {
- struct anv_attachment_view base;
- struct anv_surface_view view;
-};
-
-struct anv_depth_stencil_view {
- struct anv_attachment_view base;
-
+ const struct anv_image *image; /**< VkImageViewCreateInfo::image */
+ const struct anv_format *format; /**< VkImageViewCreateInfo::format */
struct anv_bo *bo;
+ uint32_t offset; /**< Offset into bo. */
+ VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
- uint32_t depth_offset; /**< Offset into bo. */
- uint32_t depth_stride; /**< 3DSTATE_DEPTH_BUFFER.SurfacePitch */
- uint32_t depth_format; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
- uint16_t depth_qpitch; /**< 3DSTATE_DEPTH_BUFFER.SurfaceQPitch */
+ /** RENDER_SURFACE_STATE when using image as a color render target. */
+ struct anv_state color_rt_surface_state;
- uint32_t stencil_offset; /**< Offset into bo. */
- uint32_t stencil_stride; /**< 3DSTATE_STENCIL_BUFFER.SurfacePitch */
- uint16_t stencil_qpitch; /**< 3DSTATE_STENCIL_BUFFER.SurfaceQPitch */
+ /** RENDER_SURFACE_STATE when using image as a non render target. */
+ struct anv_state nonrt_surface_state;
};
struct anv_image_create_info {
const struct anv_image_create_info *info,
VkImage *pImage);
+struct anv_surface *
+anv_image_get_surface_for_aspect_mask(struct anv_image *image,
+ VkImageAspectFlags aspect_mask);
+
void anv_image_view_init(struct anv_image_view *view,
struct anv_device *device,
const VkImageViewCreateInfo* pCreateInfo,
const VkImageViewCreateInfo* pCreateInfo,
struct anv_cmd_buffer *cmd_buffer);
-void anv_color_attachment_view_init(struct anv_color_attachment_view *view,
- struct anv_device *device,
- const VkAttachmentViewCreateInfo* pCreateInfo,
- struct anv_cmd_buffer *cmd_buffer);
-
-void gen7_color_attachment_view_init(struct anv_color_attachment_view *aview,
- struct anv_device *device,
- const VkAttachmentViewCreateInfo* pCreateInfo,
- struct anv_cmd_buffer *cmd_buffer);
-
-void gen8_color_attachment_view_init(struct anv_color_attachment_view *aview,
- struct anv_device *device,
- const VkAttachmentViewCreateInfo* pCreateInfo,
- struct anv_cmd_buffer *cmd_buffer);
-
-VkResult anv_buffer_view_create(struct anv_device *device,
- const VkBufferViewCreateInfo *pCreateInfo,
- struct anv_buffer_view **view_out);
-
void anv_fill_buffer_surface_state(struct anv_device *device, void *state,
const struct anv_format *format,
- uint32_t offset, uint32_t range);
+ uint32_t offset, uint32_t range,
+ uint32_t stride);
void gen7_fill_buffer_surface_state(void *state, const struct anv_format *format,
- uint32_t offset, uint32_t range);
+ uint32_t offset, uint32_t range,
+ uint32_t stride);
void gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
- uint32_t offset, uint32_t range);
-
-void anv_surface_view_fini(struct anv_device *device,
- struct anv_surface_view *view);
+ uint32_t offset, uint32_t range,
+ uint32_t stride);
struct anv_sampler {
uint32_t state[4];
uint32_t height;
uint32_t layers;
- /* Viewport for clears */
- VkDynamicViewportState vp_state;
-
uint32_t attachment_count;
- const struct anv_attachment_view * attachments[0];
+ const struct anv_image_view * attachments[0];
};
struct anv_subpass {
struct anv_render_pass {
uint32_t attachment_count;
uint32_t subpass_count;
-
- uint32_t num_color_clear_attachments;
- bool has_depth_clear_attachment;
- bool has_stencil_clear_attachment;
-
struct anv_render_pass_attachment * attachments;
struct anv_subpass subpasses[0];
};
+extern struct anv_render_pass anv_meta_dummy_renderpass;
+
struct anv_query_pool_slot {
uint64_t begin;
uint64_t end;
void *anv_lookup_entrypoint(const char *name);
+void anv_dump_image_to_ppm(struct anv_device *device,
+ struct anv_image *image, unsigned miplevel,
+ unsigned array_layer, const char *filename);
+
#define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
\
static inline struct __anv_type * \
ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
-ANV_DEFINE_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI);
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCmdPool)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView);
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_cb_state, VkDynamicColorBlendState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_ds_state, VkDynamicDepthStencilState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_rs_state, VkDynamicRasterState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_vp_state, VkDynamicViewportState)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)