pvr, pco: Add new compiler framework and shader gen stubs

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32258>
This commit is contained in:
Simon Perretta 2024-04-05 19:43:33 +01:00 committed by Marge Bot
parent ab1298e926
commit e90c851b8c
26 changed files with 449 additions and 28 deletions

View file

@ -1,12 +1,14 @@
# Copyright © 2024 Imagination Technologies Ltd.
# SPDX-License-Identifier: MIT
inc_powervr_compiler = include_directories([
'.',
])
inc_powervr_compiler = include_directories(['.'])
libpowervr_compiler_files = files(
'pco.c',
'pco_binary.c',
'pco_ir.c',
'pco_nir.c',
'pco_trans_nir.c',
)
libpowervr_compiler = static_library(

View file

@ -9,3 +9,50 @@
*
* \brief Main compiler interface.
*/
#include "pco.h"
#include "pco_internal.h"
#include "util/macros.h"
#include "util/ralloc.h"
/**
* \brief Allocates and sets up a PCO compiler context.
*
* \param[in] dev_info Device info.
* \param[in] mem_ctx Ralloc memory allocation context.
* \return The PCO compiler context, or NULL on failure.
*/
pco_ctx *pco_ctx_create(const struct pvr_device_info *dev_info, void *mem_ctx)
{
pco_ctx *ctx = rzalloc_size(mem_ctx, sizeof(*ctx));
ctx->dev_info = dev_info;
return ctx;
}
/**
* \brief Returns the device/core-specific SPIR-V to NIR options for a PCO
* compiler context.
*
* \param[in] ctx PCO compiler context.
* \return The device/core-specific SPIR-V to NIR options.
*/
const struct spirv_to_nir_options *pco_spirv_options(pco_ctx *ctx)
{
unreachable("finishme: pco_spirv_options");
return &ctx->spirv_options;
}
/**
* \brief Returns the device/core-specific NIR options for a PCO compiler
* context.
*
* \param[in] ctx PCO compiler context.
* \return The device/core-specific NIR options.
*/
const nir_shader_compiler_options *pco_nir_options(pco_ctx *ctx)
{
unreachable("finishme: pco_nir_options");
return &ctx->nir_options;
}

45
src/imagination/pco/pco.h Normal file
View file

@ -0,0 +1,45 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
#ifndef PCO_H
#define PCO_H
/**
* \file pco.h
*
* \brief Main compiler interface header.
*/
#include "compiler/nir/nir.h"
/* Defines. */
#define PCO_REG_UNUSED (~0U)
/* Driver-specific forward-declarations. */
struct pvr_device_info;
/* Compiler-specific forward-declarations. */
typedef struct _pco_shader pco_shader;
typedef struct _pco_ctx pco_ctx;
pco_ctx *pco_ctx_create(const struct pvr_device_info *dev_info, void *mem_ctx);
const struct spirv_to_nir_options *pco_spirv_options(pco_ctx *ctx);
const nir_shader_compiler_options *pco_nir_options(pco_ctx *ctx);
void pco_preprocess_nir(pco_ctx *ctx, nir_shader *nir);
void pco_link_nir(pco_ctx *ctx, nir_shader *producer, nir_shader *consumer);
void pco_lower_nir(pco_ctx *ctx, nir_shader *nir);
void pco_postprocess_nir(pco_ctx *ctx, nir_shader *nir);
pco_shader *pco_trans_nir(pco_ctx *ctx, nir_shader *nir, void *mem_ctx);
void pco_process_ir(pco_ctx *ctx, pco_shader *shader);
void pco_encode_ir(pco_ctx *ctx, pco_shader *shader);
void pco_shader_finalize(pco_ctx *ctx, pco_shader *shader);
unsigned pco_shader_binary_size(pco_shader *shader);
const void *pco_shader_binary_data(pco_shader *shader);
#endif /* PCO_H */

View file

@ -0,0 +1,62 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pco_binary.c
*
* \brief PCO binary-specific functions.
*/
#include "pco.h"
#include "pco_internal.h"
#include <stdio.h>
/**
* \brief Encodes a PCO shader into binary.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] shader PCO shader.
*/
void pco_encode_ir(pco_ctx *ctx, pco_shader *shader)
{
puts("finishme: pco_encode_ir");
}
/**
* \brief Finalizes a PCO shader binary.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] shader PCO shader.
*/
void pco_shader_finalize(pco_ctx *ctx, pco_shader *shader)
{
puts("finishme: pco_shader_finalize");
}
/**
* \brief Returns the size in bytes of a PCO shader binary.
*
* \param[in] shader PCO shader.
* \return The size in bytes of the PCO shader binary.
*/
unsigned pco_shader_binary_size(pco_shader *shader)
{
puts("finishme: pco_binary_size");
return 0;
}
/**
* \brief Returns the PCO shader binary data.
*
* \param[in] shader PCO shader.
* \return The PCO shader binary data.
*/
const void *pco_shader_binary_data(pco_shader *shader)
{
puts("finishme: pco_binary_data");
return NULL;
}

View file

@ -0,0 +1,31 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
#ifndef PCO_INTERNAL_H
#define PCO_INTERNAL_H
/**
* \file pco_internal.h
*
* \brief PCO internal header.
*/
#include "pco.h"
#include "spirv/nir_spirv.h"
/** PCO compiler context. */
typedef struct _pco_ctx {
/** Device information. */
const struct pvr_device_info *dev_info;
/** Device-specific NIR options. */
nir_shader_compiler_options nir_options;
/** Device-specific SPIR-V to NIR options. */
struct spirv_to_nir_options spirv_options;
} pco_ctx;
#endif /* PCO_INTERNAL_H */

View file

@ -0,0 +1,27 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pco_ir.c
*
* \brief PCO IR-specific functions.
*/
#include "pco.h"
#include "pco_internal.h"
#include <stdio.h>
/**
* \brief Runs passes on a PCO shader.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] shader PCO shader.
*/
void pco_process_ir(pco_ctx *ctx, pco_shader *shader)
{
puts("finishme: pco_process_ir");
}

View file

@ -0,0 +1,61 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pco_nir.c
*
* \brief NIR-specific functions.
*/
#include "pco.h"
#include "pco_internal.h"
#include <stdio.h>
/**
* \brief Runs pre-processing passes on a NIR shader.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] nir NIR shader.
*/
void pco_preprocess_nir(pco_ctx *ctx, nir_shader *nir)
{
puts("finishme: pco_preprocess_nir");
}
/**
* \brief Lowers a NIR shader.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] nir NIR shader.
*/
void pco_lower_nir(pco_ctx *ctx, nir_shader *nir)
{
puts("finishme: pco_lower_nir");
}
/**
* \brief Runs post-processing passes on a NIR shader.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] nir NIR shader.
*/
void pco_postprocess_nir(pco_ctx *ctx, nir_shader *nir)
{
puts("finishme: pco_postprocess_nir");
}
/**
* \brief Performs linking optimizations on consecutive NIR shader stages.
*
* \param[in] ctx PCO compiler context.
* \param[in,out] producer NIR producer shader.
* \param[in,out] consumer NIR consumer shader.
*/
void pco_link_nir(pco_ctx *ctx, nir_shader *producer, nir_shader *consumer)
{
puts("finishme: pco_link_nir");
}

View file

@ -0,0 +1,30 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pco_trans_nir.c
*
* \brief NIR translation functions.
*/
#include "pco.h"
#include "pco_internal.h"
#include <stdio.h>
/**
* \brief Translates a NIR shader into a PCO shader.
*
* \param[in] ctx PCO compiler context.
* \param[in] nir NIR shader.
* \param[in] mem_ctx Ralloc memory allocation context.
* \return The PCO shader.
*/
pco_shader *pco_trans_nir(pco_ctx *ctx, nir_shader *nir, void *mem_ctx)
{
puts("finishme: pco_trans_nir");
return ralloc_context(mem_ctx);
}

View file

@ -60,8 +60,6 @@ pvr_files = files(
)
pvr_includes = [
include_directories('usc/programs'),
include_directories('usc'),
include_directories('winsys'),
libpowervr_pds_includes,
]

View file

@ -33,8 +33,8 @@
#include "pvr_formats.h"
#include "pvr_job_transfer.h"
#include "pvr_private.h"
#include "pvr_shader_factory.h"
#include "pvr_static_shaders.h"
#include "usc/programs/pvr_shader_factory.h"
#include "usc/programs/pvr_static_shaders.h"
#include "pvr_types.h"
#include "util/bitscan.h"
#include "util/list.h"

View file

@ -29,8 +29,8 @@
#include "pvr_hardcode.h"
#include "pvr_pds.h"
#include "pvr_private.h"
#include "pvr_shader_factory.h"
#include "pvr_static_shaders.h"
#include "usc/programs/pvr_shader_factory.h"
#include "usc/programs/pvr_static_shaders.h"
#include "pvr_types.h"
#include "vk_alloc.h"
#include "vk_log.h"

View file

@ -48,7 +48,7 @@
#include "pvr_private.h"
#include "pvr_tex_state.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "pvr_winsys.h"
#include "util/bitscan.h"
#include "util/bitset.h"

View file

@ -57,7 +57,7 @@
#include "pvr_robustness.h"
#include "pvr_tex_state.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "pvr_util.h"
#include "pvr_winsys.h"
#include "rogue/rogue.h"

View file

@ -30,7 +30,7 @@
#include "hwdef/rogue_hw_utils.h"
#include "pvr_bo.h"
#include "pvr_cdm_load_sr.h"
#include "usc/programs/pvr_cdm_load_sr.h"
#include "pvr_common.h"
#include "pvr_csb.h"
#include "pvr_job_context.h"
@ -38,9 +38,9 @@
#include "pvr_private.h"
#include "pvr_transfer_frag_store.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "pvr_vdm_load_sr.h"
#include "pvr_vdm_store_sr.h"
#include "usc/pvr_uscgen.h"
#include "usc/programs/pvr_vdm_load_sr.h"
#include "usc/programs/pvr_vdm_store_sr.h"
#include "pvr_winsys.h"
#include "util/macros.h"
#include "util/os_file.h"

View file

@ -28,7 +28,7 @@
#include "pvr_private.h"
#include "pvr_transfer_frag_store.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "pvr_winsys.h"
/* Support PDS code/data loading/storing to the 'B' shared register state

View file

@ -38,7 +38,7 @@
#include "pvr_tex_state.h"
#include "pvr_transfer_frag_store.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "pvr_util.h"
#include "pvr_winsys.h"
#include "util/bitscan.h"

View file

@ -32,7 +32,7 @@
#include "pvr_pds.h"
#include "pvr_private.h"
#include "pvr_types.h"
#include "pvr_usc_fragment_shader.h"
#include "usc/programs/pvr_usc_fragment_shader.h"
#include "util/macros.h"
#include "rogue/rogue.h"
#include "vk_alloc.h"

View file

@ -48,7 +48,7 @@
#include "pvr_job_render.h"
#include "pvr_limits.h"
#include "pvr_pds.h"
#include "pvr_shader_factory.h"
#include "usc/programs/pvr_shader_factory.h"
#include "pvr_spm.h"
#include "pvr_types.h"
#include "pvr_winsys.h"

View file

@ -33,8 +33,8 @@
#include "pvr_formats.h"
#include "pvr_pds.h"
#include "pvr_private.h"
#include "pvr_shader_factory.h"
#include "pvr_static_shaders.h"
#include "usc/programs/pvr_shader_factory.h"
#include "usc/programs/pvr_static_shaders.h"
#include "pvr_tex_state.h"
#include "pvr_types.h"
#include "vk_alloc.h"

View file

@ -37,12 +37,12 @@
#include "pvr_job_common.h"
#include "pvr_pds.h"
#include "pvr_private.h"
#include "pvr_shader_factory.h"
#include "usc/programs/pvr_shader_factory.h"
#include "pvr_spm.h"
#include "pvr_static_shaders.h"
#include "usc/programs/pvr_static_shaders.h"
#include "pvr_tex_state.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "util/bitscan.h"
#include "util/macros.h"
#include "util/simple_mtx.h"

View file

@ -35,7 +35,7 @@
#include "pvr_private.h"
#include "pvr_transfer_frag_store.h"
#include "pvr_types.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "util/hash_table.h"
#include "util/macros.h"
#include "util/ralloc.h"

View file

@ -28,7 +28,7 @@
#include <vulkan/vulkan_core.h>
#include "pvr_device_info.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "pvr_types.h"
#include "util/hash_table.h"

View file

@ -0,0 +1,80 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pvr_uscgen.c
*
* \brief USC shader generation.
*/
#include "nir/nir.h"
#include "nir/nir_builder.h"
#include "pco/pco.h"
#include "pvr_uscgen.h"
#include "util/macros.h"
/**
* Common function to build a NIR shader and export the binary.
*
* \param ctx PCO context.
* \param nir NIR shader.
* \param binary Output shader binary.
*/
static void build_shader(pco_ctx *ctx, nir_shader *nir, pco_binary **binary)
{
pco_preprocess_nir(ctx, nir);
pco_lower_nir(ctx, nir);
pco_postprocess_nir(ctx, nir);
pco_shader *shader = pco_trans_nir(ctx, nir);
pco_process_ir(ctx, shader);
pco_binary *bin = pco_encode_ir(ctx, shader);
ralloc_free(shader);
pco_binary_finalize(ctx, bin);
*binary = bin;
}
/**
* Generate a nop (empty) shader.
*
* \param ctx PCO context.
* \param stage Shader stage.
* \param binary Output shader binary.
*/
void pvr_uscgen_nop(pco_ctx *ctx, gl_shader_stage stage, pco_binary **binary)
{
unreachable("finishme: pvr_uscgen_nop");
}
/**
* Generate an end-of-tile shader.
*
* \param ctx PCO context.
* \param props End of tile shader properties.
* \param binary Output shader binary.
*/
void pvr_uscgen_eot(pco_ctx *ctx,
struct pvr_eot_props *props,
pco_binary **binary)
{
unreachable("finishme: pvr_uscgen_eot");
}
/**
* Generate a transfer queue shader.
*
* \param ctx PCO context.
* \param props Transfer queue shader properties.
* \param binary Output shader binary.
*/
void pvr_uscgen_tq(pco_ctx *ctx,
struct pvr_tq_props *props,
pco_binary **binary)
{
unreachable("finishme: pvr_uscgen_tq");
}

View file

@ -0,0 +1,38 @@
/*
* Copyright © 2024 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
#ifndef PVR_USCGEN_H
#define PVR_USCGEN_H
/**
* \file pvr_uscgen.h
*
* \brief USC shader generation header.
*/
#include "compiler/shader_enums.h"
#include "pco/pco.h"
/* NOP shader generation. */
void pvr_uscgen_nop(pco_ctx *ctx, gl_shader_stage stage, pco_binary **binary);
/* EOT shader generation. */
struct pvr_eot_props {
};
void pvr_uscgen_eot(pco_ctx *ctx,
struct pvr_eot_props *props,
pco_binary **binary);
/* Transfer queue shader generation. */
struct pvr_tq_props {
};
void pvr_uscgen_tq(pco_ctx *ctx,
struct pvr_tq_props *props,
pco_binary **binary);
#endif /* PVR_USCGEN_H */

View file

@ -22,7 +22,7 @@
*/
#include "pvr_job_transfer.h"
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "rogue/rogue.h"
#include "rogue/rogue_builder.h"
#include "util/u_dynarray.h"

View file

@ -24,7 +24,7 @@
#include <assert.h>
#include <stdint.h>
#include "pvr_uscgen.h"
#include "usc/pvr_uscgen.h"
#include "rogue/rogue.h"
#include "rogue/rogue_builder.h"
#include "util/u_dynarray.h"