vertex pull shape verts

This commit is contained in:
jacob 2025-07-26 04:20:41 -05:00
parent bd4b55c2e0
commit 2237762d06
6 changed files with 57 additions and 32 deletions

View File

@ -1,3 +1,23 @@
#if !RESOURCE_RELOADING
extern "C"
{
#include "dxc.h"
}
struct dxc_compile_result dxc_compile(struct arena *arena, struct string shader_source, i32 num_args, struct string *args)
{
(UNUSED)arena;
(UNUSED)shader_source;
(UNUSED)num_args;
(UNUSED)args;
struct dxc_compile_result res = ZI;
return res;
}
#else
extern "C"
{
#include "dxc.h"
@ -67,3 +87,5 @@ struct dxc_compile_result dxc_compile(struct arena *arena, struct string shader_
scratch_end(scratch);
return res;
}
#endif

View File

@ -36,6 +36,7 @@
#pragma comment(lib, "d3d12")
#pragma comment(lib, "dxgi")
#pragma comment(lib, "dxguid")
#pragma comment(lib, "d3dcompiler")
#if PROFILING_GPU
/* For RegOpenKeyEx */
@ -98,7 +99,6 @@ struct pipeline_desc {
struct string ps_dxc;
struct string cs_dxc;
D3D12_INPUT_ELEMENT_DESC ia[8];
struct pipeline_rtv_desc rtvs[8];
};
@ -738,8 +738,6 @@ INTERNAL void dx12_init_pipelines(void)
{
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
desc->name = LIT("shape");
desc->ia[0] = (D3D12_INPUT_ELEMENT_DESC) { "pos", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 };
desc->ia[1] = (D3D12_INPUT_ELEMENT_DESC) { "color_srgb", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 };
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc->rtvs[0].blending = 1;
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
@ -869,6 +867,8 @@ INTERNAL void dx12_init_noise(void)
* Shader compilation
* ========================== */
#if RESOURCE_RELOADING
struct shader_compile_desc {
struct string src;
struct string friendly_name;
@ -932,6 +932,8 @@ INTERNAL SYS_JOB_DEF(shader_compile_job, job)
scratch_end(scratch);
}
#endif
/* ========================== *
* Pipeline
* ========================== */
@ -1115,18 +1117,8 @@ INTERNAL SYS_JOB_DEF(pipeline_alloc_job, job)
.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF
};
/* Input layout */
u32 num_input_layout_elements = 0;
for (u32 i = 0; i < countof(desc->ia); ++i) {
if (desc->ia[i].SemanticName == 0) {
break;
}
++num_input_layout_elements;
}
D3D12_INPUT_LAYOUT_DESC input_layout_desc = {
.pInputElementDescs = desc->ia,
.NumElements = num_input_layout_elements
};
/* Empty input layout */
D3D12_INPUT_LAYOUT_DESC input_layout_desc = ZI;
/* Blend state */
D3D12_BLEND_DESC blend_desc = {
@ -2874,11 +2866,11 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
/* Upload buffers */
u64 num_ui_shape_verts = rsig->ui_shape_verts_arena->pos / sizeof(struct sh_shape_vert);
u64 num_ui_shape_indices = rsig->ui_shape_indices_arena->pos / sizeof(u16);
u64 num_ui_shape_indices = rsig->ui_shape_indices_arena->pos / sizeof(u32);
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, rsig->num_material_instance_descs, material_instances);
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, rsig->num_ui_rect_instance_descs, ui_rect_instances);
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, num_ui_shape_verts, (struct sh_shape_vert *)arena_base(rsig->ui_shape_verts_arena));
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u16 *)arena_base(rsig->ui_shape_indices_arena));
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u32 *)arena_base(rsig->ui_shape_indices_arena));
struct command_buffer *grid_buffer = command_list_push_buffer(cl, rsig->num_material_grid_descs, grids);
/* Upload descriptor heap */
@ -3178,11 +3170,12 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
/* Set sig */
struct sh_shape_sig sig = ZI;
sig.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
sig.verts_urid = sh_uint_from_u32(ui_shape_verts_buffer->resource->srv_descriptor->index);
command_list_set_sig(cl, &sig, sizeof(sig));
/* Draw */
u32 index_count = ui_shape_indices_buffer->size / sizeof(u32);
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(ui_shape_verts_buffer, sizeof(struct sh_shape_vert));
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0);
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(ui_shape_indices_buffer, DXGI_FORMAT_R32_UINT);
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv);

View File

