Commit ab68601c authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Resolve many merge conflicts

parents 7b8e1d8a 6f9a6e4b
/*
* Copyright (C) 2018 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "compiler/glsl/glsl_to_nir.h"
#include "compiler/nir_types.h"
#include "main/imports.h"
#include "compiler/nir/nir_builder.h"
#include "util/half_float.h"
#include "util/register_allocate.h"
#include "util/u_dynarray.h"
#include "util/list.h"
#include "main/mtypes.h"
#include "bifrost_compile.h"
int
bifrost_compile_shader_nir(nir_shader *nir, bifrost_program *program) {
nir_print_shader(nir, stdout);
return 0;
}
/*
* Copyright (C) 2018 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "compiler/nir/nir.h"
typedef struct {
} bifrost_program;
int
bifrost_compile_shader_nir(nir_shader *nir, bifrost_program *program);
static const nir_shader_compiler_options bifrost_nir_options = {
.lower_ffma = true,
.lower_sub = true,
.lower_fpow = true,
.lower_scmp = true,
.lower_flrp32 = true,
.lower_flrp64 = true,
.lower_ffract = true,
.lower_fmod32 = true,
.lower_fmod64 = true,
.lower_fdiv = true,
.lower_idiv = true,
.vertex_id_zero_based = true,
.lower_extract_byte = true,
.lower_extract_word = true,
.native_integers = true
};
/*
* Copyright (C) 2018 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "compiler/glsl/standalone.h"
#include "compiler/glsl/glsl_to_nir.h"
#include "compiler/nir_types.h"
#include "bifrost_compile.h"
#include "disassemble.h"
#include "util/u_dynarray.h"
#include "main/mtypes.h"
static void
compile_shader(char **argv)
{
struct gl_shader_program *prog;
nir_shader *nir;
struct standalone_options options = {
.glsl_version = 140,
.do_link = true,
};
prog = standalone_compile_shader(&options, 2, argv);
prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->info.stage = MESA_SHADER_FRAGMENT;
bifrost_program compiled;
nir = glsl_to_nir(prog, MESA_SHADER_VERTEX, &bifrost_nir_options);
bifrost_compile_shader_nir(nir, &compiled);
nir = glsl_to_nir(prog, MESA_SHADER_FRAGMENT, &bifrost_nir_options);
bifrost_compile_shader_nir(nir, &compiled);
}
int
main(int argc, char **argv)
{
if (argc < 2) {
printf("Pass a command\n");
exit(1);
}
if (strcmp(argv[1], "compile") == 0) {
compile_shader(&argv[2]);
}
return 0;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (C) 2018 Connor Abbott <cwabbott0@gmail.com>
* Copyright (C) 2018 Lyude Paul <thatslyude@gmail.com>
* Copyright (C) 2018 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stddef.h>
void disassemble_bifrost(uint8_t *code, size_t size);
......@@ -28,6 +28,9 @@ files_panfrost = files(
'midgard/cppwrap.cpp',
'midgard/disassemble.c',
'bifrost/bifrost_compile.c',
'bifrost/disassemble.c',
'pan_context.c',
'pan_nondrm.c',
......@@ -47,6 +50,7 @@ inc_panfrost = [
inc_include,
inc_src,
include_directories('midgard'),
include_directories('bifrost'),
include_directories('include')
]
......@@ -87,6 +91,12 @@ files_midgard = files(
'midgard/cmdline.c',
)
files_bifrost = files(
'bifrost/bifrost_compile.c',
'bifrost/disassemble.c',
'bifrost/cmdline.c',
)
midgard_compiler = executable(
'midgard_compiler',
[files_midgard, midgard_nir_algebraic_c],
......@@ -103,5 +113,28 @@ midgard_compiler = executable(
build_by_default : true
)
bifrost_compiler = executable(
'bifrost_compiler',
[files_bifrost],
include_directories : [
inc_common,
inc_src,
inc_include,
inc_gallium,
inc_gallium_aux,
include_directories('bifrost')
],
dependencies : [
dep_thread,
idep_nir
],
link_with : [
libgallium,
libglsl_standalone,
libmesa_util
],
build_by_default : true
)
subdir('include')
subdir('panwrap')
......@@ -28,11 +28,71 @@
#include <assert.h>
#include <panfrost-misc.h>
#include <panfrost-job.h>
#include "pan_context.h"
#include "pan_nondrm.h"
/* TODO: What does this actually have to be? */
#define ALIGNMENT 128
/* Transient command stream pooling: command stream uploads try to simply copy
* into whereever we left off. If there isn't space, we allocate a new entry
* into the pool and copy there */
struct panfrost_transfer
panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz)
{
/* Pad the size */
sz = ALIGN(sz, ALIGNMENT);
/* Check if there is room in the current entry */
struct panfrost_transient_pool *pool = &ctx->transient_pools[ctx->cmdstream_i];
if ((pool->entry_offset + sz) > pool->entry_size) {
/* Don't overflow this entry -- advance to the next */
pool->entry_offset = 0;
pool->entry_index++;
assert(pool->entry_index < PANFROST_MAX_TRANSIENT_ENTRIES);
/* Check if this entry exists */
if (pool->entry_index >= pool->entry_count) {
/* Don't overflow the pool -- allocate a new one */
struct pb_slab_entry *entry = pb_slab_alloc(&ctx->slabs, pool->entry_size, HEAP_TRANSIENT);
pool->entry_count++;
pool->entries[pool->entry_index] = (struct panfrost_memory_entry *) entry;
}
/* Make sure we -still- won't overflow */
assert(sz < pool->entry_size);
}
/* We have an entry we can write to, so do the upload! */
struct panfrost_memory_entry *p_entry = pool->entries[pool->entry_index];
struct panfrost_memory *backing = (struct panfrost_memory *) p_entry->base.slab;
struct panfrost_transfer ret = {
.cpu = backing->cpu + p_entry->offset + pool->entry_offset,
.gpu = backing->gpu + p_entry->offset + pool->entry_offset
};
/* Advance the pointer */
pool->entry_offset += sz;
return ret;
}
mali_ptr
panfrost_upload_transient(struct panfrost_context *ctx, const void *data, size_t sz)
{
struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sz);
memcpy(transfer.cpu, data, sz);
return transfer.gpu;
}
// TODO: An actual allocator, perhaps
// TODO: Multiple stacks for multiple bases?
......
This diff is collapsed.
......@@ -75,20 +75,38 @@ struct panfrost_constant_buffer {
void *buffer;
};
#define PANFROST_MAX_TRANSIENT_ENTRIES 64
struct panfrost_transient_pool {
/* Memory blocks in the pool */
struct panfrost_memory_entry *entries[PANFROST_MAX_TRANSIENT_ENTRIES];
/* Number of entries we own */
unsigned entry_count;
/* Current entry that we are writing to, zero-indexed, strictly less than entry_count */
unsigned entry_index;
/* Number of bytes into the current entry we are */
off_t entry_offset;
/* Entry size (all entries must be homogenous) */
size_t entry_size;
};
struct panfrost_context {
/* Gallium context */
struct pipe_context base;
struct pipe_framebuffer_state pipe_framebuffer;
/* The number of concurrent FBOs allowed depends on the number of rings used */
struct panfrost_memory cmdstream_rings[2];
int cmdstream_i;
/* The number of concurrent FBOs allowed depends on the number of pools
* used; pools are ringed for parallelism opportunities */
struct panfrost_memory cmdstream;
struct panfrost_transient_pool transient_pools[2];
int cmdstream_i;
struct panfrost_memory cmdstream_persistent;
struct panfrost_memory textures;
struct panfrost_memory shaders;
struct panfrost_memory scratchpad;
struct panfrost_memory tiler_heap;
......@@ -139,6 +157,10 @@ struct panfrost_context {
mali_ptr vertex_jobs[MAX_DRAW_CALLS];
mali_ptr tiler_jobs[MAX_DRAW_CALLS];
struct mali_job_descriptor_header *u_set_value_job;
struct mali_job_descriptor_header *u_vertex_jobs[MAX_DRAW_CALLS];
struct mali_job_descriptor_header *u_tiler_jobs[MAX_DRAW_CALLS];
unsigned vertex_job_count;
unsigned tiler_job_count;
......@@ -188,6 +210,9 @@ struct panfrost_context {
struct pipe_blend_color blend_color;
struct pipe_depth_stencil_alpha_state *depth_stencil;
struct pipe_stencil_ref stencil_ref;
/* Memory management is based on subdividing slabs with AMD's allocator */
struct pb_slabs slabs;
};
/* Corresponds to the CSO */
......@@ -309,6 +334,9 @@ struct panfrost_resource {
mali_ptr gpu[MAX_MIP_LEVELS];
/* Memory entry corresponding to gpu above */
struct panfrost_memory_entry *entry[MAX_MIP_LEVELS];
/* Is something other than level 0 ever written? */
bool is_mipmap;
......@@ -361,9 +389,7 @@ panfrost_resource_create_front(struct pipe_screen *screen,
void
panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data);
mali_ptr
struct panfrost_transfer
panfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler, bool is_elided_tiler);
#define JOB_DESC(ptr) ((struct mali_job_descriptor_header *) (uintptr_t) (ptr - mem.gpu + (uintptr_t) mem.cpu))
#endif
......@@ -30,6 +30,7 @@
#include <stdbool.h>
#include <panfrost-job.h>
#include <linux/ioctl.h>
#include "pipebuffer/pb_slab.h"
int pandev_open(int fd);
......@@ -49,13 +50,54 @@ struct panfrost_shader_state;
void
panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *meta, const char *src, int type, struct panfrost_shader_state *state);
/* Texture memory */
#define HEAP_TEXTURE 0
/* Single-frame (transient) command stream memory, done at the block scale
* rather than the individual cmdstream alllocation scale. We use pb_alloc for
* pooling, but we have to implement our own logic atop the API for performance
* reasons when considering many low-latency tiny heterogenous allocations */
#define HEAP_TRANSIENT 1
/* Represents a fat pointer for GPU-mapped memory, returned from the transient
* allocator and not used for much else */
struct panfrost_transfer {
uint8_t *cpu;
mali_ptr gpu;
};
struct panfrost_memory {
/* Subclassing slab object */
struct pb_slab slab;
/* Backing for the slab in memory */
uint8_t *cpu;
mali_ptr gpu;
int stack_bottom;
size_t size;
};
/* Slab entry sizes range from 2^min to 2^max. In this case, we range from 1k
* to 16MB. Numbers are kind of arbitrary but these seem to work alright in
* practice. */
#define MIN_SLAB_ENTRY_SIZE (10)
#define MAX_SLAB_ENTRY_SIZE (24)
struct panfrost_memory_entry {
/* Subclass */
struct pb_slab_entry base;
/* Have we been freed? */
bool freed;
/* Offset into the slab of the entry */
off_t offset;
};
/* Functions for replay */
mali_ptr pandev_upload(int cheating_offset, int *stack_bottom, mali_ptr base, void *base_map, const void *data, size_t sz, bool no_pad);
mali_ptr pandev_upload_sequential(mali_ptr base, void *base_map, const void *data, size_t sz);
......@@ -64,6 +106,12 @@ mali_ptr pandev_upload_sequential(mali_ptr base, void *base_map, const void *dat
mali_ptr panfrost_upload(struct panfrost_memory *mem, const void *data, size_t sz, bool no_pad);
mali_ptr panfrost_upload_sequential(struct panfrost_memory *mem, const void *data, size_t sz);
struct panfrost_transfer
panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz);
mali_ptr
panfrost_upload_transient(struct panfrost_context *ctx, const void *data, size_t sz);
void *
panfrost_allocate_transfer(struct panfrost_memory *mem, size_t sz, mali_ptr *gpu);
......
......@@ -209,7 +209,7 @@ panfrost_draw_wallpaper(struct pipe_context *pipe)
2048.0, 1280.0, 0.0, 1.0,
};
ctx->payload_tiler.postfix.position_varying = panfrost_upload(&ctx->cmdstream, implied_position_varying, sizeof(implied_position_varying), true);
ctx->payload_tiler.postfix.position_varying = panfrost_upload_transient(ctx, implied_position_varying, sizeof(implied_position_varying));
/* Similarly, setup the texture coordinate varying, hardcoded to match
* the corners of the screen */
......@@ -223,13 +223,13 @@ panfrost_draw_wallpaper(struct pipe_context *pipe)
struct mali_attr varyings[1] = {
{
.elements = panfrost_upload(&ctx->cmdstream, texture_coordinates, sizeof(texture_coordinates), true) | 1,
.elements = panfrost_upload_transient(ctx, texture_coordinates, sizeof(texture_coordinates)) | 1,
.stride = sizeof(float) * 4,
.size = sizeof(texture_coordinates)
}
};
ctx->payload_tiler.postfix.varyings = panfrost_upload(&ctx->cmdstream, varyings, sizeof(varyings), true);
ctx->payload_tiler.postfix.varyings = panfrost_upload_transient(ctx, varyings, sizeof(varyings));
struct mali_attr_meta varying_meta[1] = {
{
......@@ -242,11 +242,13 @@ panfrost_draw_wallpaper(struct pipe_context *pipe)
};
mali_ptr saved_varying_meta = ctx->payload_tiler.postfix.varying_meta;
ctx->payload_tiler.postfix.varying_meta = panfrost_upload(&ctx->cmdstream, varying_meta, sizeof(varying_meta), true);
ctx->payload_tiler.postfix.varying_meta = panfrost_upload_transient(ctx, varying_meta, sizeof(varying_meta));
/* Emit the tiler job */
mali_ptr tiler_job = panfrost_vertex_tiler_job(ctx, true, true);
ctx->tiler_jobs[ctx->tiler_job_count++] = tiler_job;
struct panfrost_transfer tiler = panfrost_vertex_tiler_job(ctx, true, true);
struct mali_job_descriptor_header *jd = (struct mali_job_descriptor_header *) tiler.cpu;
ctx->u_tiler_jobs[ctx->tiler_job_count] = jd;
ctx->tiler_jobs[ctx->tiler_job_count++] = tiler.gpu;
ctx->draw_count++;
/* Okay, so we have the tiler job emitted. Since we set elided_tiler
......@@ -258,8 +260,7 @@ panfrost_draw_wallpaper(struct pipe_context *pipe)
*/
if (ctx->tiler_job_count > 1) {
struct panfrost_memory mem = ctx->cmdstream;
JOB_DESC(ctx->tiler_jobs[0])->job_dependency_index_2 = JOB_DESC(tiler_job)->job_index;
ctx->u_tiler_jobs[0]->job_dependency_index_2 = jd->job_index;
}
printf("Wallpaper boop\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment