rename res/gpu -> res/fx

This commit is contained in:
jacob 2025-06-08 20:18:03 -05:00
parent 1655d699ce
commit 012d0aaf07
6 changed files with 21 additions and 22 deletions

View File

@ -1,6 +1,11 @@
#include "gpu/common.hlsl"
#include "fx/common.hlsl"
struct instance {
struct fx_material_constant {
float4x4 projection;
uint instance_offset;
};
struct fx_material_instance {
float2x3 xf;
float2 uv0;
float2 uv1;
@ -8,11 +13,6 @@ struct instance {
float emittance;
};
struct constants {
float4x4 projection;
uint instance_offset;
};
/* ========================== *
* Root Signature
* ========================== */
@ -24,10 +24,10 @@ struct constants {
cbuffer cbuff : register(b0)
{
struct constants g_constants;
struct fx_material_constant g_constant;
};
StructuredBuffer<struct instance> g_instances : register(t0);
StructuredBuffer<struct fx_material_instance> g_instances : register(t0);
Texture2D g_texture : register(t1);
@ -58,15 +58,15 @@ struct vs_output {
};
[RootSignature(ROOTSIG)]
struct vs_output vs(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID)
struct vs_output fx_material_vs(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID)
{
struct instance instance = g_instances[g_constants.instance_offset + instance_id];
struct fx_material_instance instance = g_instances[g_constant.instance_offset + instance_id];
float2 vert = g_quad_verts[vertex_id];
float2 uv_factor = g_uv_factors[vertex_id];
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy;
struct vs_output output;
output.screen_pos = mul(g_constants.projection, float4(world_pos, 0, 1));
output.screen_pos = mul(g_constant.projection, float4(world_pos, 0, 1));
output.uv = instance.uv0 + uv_factor * (instance.uv1 - instance.uv0);
output.tint_lin = linear_from_srgb32(instance.tint_srgb);
@ -78,7 +78,7 @@ struct vs_output vs(uint instance_id : SV_InstanceID, uint vertex_id : SV_Vertex
* ========================== */
[RootSignature(ROOTSIG)]
float4 ps(struct vs_output input) : SV_TARGET
float4 fx_material_ps(struct vs_output input) : SV_TARGET
{
float4 color = g_texture.Sample(g_sampler, input.uv) * input.tint_lin;
return color;

View File

@ -27,6 +27,8 @@
#pragma comment(lib, "dxguid")
#pragma comment(lib, "d3dcompiler")
#define FX_CPU 1
#define DX12_WAIT_FRAME_LATENCY 1
#define DX12_ALLOW_TEARING 1
@ -537,11 +539,8 @@ INTERNAL void dx12_init_base(struct sys_window *window)
* Dx12 pipeline initialization
* ========================== */
/* For shared C-HLSL headers */
#define GPU 0
/* TDOO: Rename 'mesh shader' to 'triangle shader' or something */
/* TODO: Move shader structs into shared file */
/* TODO: Move shader structs into shared C-HLSL header file */
/* ============= */
/* Mesh pipeline */
@ -549,12 +548,12 @@ INTERNAL void dx12_init_base(struct sys_window *window)
/* ============= */
/* Material pipeline */
PACK(struct dx12_buffer_pipeline_uniform {
PACK(struct fx_material_constant {
struct mat4x4 vp;
u32 instance_offset;
});
PACK(struct dx12_buffer_pipeline_instance {
PACK(struct fx_material_instance {
struct xform xf;
struct v2 uv0;
struct v2 uv1;
@ -579,8 +578,8 @@ INTERNAL void dx12_init_pipelines(void)
/* Material pipeline */
{
.name = "material",
.vs = { "gpu/material.hlsl", "vs" },
.ps = { "gpu/material.hlsl", "ps" }
.vs = { "fx/material.hlsl", "fx_material_vs" },
.ps = { "fx/material.hlsl", "fx_material_ps" }
}
};
@ -742,7 +741,7 @@ INTERNAL WORK_TASK_FUNC_DEF(shader_compile_task, comp_arg_raw)
} break;
}
D3D_SHADER_MACRO defines[] = {
{ "GPU", "1" },
{ "FX_CPU", "0" },
{ NULL, NULL }
};
HRESULT hr = D3DCompile(shader_src.text, shader_src.len, friendly_name_cstr, defines, (ID3DInclude *)&include_handler, shader_desc.func, target, d3d_compile_flags, 0, &blob, &error_blob);