@ -13,7 +13,7 @@
# define INLINE /* For intellisense */
#endif
INLINE float4 float4_norm_from_uint(uint v)
INLINE float4 float4_from_uint_norm(uint v)
{
float4 res;
res.r = ((v >> 0) & 0xFF) / 255.0;
@ -32,7 +32,7 @@ INLINE float4 linear_from_srgb(float4 srgb)
/* Linear color from R8G8B8A8 sRGB */
INLINE float4 linear_from_srgb32(uint srgb32)
{
return linear_from_srgb(float4_norm_from_uint(srgb32));
return linear_from_srgb(float4_from_uint_norm(srgb32));
}
/* ========================== *

View File

@ -104,7 +104,8 @@ SH_STRUCT(sh_material_sig {
/* ----------------------------------------------------- */
SH_DECL(uint, instances_urid); /* 01 consts */
SH_DECL(uint, grids_urid); /* 01 consts */
SH_DECL(uint2, _pad0); /* 02 consts (padding) */
SH_DECL(uint, _pad0); /* 01 consts (padding) */
SH_DECL(uint, _pad1); /* 01 consts (padding) */
/* ----------------------------------------------------- */
});
SH_ASSERT_ROOT_CONST(struct sh_material_sig, 20);
@ -144,7 +145,8 @@ SH_STRUCT(sh_flood_sig {
/* ----------------------------------------------------- */
SH_DECL(uint, tex_width); /* 01 consts */
SH_DECL(uint, tex_height); /* 01 consts */
SH_DECL(uint2, _pad0); /* 02 consts (padding) */
SH_DECL(uint, _pad0); /* 01 consts (padding) */
SH_DECL(uint, _pad1); /* 01 consts (padding) */
/* ----------------------------------------------------- */
});
SH_ASSERT_ROOT_CONST(struct sh_flood_sig, 8);
@ -185,12 +187,17 @@ SH_STRUCT(sh_shape_sig {
/* ----------------------------------------------------- */
SH_DECL(float4x4, projection); /* 16 consts */
/* ----------------------------------------------------- */
SH_DECL(uint, verts_urid); /* 01 consts */
SH_DECL(uint, _pad0); /* 01 consts (padding) */
SH_DECL(uint, _pad1); /* 01 consts (padding) */
SH_DECL(uint, _pad2); /* 01 consts (padding) */
/* ----------------------------------------------------- */
});
SH_ASSERT_ROOT_CONST(struct sh_shape_sig, 16);
SH_ASSERT_ROOT_CONST(struct sh_shape_sig, 20);
SH_STRUCT(sh_shape_vert {
SH_DECLS(float2, pos);
SH_DECLS(uint, color_srgb);
SH_DECL(float2, pos);
SH_DECL(uint, color_srgb);
});
/* ========================== *
@ -202,7 +209,9 @@ SH_STRUCT(sh_ui_sig {
SH_DECL(float4x4, projection); /* 16 consts */
/* ----------------------------------------------------- */
SH_DECL(uint, instances_urid); /* 01 consts */
SH_DECL(uint3, _pad0); /* 03 consts (padding) */
SH_DECL(uint, _pad0); /* 01 consts (padding) */
SH_DECL(uint, _pad1); /* 01 consts (padding) */
SH_DECL(uint, _pad2); /* 01 consts (padding) */
/* ----------------------------------------------------- */
});
SH_ASSERT_ROOT_CONST(struct sh_ui_sig, 20);

View File

@ -1,14 +1,13 @@
#include "common.hlsl"
ConstantBuffer<struct sh_material_sig> sig : register(b0);
ConstantBuffer<struct sh_shape_sig> sig : register(b0);
/* ========================== *
* Vertex shader
* ========================== */
struct vs_input {
DECLS(float2, pos);
DECLS(float4, color_srgb);
DECLS(uint, SV_VertexID);
};
struct vs_output {
@ -18,9 +17,11 @@ struct vs_output {
SH_ENTRY struct vs_output vs(struct vs_input input)
{
StructuredBuffer<struct sh_shape_vert> verts = resource_from_urid(sig.verts_urid);
struct sh_shape_vert vert = verts[input.SV_VertexID];
struct vs_output output;
output.SV_Position = mul(sig.projection, float4(input.pos.xy, 0, 1));
output.color_srgb = input.color_srgb;
output.SV_Position = mul(sig.projection, float4(vert.pos.xy, 0, 1));
output.color_srgb = float4_from_uint_norm(vert.color_srgb);
return output;
}

View File

@ -36,7 +36,7 @@ SH_ENTRY struct vs_output vs(struct vs_input input)
output.SV_Position = mul(sig.projection, float4(world_pos, 0, 1));
output.tex_nurid = instance.tex_nurid;
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
output.tint_srgb = float4_norm_from_uint(instance.tint_srgb);
output.tint_srgb = float4_from_uint_norm(instance.tint_srgb);
return output;
}