Get it to compile again
This commit is contained in:
		
							parent
							
								
									b0e6839a1c
								
							
						
					
					
						commit
						1b4a17f01a
					
				
							
								
								
									
										10
									
								
								meson.build
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								meson.build
									
									
									
									
									
								
							@ -7,7 +7,7 @@ project('rtengine', ['c', 'cpp'],
 | 
				
			|||||||
    'werror=true',
 | 
					    'werror=true',
 | 
				
			||||||
    'b_vscrt=static_from_buildtype',
 | 
					    'b_vscrt=static_from_buildtype',
 | 
				
			||||||
    'default_library=static',
 | 
					    'default_library=static',
 | 
				
			||||||
    'b_rtti=false',
 | 
					    'cpp_rtti=false',
 | 
				
			||||||
    'cpp_eh=none'])
 | 
					    'cpp_eh=none'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
compiler = meson.get_compiler('c')
 | 
					compiler = meson.get_compiler('c')
 | 
				
			||||||
@ -82,11 +82,11 @@ subdir('src')
 | 
				
			|||||||
engine_link_libs = []
 | 
					engine_link_libs = []
 | 
				
			||||||
if get_option('default_library') == 'static'
 | 
					if get_option('default_library') == 'static'
 | 
				
			||||||
  if get_option('static_renderer') == 'vk'
 | 
					  if get_option('static_renderer') == 'vk'
 | 
				
			||||||
    engine_link_libs = [runtime_lib, gfx_lib, app_lib, vk_renderer_lib]
 | 
					    engine_link_libs = [runtime_lib, app_lib, vk_renderer_lib]
 | 
				
			||||||
  elif get_option('static_renderer') == 'null'
 | 
					  elif get_option('static_renderer') == 'null'
 | 
				
			||||||
    engine_link_libs = [runtime_lib, gfx_lib, app_lib, null_renderer_lib]
 | 
					    engine_link_libs = [runtime_lib, app_lib, null_renderer_lib]
 | 
				
			||||||
  elif get_option('static_renderer') == 'dx11'
 | 
					  elif get_option('static_renderer') == 'dx11'
 | 
				
			||||||
    engine_link_libs = [runtime_lib, gfx_lib, app_lib, dx11_renderer_lib]
 | 
					    engine_link_libs = [runtime_lib, app_lib, dx11_renderer_lib]
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    error('Invalid static_renderer option ', get_option('static_renderer'))
 | 
					    error('Invalid static_renderer option ', get_option('static_renderer'))
 | 
				
			||||||
  endif
 | 
					  endif
 | 
				
			||||||
@ -95,7 +95,7 @@ else
 | 
				
			|||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Unit/Integration test driver
 | 
					# Unit/Integration test driver
 | 
				
			||||||
subdir('tests')
 | 
					# subdir('tests')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Declare dependencies, to enable using the engine as a subproject
 | 
					# Declare dependencies, to enable using the engine as a subproject
 | 
				
			||||||
