#ifndef GPU_COMPRESS_H
#define GPU_COMPRESS_H

#include "gpu_context.h"
#include "vkz_format.h"

// ── GPU Compression Pipeline ───────────────────────────────────────
typedef struct {
  GpuContext *ctx;

  // Pipeline
  VkPipelineLayout pipeline_layout;
  VkPipeline pipeline;
  VkDescriptorSetLayout desc_layout;
  VkDescriptorPool desc_pool;
  VkDescriptorSet desc_set;

  // GPU Buffers
  VkBuffer input_buffer;
  VkDeviceMemory input_memory;
  VkBuffer output_buffer;
  VkDeviceMemory output_memory;
  VkBuffer meta_buffer;
  VkDeviceMemory meta_memory;

  // Sizes
  VkDeviceSize input_size;
  VkDeviceSize output_size;
  VkDeviceSize meta_size;
} GpuCompressPipeline;

// Push constants matching shader layout
typedef struct {
  uint32_t block_count;
  uint32_t block_size;
  uint32_t max_match_len;
  uint32_t window_size;
} CompressPushConstants;

// Block metadata matching shader layout (uvec4)
typedef struct {
  uint32_t input_offset;
  uint32_t input_size;
  uint32_t output_offset;
  uint32_t output_size; // Written by shader
} BlockMeta;

// ── Functions ──────────────────────────────────────────────────────

// Initialize compression pipeline
int gpu_compress_init(GpuCompressPipeline *pipe, GpuContext *ctx);

// Compress data using GPU
// Returns array of compressed block buffers (caller must free each + array)
int gpu_compress_data(GpuCompressPipeline *pipe, const uint8_t *input_data,
                      uint64_t input_size, uint32_t block_size,
                      uint8_t ***out_blocks, uint32_t **out_block_sizes,
                      uint32_t *out_block_count);

// Cleanup compression pipeline
void gpu_compress_cleanup(GpuCompressPipeline *pipe);

#endif // GPU_COMPRESS_H