engine_dep = declare_dependency(link_with : engine_link_libs,
 | 
					engine_dep = declare_dependency(link_with : engine_link_libs,
 | 
				
			||||||
 | 
				
			|||||||
@ -5,8 +5,7 @@
 | 
				
			|||||||
#include "runtime/buffer_manager.h"
 | 
					#include "runtime/buffer_manager.h"
 | 
				
			||||||
#include "runtime/config.h"
 | 
					#include "runtime/config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gfx/gfx.h"
 | 
					#include "renderer/common/renderer_api.h"
 | 
				
			||||||
#include "gfx/renderer_api.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -40,8 +39,6 @@ RT_DLLEXPORT int rtWin32Entry(HINSTANCE hInstance,
 | 
				
			|||||||
    rtRegisterCVAR(&rt_WindowWidth);
 | 
					    rtRegisterCVAR(&rt_WindowWidth);
 | 
				
			||||||
    rtRegisterCVAR(&rt_WindowHeight);
 | 
					    rtRegisterCVAR(&rt_WindowHeight);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rtRegisterRendererCVars();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (app_callbacks.RegisterCVars)
 | 
					    if (app_callbacks.RegisterCVars)
 | 
				
			||||||
        app_callbacks.RegisterCVars();
 | 
					        app_callbacks.RegisterCVars();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -100,8 +97,10 @@ RT_DLLEXPORT int rtWin32Entry(HINSTANCE hInstance,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rt_renderer_init_info renderer_info = {.hWnd = wnd, .hInstance = hInstance};
 | 
					    rt_renderer_init_info renderer_info = {.hWnd = wnd, .hInstance = hInstance};
 | 
				
			||||||
    if (rtInitGFX(&renderer_info) != RT_SUCCESS) {
 | 
					    if (rtLoadRenderer() != RT_SUCCESS) {
 | 
				
			||||||
        rtReportError("GFX", "Init failed.");
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (g_renderer.Init(&renderer_info) != RT_SUCCESS) {
 | 
				
			||||||
        return 1;
 | 
					        return 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -126,11 +125,8 @@ RT_DLLEXPORT int rtWin32Entry(HINSTANCE hInstance,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    app_callbacks.Shutdown();
 | 
					    app_callbacks.Shutdown();
 | 
				
			||||||
 | 
					 | 
				
			||||||
    rtShutdownMainLoop();
 | 
					    rtShutdownMainLoop();
 | 
				
			||||||
 | 
					    g_renderer.Shutdown();
 | 
				
			||||||
    rtShutdownGFX();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    DestroyWindow(wnd);
 | 
					    DestroyWindow(wnd);
 | 
				
			||||||
    UnregisterClassW(L"rtWndClass", hInstance);
 | 
					    UnregisterClassW(L"rtWndClass", hInstance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -183,8 +179,6 @@ RT_DLLEXPORT int rtXlibEntry(int argc, char **argv, rt_app_callbacks app_callbac
 | 
				
			|||||||
    if (rtInitRuntime() != RT_SUCCESS)
 | 
					    if (rtInitRuntime() != RT_SUCCESS)
 | 
				
			||||||
        return 1;
 | 
					        return 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rtRegisterRendererCVars();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (app_callbacks.RegisterCVars)
 | 
					    if (app_callbacks.RegisterCVars)
 | 
				
			||||||
        app_callbacks.RegisterCVars();
 | 
					        app_callbacks.RegisterCVars();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -257,7 +251,6 @@ RT_DLLEXPORT int rtXlibEntry(int argc, char **argv, rt_app_callbacks app_callbac
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    app_callbacks.Shutdown();
 | 
					    app_callbacks.Shutdown();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rtShutdownGFX();
 | 
					 | 
				
			||||||
    XDestroyWindow(dpy, window);
 | 
					    XDestroyWindow(dpy, window);
 | 
				
			||||||
    XCloseDisplay(dpy);
 | 
					    XCloseDisplay(dpy);
 | 
				
			||||||
    rtShutdownRuntime();
 | 
					    rtShutdownRuntime();
 | 
				
			||||||
 | 
				
			|||||||
@ -3,8 +3,6 @@
 | 
				
			|||||||
#include "runtime/runtime.h"
 | 
					#include "runtime/runtime.h"
 | 
				
			||||||
#include "runtime/config.h"
 | 
					#include "runtime/config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gfx/gfx.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RT_CVAR_I(rt_MaxFrameLatency, "Maximum latency between update and rendering. Default: 2", 1);
 | 
					RT_CVAR_I(rt_MaxFrameLatency, "Maximum latency between update and rendering. Default: 2", 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RT_DLLEXPORT rt_main_loop g_main_loop;
 | 
					RT_DLLEXPORT rt_main_loop g_main_loop;
 | 
				
			||||||
@ -39,9 +37,7 @@ void RenderThreadEntry(void *param) {
 | 
				
			|||||||
        rtWaitOnSemaphore(&g_main_loop.render_proceed);
 | 
					        rtWaitOnSemaphore(&g_main_loop.render_proceed);
 | 
				
			||||||
        //rtLog("RT", "Processing %u", g_main_loop.r_frame_id);
 | 
					        //rtLog("RT", "Processing %u", g_main_loop.r_frame_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        rtBeginGFXFrame(g_main_loop.r_frame_id);
 | 
					 | 
				
			||||||
        (g_main_loop.GameRender)(g_main_loop.r_frame_id);
 | 
					        (g_main_loop.GameRender)(g_main_loop.r_frame_id);
 | 
				
			||||||
        rtEndGFXFrame(g_main_loop.r_frame_id);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //rtLog("RT", "Finished   %u", g_main_loop.r_frame_id);
 | 
					        //rtLog("RT", "Finished   %u", g_main_loop.r_frame_id);
 | 
				
			||||||
        g_main_loop.r_frame_id += 1;
 | 
					        g_main_loop.r_frame_id += 1;
 | 
				
			||||||
 | 
				
			|||||||
@ -6,9 +6,11 @@ app_lib = library('rtapp',
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
  'app.c',
 | 
					  'app.c',
 | 
				
			||||||
  'main_loop.c',
 | 
					  'main_loop.c',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  '../renderer/common/load_stub.c',
 | 
				
			||||||
  dependencies : app_deps,
 | 
					  dependencies : app_deps,
 | 
				
			||||||
  include_directories : engine_incdir,
 | 
					  include_directories : engine_incdir,
 | 
				
			||||||
  link_with : [runtime_lib, gfx_lib],
 | 
					  link_with : [runtime_lib],
 | 
				
			||||||
  c_pch : 'pch/app_pch.h',
 | 
					  c_pch : 'pch/app_pch.h',
 | 
				
			||||||
  install : true)
 | 
					  install : true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,12 +4,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "runtime/buffer_manager.h"
 | 
					#include "runtime/buffer_manager.h"
 | 
				
			||||||
#include "runtime/config.h"
 | 
					#include "runtime/config.h"
 | 
				
			||||||
 | 
					#include "runtime/hashing.h"
 | 
				
			||||||
#include "runtime/mem_arena.h"
 | 
					#include "runtime/mem_arena.h"
 | 
				
			||||||
#include "runtime/runtime.h"
 | 
					#include "runtime/runtime.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gfx/effect.h"
 | 
					 | 
				
			||||||
#include "gfx/gfx.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <limits.h>
 | 
					#include <limits.h>
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
@ -43,8 +41,6 @@ enum {
 | 
				
			|||||||
    RT_SHADER_NOT_PRESENT = RT_ASSET_PROCESSING_FAILED + 1
 | 
					    RT_SHADER_NOT_PRESENT = RT_ASSET_PROCESSING_FAILED + 1
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern RT_DLLIMPORT rt_cvar rt_Renderer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static char *GenerateShaderName(rt_shader_type type,
 | 
					static char *GenerateShaderName(rt_shader_type type,
 | 
				
			||||||
                                rt_shader_stage stage,
 | 
					                                rt_shader_stage stage,
 | 
				
			||||||
                                rt_shader_optimization_level optimization,
 | 
					                                rt_shader_optimization_level optimization,
 | 
				
			||||||
@ -104,7 +100,6 @@ static rt_result ParseShader(rt_parse_state *state,
 | 
				
			|||||||
                             unsigned int root_list,
 | 
					                             unsigned int root_list,
 | 
				
			||||||
                             const char *name,
 | 
					                             const char *name,
 | 
				
			||||||
                             const char *file_path,
 | 
					                             const char *file_path,
 | 
				
			||||||
                             rt_shader_type type,
 | 
					 | 
				
			||||||
                             rt_shader_stage stage,
 | 
					                             rt_shader_stage stage,
 | 
				
			||||||
                             rt_shader_optimization_level optimization,
 | 
					                             rt_shader_optimization_level optimization,
 | 
				
			||||||
                             rt_resource *p_resource,
 | 
					                             rt_resource *p_resource,
 | 
				
			||||||
@ -135,11 +130,11 @@ static rt_result ParseShader(rt_parse_state *state,
 | 
				
			|||||||
                              file_path);
 | 
					                              file_path);
 | 
				
			||||||
                return RT_ASSET_PROCESSING_FAILED;
 | 
					                return RT_ASSET_PROCESSING_FAILED;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            rt_shader_type in_file_type = RT_SHADER_TYPE_INVALID;
 | 
					            rt_shader_type type = RT_SHADER_TYPE_INVALID;
 | 
				
			||||||
            if (rtCompareSpanToString(shader->attribute, "vk") == 0) {
 | 
					            if (rtCompareSpanToString(shader->attribute, "vk") == 0) {
 | 
				
			||||||
                in_file_type = RT_SHADER_TYPE_VULKAN;
 | 
					                type = RT_SHADER_TYPE_VULKAN;
 | 
				
			||||||
            } else if (rtCompareSpanToString(shader->attribute, "dx11") == 0) {
 | 
					            } else if (rtCompareSpanToString(shader->attribute, "dx11") == 0) {
 | 
				
			||||||
                in_file_type = RT_SHADER_TYPE_DX11;
 | 
					                type = RT_SHADER_TYPE_DX11;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                rtReportError("GFX",
 | 
					                rtReportError("GFX",
 | 
				
			||||||
                              "Invalid renderer backend"
 | 
					                              "Invalid renderer backend"
 | 
				
			||||||
@ -151,41 +146,43 @@ static rt_result ParseShader(rt_parse_state *state,
 | 
				
			|||||||
                return RT_ASSET_PROCESSING_FAILED;
 | 
					                return RT_ASSET_PROCESSING_FAILED;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (in_file_type == type) {
 | 
					            if (shader->form == RT_STMT_FORM_BLOCK) {
 | 
				
			||||||
                if (shader->form == RT_STMT_FORM_BLOCK) {
 | 
					                /* Inline code */
 | 
				
			||||||
                    /* Inline code */
 | 
					                rt_shader_bytecode bytecode =
 | 
				
			||||||
                    rt_shader_bytecode bytecode =
 | 
					                    CompileShader(type, stage, optimization, shader->block, file_path, arena);
 | 
				
			||||||
                        CompileShader(type, stage, optimization, shader->block, file_path, arena);
 | 
					                if (!bytecode.bytes)
 | 
				
			||||||
                    if (!bytecode.bytes)
 | 
					 | 
				
			||||||
                        return RT_ASSET_PROCESSING_FAILED;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    *p_resource_name =
 | 
					 | 
				
			||||||
                        GenerateShaderName(type, stage, optimization, file_path, arena);
 | 
					 | 
				
			||||||
                    if (!*p_resource_name)
 | 
					 | 
				
			||||||
                        return RT_ASSET_PROCESSING_FAILED;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    rt_resource resource;
 | 
					 | 
				
			||||||
                    resource.type              = RT_RESOURCE_SHADER;
 | 
					 | 
				
			||||||
                    resource.dependency_count  = 0;
 | 
					 | 
				
			||||||
                    resource.subresource_count = 0;
 | 
					 | 
				
			||||||
                    resource.data = rtArenaPush(arena, sizeof(rt_shader_info) + bytecode.len);
 | 
					 | 
				
			||||||
                    if (!resource.data)
 | 
					 | 
				
			||||||
                        return RT_ASSET_PROCESSING_FAILED;
 | 
					 | 
				
			||||||
                    rt_shader_info *shader_info  = resource.data;
 | 
					 | 
				
			||||||
                    uint8_t *shader_bytecode     = (uint8_t *)(shader_info + 1);
 | 
					 | 
				
			||||||
                    shader_info->stage           = stage;
 | 
					 | 
				
			||||||
                    shader_info->type            = type;
 | 
					 | 
				
			||||||
                    shader_info->bytecode_length = bytecode.len;
 | 
					 | 
				
			||||||
                    rtSetRelptr(&shader_info->bytecode, shader_bytecode);
 | 
					 | 
				
			||||||
                    memcpy(shader_bytecode, bytecode.bytes, bytecode.len);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    memcpy(p_resource, &resource, sizeof(resource));
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                } else if (shader->form != RT_STMT_FORM_VALUE) {
 | 
					 | 
				
			||||||
                    /* A filename */
 | 
					 | 
				
			||||||
                    rtLog("AC", "Shader source files not implemented yet!");
 | 
					 | 
				
			||||||
                    return RT_ASSET_PROCESSING_FAILED;
 | 
					                    return RT_ASSET_PROCESSING_FAILED;
 | 
				
			||||||
                }
 | 
					
 | 
				
			||||||
 | 
					                *p_resource_name = GenerateShaderName(type, stage, optimization, file_path, arena);
 | 
				
			||||||
 | 
					                if (!*p_resource_name)
 | 
				
			||||||
 | 
					                    return RT_ASSET_PROCESSING_FAILED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // TODO add the compiled code to a meta resource
 | 
				
			||||||
 | 
					                // that represents every version of that shader
 | 
				
			||||||
 | 
					                // I:e. -> API -> BLOB
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
 | 
					                rt_resource resource;
 | 
				
			||||||
 | 
					                resource.type              = RT_RESOURCE_SHADER;
 | 
				
			||||||
 | 
					                resource.dependency_count  = 0;
 | 
				
			||||||
 | 
					                resource.subresource_count = 0;
 | 
				
			||||||
 | 
					                resource.data = rtArenaPush(arena, sizeof(rt_shader_info) + bytecode.len);
 | 
				
			||||||
 | 
					                if (!resource.data)
 | 
				
			||||||
 | 
					                    return RT_ASSET_PROCESSING_FAILED;
 | 
				
			||||||
 | 
					                rt_shader_info *shader_info  = resource.data;
 | 
				
			||||||
 | 
					                uint8_t *shader_bytecode     = (uint8_t *)(shader_info + 1);
 | 
				
			||||||
 | 
					                shader_info->stage           = stage;
 | 
				
			||||||
 | 
					                shader_info->type            = type;
 | 
				
			||||||
 | 
					                shader_info->bytecode_length = bytecode.len;
 | 
				
			||||||
 | 
					                rtSetRelptr(&shader_info->bytecode, shader_bytecode);
 | 
				
			||||||
 | 
					                memcpy(shader_bytecode, bytecode.bytes, bytecode.len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                memcpy(p_resource, &resource, sizeof(resource));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            } else if (shader->form != RT_STMT_FORM_VALUE) {
 | 
				
			||||||
 | 
					                /* A filename */
 | 
				
			||||||
 | 
					                rtLog("AC", "Shader source files not implemented yet!");
 | 
				
			||||||
 | 
					                return RT_ASSET_PROCESSING_FAILED;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            stmt_index = shader->next;
 | 
					            stmt_index = shader->next;
 | 
				
			||||||
@ -232,24 +229,11 @@ static rt_result ParsePipeline(rt_parse_state *state,
 | 
				
			|||||||
                               rt_arena *arena) {
 | 
					                               rt_arena *arena) {
 | 
				
			||||||
    rt_result result = RT_SUCCESS;
 | 
					    rt_result result = RT_SUCCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rt_shader_type type = RT_SHADER_TYPE_INVALID;
 | 
					 | 
				
			||||||
    if (strcmp(rt_Renderer.s, "vk") == 0)
 | 
					 | 
				
			||||||
        type = RT_SHADER_TYPE_VULKAN;
 | 
					 | 
				
			||||||
    else if (strcmp(rt_Renderer.s, "dx11") == 0)
 | 
					 | 
				
			||||||
        type = RT_SHADER_TYPE_DX11;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (type == RT_SHADER_TYPE_INVALID) {
 | 
					 | 
				
			||||||
        result = RT_ASSET_PROCESSING_FAILED;
 | 
					 | 
				
			||||||
        rtLog("AC", "rt_Renderer (%s) could not be translated to a shader type.", rt_Renderer.s);
 | 
					 | 
				
			||||||
        goto out;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Process shader stages */
 | 
					    /* Process shader stages */
 | 
				
			||||||
    result = ParseShader(state,
 | 
					    result = ParseShader(state,
 | 
				
			||||||
                         root_list,
 | 
					                         root_list,
 | 
				
			||||||
                         "vertex",
 | 
					                         "vertex",
 | 
				
			||||||
                         file_path,
 | 
					                         file_path,
 | 
				
			||||||
                         type,
 | 
					 | 
				
			||||||
                         RT_SHADER_STAGE_VERTEX,
 | 
					                         RT_SHADER_STAGE_VERTEX,
 | 
				
			||||||
                         optimization,
 | 
					                         optimization,
 | 
				
			||||||
                         &pipeline->shaders[pipeline->shader_count],
 | 
					                         &pipeline->shaders[pipeline->shader_count],
 | 
				
			||||||
@ -269,7 +253,6 @@ static rt_result ParsePipeline(rt_parse_state *state,
 | 
				
			|||||||
                         root_list,
 | 
					                         root_list,
 | 
				
			||||||
                         "fragment",
 | 
					                         "fragment",
 | 
				
			||||||
                         file_path,
 | 
					                         file_path,
 | 
				
			||||||
                         type,
 | 
					 | 
				
			||||||
                         RT_SHADER_STAGE_FRAGMENT,
 | 
					                         RT_SHADER_STAGE_FRAGMENT,
 | 
				
			||||||
                         optimization,
 | 
					                         optimization,
 | 
				
			||||||
                         &pipeline->shaders[pipeline->shader_count],
 | 
					                         &pipeline->shaders[pipeline->shader_count],
 | 
				
			||||||
@ -289,7 +272,6 @@ static rt_result ParsePipeline(rt_parse_state *state,
 | 
				
			|||||||
                         root_list,
 | 
					                         root_list,
 | 
				
			||||||
                         "compute",
 | 
					                         "compute",
 | 
				
			||||||
                         file_path,
 | 
					                         file_path,
 | 
				
			||||||
                         type,
 | 
					 | 
				
			||||||
                         RT_SHADER_STAGE_COMPUTE,
 | 
					                         RT_SHADER_STAGE_COMPUTE,
 | 
				
			||||||
                         optimization,
 | 
					                         optimization,
 | 
				
			||||||
                         &pipeline->shaders[pipeline->shader_count],
 | 
					                         &pipeline->shaders[pipeline->shader_count],
 | 
				
			||||||
@ -358,7 +340,7 @@ static rt_result ParseEffect(rt_file_id fid,
 | 
				
			|||||||
            return RT_INVALID_VALUE;
 | 
					            return RT_INVALID_VALUE;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        effect->pass_ids[i] =
 | 
					        effect->pass_ids[i] =
 | 
				
			||||||
            rtCalculateRenderPassID(pass_stmt->attribute.start, pass_stmt->attribute.length);
 | 
					            rtHashBytes32(pass_stmt->attribute.start, pass_stmt->attribute.length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        result = ParsePipeline(&state,
 | 
					        result = ParsePipeline(&state,
 | 
				
			||||||
                               pass_stmt->list_index,
 | 
					                               pass_stmt->list_index,
 | 
				
			||||||
@ -384,6 +366,9 @@ RT_ASSET_PROCESSOR_FN(EffectProcessor) {
 | 
				
			|||||||
    if (result != RT_SUCCESS)
 | 
					    if (result != RT_SUCCESS)
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    *new_resource_count = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
    rt_effect_info effect_info;
 | 
					    rt_effect_info effect_info;
 | 
				
			||||||
    effect_info.pass_count = effect.pass_count;
 | 
					    effect_info.pass_count = effect.pass_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -392,8 +377,6 @@ RT_ASSET_PROCESSOR_FN(EffectProcessor) {
 | 
				
			|||||||
    effect_resource.type              = RT_RESOURCE_EFFECT;
 | 
					    effect_resource.type              = RT_RESOURCE_EFFECT;
 | 
				
			||||||
    effect_resource.subresource_count = effect.pass_count;
 | 
					    effect_resource.subresource_count = effect.pass_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *new_resource_count = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const char *name = rtGetFilePath(file);
 | 
					    const char *name = rtGetFilePath(file);
 | 
				
			||||||
    for (unsigned int i = 0; i < effect.pass_count; ++i) {
 | 
					    for (unsigned int i = 0; i < effect.pass_count; ++i) {
 | 
				
			||||||
        effect_info.passes[i].pass_id  = effect.pass_ids[i];
 | 
					        effect_info.passes[i].pass_id  = effect.pass_ids[i];
 | 
				
			||||||
@ -447,6 +430,7 @@ RT_ASSET_PROCESSOR_FN(EffectProcessor) {
 | 
				
			|||||||
            effect_resource.subresources[i] = pipeline_id;
 | 
					            effect_resource.subresources[i] = pipeline_id;
 | 
				
			||||||
            effect_info.passes[i].pipeline  = pipeline_id;
 | 
					            effect_info.passes[i].pipeline  = pipeline_id;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rt_resource_id effect_id = 0;
 | 
					    rt_resource_id effect_id = 0;
 | 
				
			||||||
@ -455,6 +439,7 @@ RT_ASSET_PROCESSOR_FN(EffectProcessor) {
 | 
				
			|||||||
        new_resources[*new_resource_count] = effect_id;
 | 
					        new_resources[*new_resource_count] = effect_id;
 | 
				
			||||||
        *new_resource_count += 1;
 | 
					        *new_resource_count += 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
out:
 | 
					out:
 | 
				
			||||||
    rtLog("AC", "Released %p", asset.buffer);
 | 
					    rtLog("AC", "Released %p", asset.buffer);
 | 
				
			||||||
    rtReleaseBuffer(asset.buffer, asset.size);
 | 
					    rtReleaseBuffer(asset.buffer, asset.size);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +1,15 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
#include "description_parser.h"
 | 
					#include "description_parser.h"
 | 
				
			||||||
#include "processor.h"
 | 
					#include "processor.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
#include "gfx/gfx.h"
 | 
					#include "gfx/gfx.h"
 | 
				
			||||||
#include "runtime/buffer_manager.h"
 | 
					#include "runtime/buffer_manager.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if 0
 | 
					 | 
				
			||||||
static int RenderTargetExists(const rt_framegraph_info *framegraph, rt_render_target_id id) {
 | 
					static int RenderTargetExists(const rt_framegraph_info *framegraph, rt_render_target_id id) {
 | 
				
			||||||
    const rt_render_target_info *render_targets = rtResolveConstRelptr(&framegraph->render_targets);
 | 
					    const rt_render_target_info *render_targets = rtResolveConstRelptr(&framegraph->render_targets);
 | 
				
			||||||
    for (uint32_t i = 0; i < framegraph->render_target_count; ++i) {
 | 
					    for (uint32_t i = 0; i < framegraph->render_target_count; ++i) {
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "runtime/runtime.h"
 | 
					#include "runtime/runtime.h"
 | 
				
			||||||
#include "runtime/mem_arena.h"
 | 
					#include "runtime/mem_arena.h"
 | 
				
			||||||
#include "gfx/renderer_api.h"
 | 
					#include "renderer/common/renderer_api.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
@ -15,6 +15,14 @@ typedef enum {
 | 
				
			|||||||
    RT_SHADER_OPTIMIZATION_SIZE,
 | 
					    RT_SHADER_OPTIMIZATION_SIZE,
 | 
				
			||||||
} rt_shader_optimization_level;
 | 
					} rt_shader_optimization_level;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    RT_SHADER_TYPE_INVALID,
 | 
				
			||||||
 | 
					    RT_SHADER_TYPE_VULKAN,
 | 
				
			||||||
 | 
					    RT_SHADER_TYPE_DX11,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    RT_SHADER_TYPE_count
 | 
				
			||||||
 | 
					} rt_shader_type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    void *bytes;
 | 
					    void *bytes;
 | 
				
			||||||
    size_t len;
 | 
					    size_t len;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										170
									
								
								src/game/main.c
									
									
									
									
									
								
							
							
						
						
									
										170
									
								
								src/game/main.c
									
									
									
									
									
								
							@ -3,66 +3,10 @@
 | 
				
			|||||||
#include "runtime/rt_math.h"
 | 
					#include "runtime/rt_math.h"
 | 
				
			||||||
#include "runtime/threading.h"
 | 
					#include "runtime/threading.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gfx/builtin_objects.h"
 | 
					 | 
				
			||||||
#include "gfx/effect.h"
 | 
					 | 
				
			||||||
#include "gfx/gfx.h"
 | 
					 | 
				
			||||||
#include "gfx/renderer_api.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "asset_compiler/asset_compiler.h"
 | 
					#include "asset_compiler/asset_compiler.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Matches the default vertex layout */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    rt_v3 pos;
 | 
					 | 
				
			||||||
    rt_v3 normal;
 | 
					 | 
				
			||||||
    rt_v3 tangent;
 | 
					 | 
				
			||||||
    rt_v2 texcoord;
 | 
					 | 
				
			||||||
} rt_vertex;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    const rt_effect *effect;
 | 
					 | 
				
			||||||
    rt_buffer_handle vbo;
 | 
					 | 
				
			||||||
    uint32_t vertex_count;
 | 
					 | 
				
			||||||
} rt_demo_renderable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static rt_demo_renderable *_renderables;
 | 
					 | 
				
			||||||
static unsigned int _renderable_count;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static rt_render_graph *_graph;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static rt_result ForwardPassExecute(uint32_t pass_id,
 | 
					 | 
				
			||||||
                                    rt_command_buffer_handle cmdbuf,
 | 
					 | 
				
			||||||
                                    const rt_render_view *views,
 | 
					 | 
				
			||||||
                                    uint32_t view_count,
 | 
					 | 
				
			||||||
                                    void *userdata) {
 | 
					 | 
				
			||||||
    RT_ASSERT(view_count == 1, "Expected a single view for the main camera.");
 | 
					 | 
				
			||||||
    rt_render_view view = *views;
 | 
					 | 
				
			||||||
    RT_VERIFY(rtDoViewTypesMatchExact(view, &g_builtin_render_object_types.render_mesh, 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rt_render_list meshes = view.lists[0];
 | 
					 | 
				
			||||||
    if (meshes.length == 0)
 | 
					 | 
				
			||||||
        return RT_SUCCESS;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rt_pipeline_handle bound_pipeline =
 | 
					 | 
				
			||||||
        (RT_GET_RENDER_LIST_ELEMENT(meshes, rt_render_mesh, 0)).pipeline;
 | 
					 | 
				
			||||||
    g_renderer.CmdBindPipeline(cmdbuf, bound_pipeline);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (size_t mesh_idx = 0; mesh_idx < meshes.length; ++mesh_idx) {
 | 
					 | 
				
			||||||
        rt_render_mesh mesh = RT_GET_RENDER_LIST_ELEMENT(meshes, rt_render_mesh, mesh_idx);
 | 
					 | 
				
			||||||
        if (RT_COMPARE_RENDER_HANDLES(bound_pipeline, mesh.pipeline, !=)) {
 | 
					 | 
				
			||||||
            bound_pipeline = mesh.pipeline;
 | 
					 | 
				
			||||||
            g_renderer.CmdBindPipeline(cmdbuf, bound_pipeline);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        uint32_t stride = sizeof(rt_vertex);
 | 
					 | 
				
			||||||
        g_renderer.CmdBindVertexBuffers(cmdbuf, 0, 1, &mesh.vbo, &stride, NULL);
 | 
					 | 
				
			||||||
        g_renderer.CmdDraw(cmdbuf, 0, mesh.vertex_count);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return RT_SUCCESS;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void RegisterCVars(void) {
 | 
					void RegisterCVars(void) {
 | 
				
			||||||
    rtRegisterAssetCompilerCVars();
 | 
					    rtRegisterAssetCompilerCVars();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -72,134 +16,20 @@ void Init(void) {
 | 
				
			|||||||
    rtInitAssetCompiler();
 | 
					    rtInitAssetCompiler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rtWaitForAssetProcessing();
 | 
					    rtWaitForAssetProcessing();
 | 
				
			||||||
 | 
					 | 
				
			||||||
    rtRegisterBuiltinRenderObjectTypes();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rt_render_graph_builder builder = g_renderer.CreateRenderGraphBuilder();
 | 
					 | 
				
			||||||
    rt_attachment_info backbuffer   = {
 | 
					 | 
				
			||||||
          .name    = "backbuffer",
 | 
					 | 
				
			||||||
          .format  = RT_PIXEL_FORMAT_SWAPCHAIN,
 | 
					 | 
				
			||||||
          .width   = RT_RENDER_TARGET_SIZE_SWAPCHAIN,
 | 
					 | 
				
			||||||
          .height  = RT_RENDER_TARGET_SIZE_SWAPCHAIN,
 | 
					 | 
				
			||||||
          .samples = 1,
 | 
					 | 
				
			||||||
          .layers  = 1,
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    builder.AddRenderTarget(builder.obj, &backbuffer);
 | 
					 | 
				
			||||||
    rt_attachment_info depth = {.name    = "depth",
 | 
					 | 
				
			||||||
                                .format  = RT_PIXEL_FORMAT_DEPTH24_STENCIL8,
 | 
					 | 
				
			||||||
                                .width   = RT_RENDER_TARGET_SIZE_SWAPCHAIN,
 | 
					 | 
				
			||||||
                                .height  = RT_RENDER_TARGET_SIZE_SWAPCHAIN,
 | 
					 | 
				
			||||||
                                .samples = 1,
 | 
					 | 
				
			||||||
                                .layers  = 1};
 | 
					 | 
				
			||||||
    builder.AddRenderTarget(builder.obj, &depth);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rt_pass_info forward = {.name  = "forward",
 | 
					 | 
				
			||||||
                            .flags = RT_PASS_FLAG_EXECUTE_ALWAYS | RT_PASS_FLAG_GRAPHICS};
 | 
					 | 
				
			||||||
    builder.AddRenderPass(builder.obj, &forward);
 | 
					 | 
				
			||||||
    builder.AddColorOutput(builder.obj,
 | 
					 | 
				
			||||||
                           "forward",
 | 
					 | 
				
			||||||
                           "backbuffer",
 | 
					 | 
				
			||||||
                           RT_PASS_LOAD_MODE_CLEAR,
 | 
					 | 
				
			||||||
                           RT_PASS_WRITE_MODE_STORE,
 | 
					 | 
				
			||||||
                           (rt_color){.r = 1.f, .g = 0.f, .b = 1.f, .a = 1.f});
 | 
					 | 
				
			||||||
    builder.SetDepthStencilAttachment(builder.obj,
 | 
					 | 
				
			||||||
                                      "forward",
 | 
					 | 
				
			||||||
                                      "depth",
 | 
					 | 
				
			||||||
                                      RT_PASS_LOAD_MODE_CLEAR,
 | 
					 | 
				
			||||||
                                      RT_PASS_WRITE_MODE_DISCARD,
 | 
					 | 
				
			||||||
                                      (rt_depth_stencil_value){.depth = 1.f, .stencil = 0});
 | 
					 | 
				
			||||||
    builder.SetRenderArea(
 | 
					 | 
				
			||||||
        builder.obj,
 | 
					 | 
				
			||||||
        "forward",
 | 
					 | 
				
			||||||
        (rt_rect2){
 | 
					 | 
				
			||||||
            .size = {RT_RENDER_TARGET_SIZE_SWAPCHAIN, RT_RENDER_TARGET_SIZE_SWAPCHAIN}
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
        0.f,
 | 
					 | 
				
			||||||
        1.f);
 | 
					 | 
				
			||||||
    builder.SetBackbuffer(builder.obj, "backbuffer");
 | 
					 | 
				
			||||||
    builder.BindRenderPass(builder.obj, "forward", ForwardPassExecute, NULL);
 | 
					 | 
				
			||||||
    if (builder.Build(builder.obj, &_graph) != RT_SUCCESS) {
 | 
					 | 
				
			||||||
        rtReportError("GAME", "Failed to build the render graph.");
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    g_renderer.DestroyRenderGraphBuilder(&builder);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Create a simple "scene" */
 | 
					 | 
				
			||||||
    _renderable_count = 1;
 | 
					 | 
				
			||||||
    _renderables      = calloc(_renderable_count, sizeof(rt_demo_renderable));
 | 
					 | 
				
			||||||
    RT_VERIFY(_renderables);
 | 
					 | 
				
			||||||
    for (unsigned int i = 0; i < _renderable_count; ++i) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        rt_vertex tri[3] = {
 | 
					 | 
				
			||||||
            {.pos = {0.f, 0.5f, 0.f}},
 | 
					 | 
				
			||||||
            {.pos = {-.5f, -.5f, 0.f}},
 | 
					 | 
				
			||||||
            {.pos = {.5f, -.5f, 0.f}},
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        rt_buffer_handle vbo;
 | 
					 | 
				
			||||||
        rt_buffer_info vbo_info = {
 | 
					 | 
				
			||||||
            .data  = tri,
 | 
					 | 
				
			||||||
            .size  = sizeof(tri),
 | 
					 | 
				
			||||||
            .type  = RT_BUFFER_TYPE_VERTEX,
 | 
					 | 
				
			||||||
            .usage = RT_BUFFER_USAGE_STATIC,
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
        if (g_renderer.CreateBuffers(1, &vbo_info, &vbo) != RT_SUCCESS) {
 | 
					 | 
				
			||||||
            rtReportError("GAME", "Oh noo...");
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        _renderables[i].vbo          = vbo;
 | 
					 | 
				
			||||||
        _renderables[i].vertex_count = 3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const rt_effect *effect;
 | 
					 | 
				
			||||||
        if (rtLoadEffect(rtGetResourceID("assets/shader/static_object.effect"), &effect) !=
 | 
					 | 
				
			||||||
            RT_SUCCESS) {
 | 
					 | 
				
			||||||
            rtReportError("GAME", "Oh noo...");
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        _renderables[i].effect = effect;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Called after exiting the main-loop and before the runtime starts its shutdown */
 | 
					/* Called after exiting the main-loop and before the runtime starts its shutdown */
 | 
				
			||||||
void Shutdown(void) {
 | 
					void Shutdown(void) {
 | 
				
			||||||
    rtLog("GAME", "Shutdown");
 | 
					    rtLog("GAME", "Shutdown");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (unsigned int i = 0; i < _renderable_count; ++i) {
 | 
					 | 
				
			||||||
        rtReleaseEffect(_renderables[i].effect);
 | 
					 | 
				
			||||||
        g_renderer.DestroyBuffers(1, &_renderables[i].vbo);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rtShutdownAssetCompiler();
 | 
					    rtShutdownAssetCompiler();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void DrawRenderables(unsigned int frame_id) {
 | 
					 | 
				
			||||||
    rt_create_render_view_result main_view_res =
 | 
					 | 
				
			||||||
        rtCreateRenderView(&g_builtin_render_object_types.render_mesh, 1, frame_id);
 | 
					 | 
				
			||||||
    if (!main_view_res.ok)
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    rt_render_view main_view   = main_view_res.view;
 | 
					 | 
				
			||||||
    const rt_effect_pass *pass = &_renderables[0].effect->passes[0];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (unsigned int i = 0; i < _renderable_count; ++i) {
 | 
					 | 
				
			||||||
        pass = &_renderables[i].effect->passes[0];
 | 
					 | 
				
			||||||
        rt_render_mesh mesh;
 | 
					 | 
				
			||||||
        mesh.vbo          = _renderables[i].vbo;
 | 
					 | 
				
			||||||
        mesh.vertex_count = _renderables[i].vertex_count;
 | 
					 | 
				
			||||||
        mesh.pipeline     = pass->pipeline;
 | 
					 | 
				
			||||||
        rtPushRenderObjectToView(&main_view, g_builtin_render_object_types.render_mesh, &mesh);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    rtSubmitRenderView(main_view, _graph, pass->pass_id, frame_id);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Question; How do we move data from update to render.
 | 
					// Question; How do we move data from update to render.
 | 
				
			||||||
// This is where we could fill the render views, but that would
 | 
					// This is where we could fill the render views, but that would
 | 
				
			||||||
// mean double/triple buffering the views
 | 
					// mean double/triple buffering the views
 | 
				
			||||||
void Update(unsigned int frame_id) {
 | 
					void Update(unsigned int frame_id) {
 | 
				
			||||||
    DrawRenderables(frame_id);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Render(unsigned int frame_id) {
 | 
					void Render(unsigned int frame_id) {
 | 
				
			||||||
    g_renderer.ExecuteRenderGraph(_graph, frame_id);
 | 
					 | 
				
			||||||
    g_renderer.ResetRenderGraph(_graph, frame_id);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
subdir('runtime')
 | 
					subdir('runtime')
 | 
				
			||||||
subdir('asset_compiler')
 | 
					subdir('asset_compiler')
 | 
				
			||||||
subdir('app_framework')
 | 
					subdir('app_framework')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					subdir('renderer/dx11')
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										46
									
								
								src/renderer/common/load_stub.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/renderer/common/load_stub.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					#include "renderer_api.h"
 | 
				
			||||||
 | 
					#include "runtime/dynamic_libs.h"
 | 
				
			||||||
 | 
					#include "runtime/config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static RT_CVAR_S(rt_Renderer, "The used renderer. Available options: dx11.", "dx11");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RT_DLLEXPORT rt_renderer_api g_renderer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef rt_renderer_api rt_load_renderer_impl_fn(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef RT_STATIC_LIB
 | 
				
			||||||
 | 
					extern rt_renderer_api rtLoadRendererImpl(void);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					static rt_dynlib _renderer_lib;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RT_DLLEXPORT rt_result rtLoadRenderer(void) {
 | 
				
			||||||
 | 
					    rt_load_renderer_impl_fn *LoadRendererImpl = NULL;
 | 
				
			||||||
 | 
					    if (!rtGetCVAR("rt_Renderer"))
 | 
				
			||||||
 | 
					        rtRegisterCVAR(&rt_Renderer);
 | 
				
			||||||
 | 
					#ifdef RT_STATIC_LIB
 | 
				
			||||||
 | 
					    LoadRendererImpl = rtLoadRendererImpl;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    const char *dllname = NULL;
 | 
				
			||||||
 | 
					    if (strcmp(rt_Renderer.s, "dx11")==0)
 | 
				
			||||||
 | 
					        dllname = RT_DLLNAME("rtdx11");
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        rtReportError("RENDERER", "Invalid renderer selected: %s", rt_Renderer.s);
 | 
				
			||||||
 | 
					        return RT_INVALID_VALUE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    _renderer_lib = rtOpenLib(dllname);
 | 
				
			||||||
 | 
					    if (!_renderer_lib) {
 | 
				
			||||||
 | 
					        rtReportError("RENDERER", "Unable to load renderer backend: %s", dllname);
 | 
				
			||||||
 | 
					        return RT_UNKNOWN_ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    LoadRendererImpl = (rt_load_renderer_impl_fn *)rtGetSymbol(_renderer_lib, "rtLoadRendererImpl");
 | 
				
			||||||
 | 
					    if (!LoadRendererImpl) {
 | 
				
			||||||
 | 
					        rtReportError("RENDERER", "Invalid renderer. Could not find rtLoadRendererImpl");
 | 
				
			||||||
 | 
					        return RT_UNKNOWN_ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    g_renderer = LoadRendererImpl();
 | 
				
			||||||
 | 
					    return RT_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								src/renderer/common/renderer_api.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/renderer/common/renderer_api.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					#ifndef RT_RENCOM_RENDERER_API_H
 | 
				
			||||||
 | 
					#define RT_RENCOM_RENDERER_API_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "runtime/runtime.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Defines the outward facing renderer api */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef _WIN32
 | 
				
			||||||
 | 
					struct HINSTANCE__;
 | 
				
			||||||
 | 
					struct HWND__;
 | 
				
			||||||
 | 
					#elif defined(RT_USE_XLIB)
 | 
				
			||||||
 | 
					struct _XDisplay;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Platform specific init info for the renderer */
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					#ifdef _WIN32
 | 
				
			||||||
 | 
					    struct HINSTANCE__ *hInstance;
 | 
				
			||||||
 | 
					    struct HWND__ *hWnd;
 | 
				
			||||||
 | 
					#elif defined(RT_USE_XLIB)
 | 
				
			||||||
 | 
					    struct _XDisplay *display;
 | 
				
			||||||
 | 
					    unsigned long window;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					} rt_renderer_init_info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef rt_result rt_renderer_init_fn(const rt_renderer_init_info *info);
 | 
				
			||||||
 | 
					typedef void rt_renderer_shutdown_fn(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    RT_SHADER_STAGE_VERTEX,
 | 
				
			||||||
 | 
					    RT_SHADER_STAGE_FRAGMENT,
 | 
				
			||||||
 | 
					    RT_SHADER_STAGE_COMPUTE,
 | 
				
			||||||
 | 
					} rt_shader_stage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Public renderer interface */
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    rt_renderer_init_fn *Init;
 | 
				
			||||||
 | 
					    rt_renderer_shutdown_fn *Shutdown;
 | 
				
			||||||
 | 
					} rt_renderer_api;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Global renderer object */
 | 
				
			||||||
 | 
					RT_DLLIMPORT extern rt_renderer_api g_renderer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RT_DLLEXPORT rt_result rtLoadRenderer(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										18
									
								
								src/renderer/dx11/init.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/renderer/dx11/init.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					#include "renderer/common/renderer_api.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rt_result Dx11Init(const rt_renderer_init_info *info) {
 | 
				
			||||||
 | 
					    return RT_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Dx11Shutdown(void) {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Called by the application to retrieve the renderer api
 | 
				
			||||||
 | 
					extern "C" RT_DLLEXPORT rt_renderer_api rtLoadRendererImpl(void) {
 | 
				
			||||||
 | 
					    rt_renderer_api api = {
 | 
				
			||||||
 | 
					        .Init     = Dx11Init,
 | 
				
			||||||
 | 
					        .Shutdown = Dx11Shutdown,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    return api;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17
									
								
								src/renderer/dx11/meson.build
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/renderer/dx11/meson.build
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					if get_option('build_dx11')
 | 
				
			||||||
 | 
					  dx11_dep = declare_dependency(link_args: ['-ld3d11', '-ldxgi', '-lwinmm', '-ldxguid'])
 | 
				
			||||||
 | 
					  dx11_renderer_lib = library('rtdx11',
 | 
				
			||||||
 | 
					    '../common/renderer_api.h',
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    'init.cpp',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dependencies: [m_dep, windowing_dep, dx11_dep, thread_dep],
 | 
				
			||||||
 | 
					    include_directories: [engine_incdir, contrib_incdir],
 | 
				
			||||||
 | 
					    link_with: runtime_lib,
 | 
				
			||||||
 | 
					    cpp_pch: 'pch/dx11_pch.h',
 | 
				
			||||||
 | 
					    override_options: ['b_sanitize=none'],
 | 
				
			||||||
 | 
					    install: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  engine_libs += dx11_renderer_lib
 | 
				
			||||||
 | 
					  engine_lib_paths += dx11_renderer_lib.full_path()
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
							
								
								
									
										2
									
								
								src/renderer/dx11/pch/dx11_pch.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/renderer/dx11/pch/dx11_pch.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					#include "runtime/runtime.h"
 | 
				
			||||||
@ -10,8 +10,7 @@
 | 
				
			|||||||
#include "resources.h"
 | 
					#include "resources.h"
 | 
				
			||||||
#include "threading.h"
 | 
					#include "threading.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gfx/effect.h"
 | 
					#include "renderer/common/renderer_api.h"
 | 
				
			||||||
#include "gfx/renderer_api.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
@ -93,6 +92,7 @@ typedef struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static size_t GetResourceDataSize(const rt_resource *resource) {
 | 
					static size_t GetResourceDataSize(const rt_resource *resource) {
 | 
				
			||||||
    switch (resource->type) {
 | 
					    switch (resource->type) {
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
    case RT_RESOURCE_SHADER: {
 | 
					    case RT_RESOURCE_SHADER: {
 | 
				
			||||||
        /* Sizeof metadata + bytecode */
 | 
					        /* Sizeof metadata + bytecode */
 | 
				
			||||||
        const rt_shader_info *info = resource->data;
 | 
					        const rt_shader_info *info = resource->data;
 | 
				
			||||||
@ -101,7 +101,7 @@ static size_t GetResourceDataSize(const rt_resource *resource) {
 | 
				
			|||||||
    case RT_RESOURCE_PIPELINE:
 | 
					    case RT_RESOURCE_PIPELINE:
 | 
				
			||||||
        return sizeof(rt_pipeline_info);
 | 
					        return sizeof(rt_pipeline_info);
 | 
				
			||||||
    case RT_RESOURCE_FRAMEGRAPH: {
 | 
					    case RT_RESOURCE_FRAMEGRAPH: {
 | 
				
			||||||
        #if 0
 | 
					#if 0
 | 
				
			||||||
        const rt_framegraph_info *info = resource->data;
 | 
					        const rt_framegraph_info *info = resource->data;
 | 
				
			||||||
        size_t size = sizeof(*info) + sizeof(rt_render_target_info) * info->render_target_count +
 | 
					        size_t size = sizeof(*info) + sizeof(rt_render_target_info) * info->render_target_count +
 | 
				
			||||||
                      sizeof(rt_render_pass_info) * info->render_pass_count + info->names_size;
 | 
					                      sizeof(rt_render_pass_info) * info->render_pass_count + info->names_size;
 | 
				
			||||||
@ -111,11 +111,12 @@ static size_t GetResourceDataSize(const rt_resource *resource) {
 | 
				
			|||||||
                    passes[i].write_render_target_count * sizeof(rt_render_target_write);
 | 
					                    passes[i].write_render_target_count * sizeof(rt_render_target_write);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return size;
 | 
					        return size;
 | 
				
			||||||
        #endif
 | 
					#endif
 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
    case RT_RESOURCE_EFFECT: {
 | 
					    case RT_RESOURCE_EFFECT: {
 | 
				
			||||||
        return sizeof(rt_effect_info);
 | 
					        return sizeof(rt_effect_info);
 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        rtLog("RESMGR", "Tried to get size of an invalid resource type %u", resource->type);
 | 
					        rtLog("RESMGR", "Tried to get size of an invalid resource type %u", resource->type);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -124,6 +125,7 @@ static size_t GetResourceDataSize(const rt_resource *resource) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void CopyResourceData(const rt_resource *resource, void *dest) {
 | 
					static void CopyResourceData(const rt_resource *resource, void *dest) {
 | 
				
			||||||
    switch (resource->type) {
 | 
					    switch (resource->type) {
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
    case RT_RESOURCE_SHADER: {
 | 
					    case RT_RESOURCE_SHADER: {
 | 
				
			||||||
        /* Sizeof metadata + bytecode */
 | 
					        /* Sizeof metadata + bytecode */
 | 
				
			||||||
        const rt_shader_info *info = resource->data;
 | 
					        const rt_shader_info *info = resource->data;
 | 
				
			||||||
@ -136,7 +138,7 @@ static void CopyResourceData(const rt_resource *resource, void *dest) {
 | 
				
			|||||||
        memcpy(dest, resource->data, sizeof(rt_pipeline_info));
 | 
					        memcpy(dest, resource->data, sizeof(rt_pipeline_info));
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case RT_RESOURCE_FRAMEGRAPH: {
 | 
					    case RT_RESOURCE_FRAMEGRAPH: {
 | 
				
			||||||
        #if 0
 | 
					#if 0
 | 
				
			||||||
        const rt_framegraph_info *info = resource->data;
 | 
					        const rt_framegraph_info *info = resource->data;
 | 
				
			||||||
        rt_framegraph_info *dest_info  = dest;
 | 
					        rt_framegraph_info *dest_info  = dest;
 | 
				
			||||||
        memcpy(dest_info, info, sizeof(*info));
 | 
					        memcpy(dest_info, info, sizeof(*info));
 | 
				
			||||||
@ -206,11 +208,12 @@ static void CopyResourceData(const rt_resource *resource, void *dest) {
 | 
				
			|||||||
                rtSetRelptr(&passes_dest[i].name, names_begin + (src_name - src_names));
 | 
					                rtSetRelptr(&passes_dest[i].name, names_begin + (src_name - src_names));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #endif
 | 
					#endif
 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
    case RT_RESOURCE_EFFECT: {
 | 
					    case RT_RESOURCE_EFFECT: {
 | 
				
			||||||
        memcpy(dest, resource->data, sizeof(rt_effect_info));
 | 
					        memcpy(dest, resource->data, sizeof(rt_effect_info));
 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        rtLog("RESMGR", "Tried to copy a resource of invalid type %u", resource->type);
 | 
					        rtLog("RESMGR", "Tried to copy a resource of invalid type %u", resource->type);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -968,6 +971,7 @@ RT_DLLEXPORT void rDebugLogResource(rt_resource_id id, const rt_resource *resour
 | 
				
			|||||||
        rtLog("RESMGR", "    - %llx", resource->dependencies[i]);
 | 
					        rtLog("RESMGR", "    - %llx", resource->dependencies[i]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    switch (resource->type) {
 | 
					    switch (resource->type) {
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
    case RT_RESOURCE_SHADER: {
 | 
					    case RT_RESOURCE_SHADER: {
 | 
				
			||||||
        static const char *stype_str[RT_SHADER_TYPE_count]  = {"<INVALID>", "Vulkan"};
 | 
					        static const char *stype_str[RT_SHADER_TYPE_count]  = {"<INVALID>", "Vulkan"};
 | 
				
			||||||
        static const char *stage_str[RT_SHADER_STAGE_count] = {"Vertex", "Fragment", "Compute"};
 | 
					        static const char *stage_str[RT_SHADER_STAGE_count] = {"Vertex", "Fragment", "Compute"};
 | 
				
			||||||
@ -989,7 +993,6 @@ RT_DLLEXPORT void rDebugLogResource(rt_resource_id id, const rt_resource *resour
 | 
				
			|||||||
        rtLog("RESMGR", "    compute shader:  %llx", pipeline->compute_shader);
 | 
					        rtLog("RESMGR", "    compute shader:  %llx", pipeline->compute_shader);
 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
    case RT_RESOURCE_FRAMEGRAPH: {
 | 
					    case RT_RESOURCE_FRAMEGRAPH: {
 | 
				
			||||||
        #if 0
 | 
					 | 
				
			||||||
        static const char *format_str[RT_PIXEL_FORMAT_count] = {
 | 
					        static const char *format_str[RT_PIXEL_FORMAT_count] = {
 | 
				
			||||||
            "<INVALID>",
 | 
					            "<INVALID>",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1067,7 +1070,6 @@ RT_DLLEXPORT void rDebugLogResource(rt_resource_id id, const rt_resource *resour
 | 
				
			|||||||
                      writes[j].clear.depth_stencil.stencil);
 | 
					                      writes[j].clear.depth_stencil.stencil);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        #endif
 | 
					 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
    case RT_RESOURCE_EFFECT: {
 | 
					    case RT_RESOURCE_EFFECT: {
 | 
				
			||||||
        const rt_effect_info *effect = resource->data;
 | 
					        const rt_effect_info *effect = resource->data;
 | 
				
			||||||
@ -1078,6 +1080,7 @@ RT_DLLEXPORT void rDebugLogResource(rt_resource_id id, const rt_resource *resour
 | 
				
			|||||||
            rtLog("RESMGR", "      pipeline: %llx", effect->passes[i].pipeline);
 | 
					            rtLog("RESMGR", "      pipeline: %llx", effect->passes[i].pipeline);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } break;
 | 
					    } break;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        rtLog("RESMGR", "  unknown data at: %llx", (uintptr_t)resource->data);
 | 
					        rtLog("RESMGR", "  unknown data at: %llx", (uintptr_t)resource->data);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user