renderer working again
This commit is contained in:
parent
27c2e34e24
commit
5952bd99e9
@ -5,69 +5,50 @@
|
|||||||
#define GoldenRatio ((f32)1.61803398874989484820)
|
#define GoldenRatio ((f32)1.61803398874989484820)
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Floating point vector2 types
|
//~ Vector types
|
||||||
|
|
||||||
Struct(Vec2) {
|
|
||||||
f32 x, y;
|
|
||||||
};
|
|
||||||
#define VEC2(x, y) (Vec2) { (x), (y) }
|
#define VEC2(x, y) (Vec2) { (x), (y) }
|
||||||
|
#define VEC3(x, y, z) (Vec3) { (x), (y), (z) }
|
||||||
|
#define VEC4(x, y, z, w) (Vec4) { (x), (y), (z), (w) }
|
||||||
|
|
||||||
Struct(Vec2Array) {
|
#define VEC2I32(x, y) (Vec2I32) { (x), (y) }
|
||||||
|
#define VEC3I32(x, y, z) (Vec3I32) { (x), (y), (z) }
|
||||||
|
#define VEC4I32(x, y, z, w) (Vec4I32) { (x), (y), (z), (w) }
|
||||||
|
|
||||||
|
#define VEC2U32(x, y) (Vec2U32) { (x), (y) }
|
||||||
|
#define VEC3U32(x, y, z) (Vec3U32) { (x), (y), (z) }
|
||||||
|
#define VEC4U32(x, y, z, w) (Vec4U32) { (x), (y), (z), (w) }
|
||||||
|
|
||||||
|
Struct(Vec2) { f32 x, y; };
|
||||||
|
Struct(Vec3) { f32 x, y, z; };
|
||||||
|
Struct(Vec4) { f32 x, y, z, w; };
|
||||||
|
|
||||||
|
Struct(Vec2I32) { i32 x, y; };
|
||||||
|
Struct(Vec3I32) { i32 x, y, z; };
|
||||||
|
Struct(Vec4I32) { i32 x, y, z, w; };
|
||||||
|
|
||||||
|
Struct(Vec2U32) { u32 x, y; };
|
||||||
|
Struct(Vec3U32) { u32 x, y, z; };
|
||||||
|
Struct(Vec4U32) { u32 x, y, z, w; };
|
||||||
|
|
||||||
|
Struct(Vec2Array)
|
||||||
|
{
|
||||||
Vec2 *points;
|
Vec2 *points;
|
||||||
u64 count;
|
u64 count;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
Struct(Vec3Array)
|
||||||
//~ Floating point vector3 types
|
{
|
||||||
|
|
||||||
Struct(Vec3) {
|
|
||||||
f32 x, y, z;
|
|
||||||
};
|
|
||||||
#define VEC3(x, y, z) (Vec3) { (x), (y), (z) }
|
|
||||||
|
|
||||||
Struct(Vec3Array) {
|
|
||||||
Vec3 *points;
|
Vec3 *points;
|
||||||
u64 count;
|
u64 count;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
Struct(Vec4Array)
|
||||||
//~ Floating point vector4 types
|
{
|
||||||
|
|
||||||
Struct(Vec4) {
|
|
||||||
f32 x, y, z, w;
|
|
||||||
};
|
|
||||||
#define VEC4(x, y, z, w) ((Vec4) { (x), (y), (z), (w) })
|
|
||||||
|
|
||||||
Struct(Vec4Array) {
|
|
||||||
Vec4 *points;
|
Vec4 *points;
|
||||||
u64 count;
|
u64 count;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Integer vec2 types
|
|
||||||
|
|
||||||
Struct(Vec2I32) {
|
|
||||||
i32 x, y;
|
|
||||||
};
|
|
||||||
#define VEC2I32(x, y) (Vec2I32) { (x), (y) }
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Integer vector3 types
|
|
||||||
|
|
||||||
Struct(Vec3I32) {
|
|
||||||
i32 x, y, z;
|
|
||||||
};
|
|
||||||
#define VEC3I32(x, y, z) (Vec3I32) { (x), (y), (z) }
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Integer vector4 types
|
|
||||||
|
|
||||||
Struct(Vec4I32)
|
|
||||||
{
|
|
||||||
i32 x, y, z, w;
|
|
||||||
};
|
|
||||||
#define VEC4I32(x, y, z, w) (Vec4I32) { (x), (y), (z), (w) }
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Xform types
|
//~ Xform types
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,9 @@ typedef float4 Vec4;
|
|||||||
typedef int2 Vec2I32;
|
typedef int2 Vec2I32;
|
||||||
typedef int3 Vec3I32;
|
typedef int3 Vec3I32;
|
||||||
typedef int4 Vec4I32;
|
typedef int4 Vec4I32;
|
||||||
|
typedef uint2 Vec2U32;
|
||||||
|
typedef uint3 Vec3U32;
|
||||||
|
typedef uint4 Vec4U32;
|
||||||
typedef float2x3 Xform;
|
typedef float2x3 Xform;
|
||||||
typedef float4 Rect;
|
typedef float4 Rect;
|
||||||
typedef float4 ClipRect;
|
typedef float4 ClipRect;
|
||||||
|
|||||||
121
src/gpu/gpu.h
121
src/gpu/gpu.h
@ -29,7 +29,7 @@ Enum(GPU_QueueKind)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Format types
|
//~ Format types
|
||||||
|
|
||||||
/* NOTE: Matches DXGI_FORMAT */
|
/* NOTE: Matches DirectX DXGI_FORMAT */
|
||||||
Enum(GPU_Format)
|
Enum(GPU_Format)
|
||||||
{
|
{
|
||||||
GPU_Format_Unknown = 0,
|
GPU_Format_Unknown = 0,
|
||||||
@ -151,12 +151,91 @@ Enum(GPU_Format)
|
|||||||
GPU_Format_P208 = 130,
|
GPU_Format_P208 = 130,
|
||||||
GPU_Format_V208 = 131,
|
GPU_Format_V208 = 131,
|
||||||
GPU_Format_V408 = 132,
|
GPU_Format_V408 = 132,
|
||||||
GPU_Format_SAMPLER_FEEDBACK_MIN_MIP_Opaque = 189,
|
GPU_Format_SamplerFeedbackMinMipOpaque = 189,
|
||||||
GPU_Format_SAMPLER_FEEDBACK_MIP_REGION_USED_Opaque = 190,
|
GPU_Format_SamplerFeedbackMipRegionUsedOpaque = 190,
|
||||||
GPU_Format_A4B4G4R4_Unorm = 191,
|
GPU_Format_A4B4G4R4_Unorm = 191,
|
||||||
GPU_Format_Count = 192
|
GPU_Format_Count = 192
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Filter types
|
||||||
|
|
||||||
|
/* NOTE: Matches DirectX D3D12_FILTER */
|
||||||
|
Enum(GPU_Filter)
|
||||||
|
{
|
||||||
|
/* Standard filter */
|
||||||
|
GPU_Filter_MinMagMipPoint = 0,
|
||||||
|
GPU_Filter_MinMagPointMipLinear = 0x1,
|
||||||
|
GPU_Filter_MinPointMagLinearMipPoint = 0x4,
|
||||||
|
GPU_Filter_MinPointMagMipLinear = 0x5,
|
||||||
|
GPU_Filter_MinLinearMagMipPoint = 0x10,
|
||||||
|
GPU_Filter_MinLinearMagPointMipLinear = 0x11,
|
||||||
|
GPU_Filter_MinMagLinearMipPoint = 0x14,
|
||||||
|
GPU_Filter_MinMagMipLinear = 0x15,
|
||||||
|
GPU_Filter_MinMagAnisotropicMipPoint = 0x54,
|
||||||
|
GPU_Filter_Anisotropic = 0x55,
|
||||||
|
|
||||||
|
/* Comparison filter */
|
||||||
|
GPU_Filter_Comparison_MinMagMipPoint = 0x80,
|
||||||
|
GPU_Filter_Comparison_MinMagPointMipLinear = 0x81,
|
||||||
|
GPU_Filter_Comparison_MinPointMagLinearMipPoint = 0x84,
|
||||||
|
GPU_Filter_Comparison_MinPointMagMipLinear = 0x85,
|
||||||
|
GPU_Filter_Comparison_MinLinearMagMipPoint = 0x90,
|
||||||
|
GPU_Filter_Comparison_MinLinearMagPointMipLinear = 0x91,
|
||||||
|
GPU_Filter_Comparison_MinMagLinearMipPoint = 0x94,
|
||||||
|
GPU_Filter_Comparison_MinMagMipLinear = 0x95,
|
||||||
|
GPU_Filter_Comparison_MinMagAnisotropicMipPoint = 0xd4,
|
||||||
|
GPU_Filter_Comparison_Anisotropic = 0xd5,
|
||||||
|
|
||||||
|
/* Minimum filter */
|
||||||
|
GPU_Filter_Minimum_MinMagMipPoint = 0x100,
|
||||||
|
GPU_Filter_Minimum_MinMagPointMipLinear = 0x101,
|
||||||
|
GPU_Filter_Minimum_MinPointMagLinearMipPoint = 0x104,
|
||||||
|
GPU_Filter_Minimum_MinPointMagMipLinear = 0x105,
|
||||||
|
GPU_Filter_Minimum_MinLinearMagMipPoint = 0x110,
|
||||||
|
GPU_Filter_Minimum_MinLinearMagPointMipLinear = 0x111,
|
||||||
|
GPU_Filter_Minimum_MinMagLinearMipPoint = 0x114,
|
||||||
|
GPU_Filter_Minimum_MinMagMipLinear = 0x115,
|
||||||
|
GPU_Filter_Minimum_MinMagAnisotropicMipPoint = 0x155,
|
||||||
|
GPU_Filter_Minimum_Anisotropic = 0x155,
|
||||||
|
|
||||||
|
/* Maximum filter */
|
||||||
|
GPU_Filter_Maximum_MinMagMipPoint = 0x180,
|
||||||
|
GPU_Filter_Maximum_MinMagPointMipLinear = 0x181,
|
||||||
|
GPU_Filter_Maximum_MinPointMagLinearMipPoint = 0x184,
|
||||||
|
GPU_Filter_Maximum_MinPointMagMipLinear = 0x185,
|
||||||
|
GPU_Filter_Maximum_MinLinearMagMipPoint = 0x190,
|
||||||
|
GPU_Filter_Maximum_MinLinearMagPointMipLinear = 0x191,
|
||||||
|
GPU_Filter_Maximum_MinMagLinearMipPoint = 0x194,
|
||||||
|
GPU_Filter_Maximum_MinMagMipLinear = 0x195,
|
||||||
|
GPU_Filter_Maximum_MinMagAnisotropicMipPoint = 0x1d4,
|
||||||
|
GPU_Filter_Maximum_Anisotropic = 0x1d5
|
||||||
|
};
|
||||||
|
|
||||||
|
/* NOTE: Matches DirectX D3D12_TEXTURE_ADDRESS_MODE */
|
||||||
|
Enum(GPU_AddressMode)
|
||||||
|
{
|
||||||
|
GPU_AddressMode_Wrap = 1,
|
||||||
|
GPU_AddressMode_Mirror = 2,
|
||||||
|
GPU_AddressMode_Clamp = 3,
|
||||||
|
GPU_AddressMode_Border = 4,
|
||||||
|
GPU_AddressMode_MirrorOnce = 5
|
||||||
|
};
|
||||||
|
|
||||||
|
/* NOTE: Matches DirectX D3D12_COMPARISON_FUNC */
|
||||||
|
Enum(GPU_ComparisonFunc)
|
||||||
|
{
|
||||||
|
GPU_ComparisonFunc_None = 0,
|
||||||
|
GPU_ComparisonFunc_Never = 1,
|
||||||
|
GPU_ComparisonFunc_Less = 2,
|
||||||
|
GPU_ComparisonFunc_Equal = 3,
|
||||||
|
GPU_ComparisonFunc_LessEqual = 4,
|
||||||
|
GPU_ComparisonFunc_Greater = 5,
|
||||||
|
GPU_ComparisonFunc_NotEqual = 6,
|
||||||
|
GPU_ComparisonFunc_GreaterEqual = 7,
|
||||||
|
GPU_ComparisonFunc_Always = 8
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Resource types
|
//~ Resource types
|
||||||
|
|
||||||
@ -174,9 +253,10 @@ Enum(GPU_ResourceKind)
|
|||||||
|
|
||||||
Enum(GPU_ResourceFlag)
|
Enum(GPU_ResourceFlag)
|
||||||
{
|
{
|
||||||
GPU_ResourceFlag_None = 0,
|
GPU_ResourceFlag_None = 0,
|
||||||
GPU_ResourceFlag_Writable = (1 << 0),
|
GPU_ResourceFlag_Writable = (1 << 0),
|
||||||
GPU_ResourceFlag_Renderable = (1 << 1),
|
GPU_ResourceFlag_Renderable = (1 << 1),
|
||||||
|
GPU_ResourceFlag_MaxMipLevels = (1 << 2),
|
||||||
};
|
};
|
||||||
|
|
||||||
Enum(GPU_HeapKind)
|
Enum(GPU_HeapKind)
|
||||||
@ -189,6 +269,10 @@ Enum(GPU_HeapKind)
|
|||||||
Enum(GPU_ReleaseFlag)
|
Enum(GPU_ReleaseFlag)
|
||||||
{
|
{
|
||||||
GPU_ReleaseFlag_None = 0,
|
GPU_ReleaseFlag_None = 0,
|
||||||
|
|
||||||
|
/* Hints to the GPU layer that more resources using the same desc will
|
||||||
|
* be allocated soon, so the resource's memory should be kept around for
|
||||||
|
* re-use. */
|
||||||
GPU_ReleaseFlag_Reuse = (1 << 0)
|
GPU_ReleaseFlag_Reuse = (1 << 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -212,6 +296,19 @@ Struct(GPU_ResourceDesc)
|
|||||||
u32 element_count;
|
u32 element_count;
|
||||||
u32 element_size;
|
u32 element_size;
|
||||||
} buffer;
|
} buffer;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
GPU_Filter filter;
|
||||||
|
GPU_AddressMode x;
|
||||||
|
GPU_AddressMode y;
|
||||||
|
GPU_AddressMode z;
|
||||||
|
f32 mip_lod_bias;
|
||||||
|
u32 max_anisotropy;
|
||||||
|
GPU_ComparisonFunc comparison;
|
||||||
|
Vec4 border_color;
|
||||||
|
f32 min_lod;
|
||||||
|
f32 max_lod;
|
||||||
|
} sampler;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -304,14 +401,14 @@ void GPU_ProfN(GPU_CommandList *cl, String name);
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdecl Barrier operations
|
//~ @hookdecl Barrier operations
|
||||||
|
|
||||||
void GPU_TransitionToReadable(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be read via read-only types in shaders */
|
void GPU_TransitionToReadable(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be read via read-only types in shaders */
|
||||||
void GPU_TransitionToWritable(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be read/written to via read-write types in shader */
|
void GPU_TransitionToWritable(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be read/written to via read-write types in shader */
|
||||||
void GPU_TransitionToRenderable(GPU_CommandList *cl, GPU_Resource *resource, i32 slot); /* Allows the resource to be used as a render target bound at slot */
|
void GPU_TransitionToRenderable(GPU_CommandList *cl, GPU_Resource *resource, i32 slot); /* Allows the resource to be used as a render target bound at slot */
|
||||||
|
|
||||||
void GPU_TransitionToCopySrc(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be used as a src in copy operations */
|
void GPU_TransitionToCopySrc(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be used as a source in copy operations */
|
||||||
void GPU_TransitionToCopyDst(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be used as a dst in copy operations */
|
void GPU_TransitionToCopyDst(GPU_CommandList *cl, GPU_Resource *resource); /* Allows the resource to be used as a destination in copy operations */
|
||||||
|
|
||||||
void GPU_FlushWritable(GPU_CommandList *cl, GPU_Resource *resource); /* Waits until all writes to a shader writable resource have completed */
|
void GPU_FlushWritable(GPU_CommandList *cl, GPU_Resource *resource); /* Waits until writes to a shader writable resource have completed */
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ @hookdecl Dispatch operations
|
//~ @hookdecl Dispatch operations
|
||||||
|
|||||||
@ -785,7 +785,7 @@ i64 GPU_D12_BlitToSwapchain(GPU_D12_SwapchainBuffer *dst, GPU_D12_Resource *text
|
|||||||
ID3D12GraphicsCommandList_ResourceBarrier(rcl, barriers_count, rbs);
|
ID3D12GraphicsCommandList_ResourceBarrier(rcl, barriers_count, rbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy (entire resource or a region)
|
/* Copy */
|
||||||
ID3D12GraphicsCommandList_CopyResource(rcl, dst->d3d_resource, texture->d3d_resource);
|
ID3D12GraphicsCommandList_CopyResource(rcl, dst->d3d_resource, texture->d3d_resource);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -971,6 +971,8 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
|
|||||||
|
|
||||||
switch (desc.kind)
|
switch (desc.kind)
|
||||||
{
|
{
|
||||||
|
case GPU_ResourceKind_Sampler: break;
|
||||||
|
|
||||||
/* Buffer */
|
/* Buffer */
|
||||||
case GPU_ResourceKind_Buffer:
|
case GPU_ResourceKind_Buffer:
|
||||||
{
|
{
|
||||||
@ -1013,14 +1015,14 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
|
|||||||
D3D12_RESOURCE_DESC d3d_desc = ZI;
|
D3D12_RESOURCE_DESC d3d_desc = ZI;
|
||||||
d3d_desc.Dimension = desc.kind == GPU_ResourceKind_Texture1D ? D3D12_RESOURCE_DIMENSION_TEXTURE1D
|
d3d_desc.Dimension = desc.kind == GPU_ResourceKind_Texture1D ? D3D12_RESOURCE_DIMENSION_TEXTURE1D
|
||||||
: desc.kind == GPU_ResourceKind_Texture2D ? D3D12_RESOURCE_DIMENSION_TEXTURE2D
|
: desc.kind == GPU_ResourceKind_Texture2D ? D3D12_RESOURCE_DIMENSION_TEXTURE2D
|
||||||
: GPU_ResourceKind_Texture3D;
|
: D3D12_RESOURCE_DIMENSION_TEXTURE3D;
|
||||||
d3d_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
d3d_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
d3d_desc.Format = GPU_D12_DxgiFormatFromGpuFormat(desc.texture.format);
|
d3d_desc.Format = GPU_D12_DxgiFormatFromGpuFormat(desc.texture.format);
|
||||||
d3d_desc.Alignment = 0;
|
d3d_desc.Alignment = 0;
|
||||||
d3d_desc.Width = desc.texture.size.x;
|
d3d_desc.Width = desc.texture.size.x;
|
||||||
d3d_desc.Height = desc.texture.size.y;
|
d3d_desc.Height = desc.texture.size.y;
|
||||||
d3d_desc.DepthOrArraySize = desc.texture.size.z;
|
d3d_desc.DepthOrArraySize = desc.texture.size.z;
|
||||||
d3d_desc.MipLevels = 1;
|
d3d_desc.MipLevels = (desc.flags & GPU_ResourceFlag_MaxMipLevels) ? 0 : MaxI32(desc.texture.mip_levels, 1);
|
||||||
d3d_desc.SampleDesc.Count = 1;
|
d3d_desc.SampleDesc.Count = 1;
|
||||||
d3d_desc.SampleDesc.Quality = 0;
|
d3d_desc.SampleDesc.Quality = 0;
|
||||||
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS * !!(desc.flags & GPU_ResourceFlag_Writable);
|
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS * !!(desc.flags & GPU_ResourceFlag_Writable);
|
||||||
@ -1039,8 +1041,6 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
|
|||||||
Panic(Lit("Failed to create buffer resource"));
|
Panic(Lit("Failed to create buffer resource"));
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
/* TODO: Sampler */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create texture srv descriptor */
|
/* Create texture srv descriptor */
|
||||||
@ -1086,7 +1086,26 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
|
|||||||
/* Create sampler descriptor */
|
/* Create sampler descriptor */
|
||||||
if (desc.kind == GPU_ResourceKind_Sampler)
|
if (desc.kind == GPU_ResourceKind_Sampler)
|
||||||
{
|
{
|
||||||
/* TODO */
|
D3D12_SAMPLER_DESC d3d_desc = ZI;
|
||||||
|
d3d_desc.Filter = (D3D12_FILTER)desc.sampler.filter;
|
||||||
|
d3d_desc.AddressU = (D3D12_TEXTURE_ADDRESS_MODE)desc.sampler.x;
|
||||||
|
d3d_desc.AddressV = (D3D12_TEXTURE_ADDRESS_MODE)desc.sampler.y;
|
||||||
|
d3d_desc.AddressW = (D3D12_TEXTURE_ADDRESS_MODE)desc.sampler.z;
|
||||||
|
d3d_desc.MipLODBias = desc.sampler.mip_lod_bias;
|
||||||
|
d3d_desc.MaxAnisotropy = desc.sampler.max_anisotropy;
|
||||||
|
d3d_desc.ComparisonFunc = (D3D12_COMPARISON_FUNC)desc.sampler.comparison;
|
||||||
|
d3d_desc.BorderColor[0] = desc.sampler.border_color.x;
|
||||||
|
d3d_desc.BorderColor[1] = desc.sampler.border_color.y;
|
||||||
|
d3d_desc.BorderColor[2] = desc.sampler.border_color.z;
|
||||||
|
d3d_desc.BorderColor[3] = desc.sampler.border_color.w;
|
||||||
|
d3d_desc.MinLOD = desc.sampler.min_lod;
|
||||||
|
d3d_desc.MaxLOD = desc.sampler.max_lod;
|
||||||
|
if (d3d_desc.MaxLOD >= F32Infinity)
|
||||||
|
{
|
||||||
|
d3d_desc.MaxLOD = D3D12_FLOAT32_MAX;
|
||||||
|
}
|
||||||
|
r->sampler_descriptor = GPU_D12_AcquireDescriptor(g->sampler_heap);
|
||||||
|
ID3D12Device_CreateSampler(g->device, &d3d_desc, r->sampler_descriptor->handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1110,8 +1129,6 @@ void GPU_ReleaseResource(GPU_Resource *gpu_resource, GPU_ReleaseFlag flags)
|
|||||||
{
|
{
|
||||||
ID3D12Resource_Release(r->d3d_resource);
|
ID3D12Resource_Release(r->d3d_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Sampler */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->srv_descriptor)
|
if (r->srv_descriptor)
|
||||||
@ -1236,9 +1253,11 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
|
|||||||
case GPU_D12_CommandKind_TransitionToCopyDst:
|
case GPU_D12_CommandKind_TransitionToCopyDst:
|
||||||
case GPU_D12_CommandKind_FlushUav:
|
case GPU_D12_CommandKind_FlushUav:
|
||||||
{
|
{
|
||||||
|
u64 barrier_gen = 1 + Atomic64FetchAdd(&g->resource_barrier_gen.v, 1);
|
||||||
|
|
||||||
/* Build barriers batch list */
|
/* Build barriers batch list */
|
||||||
u32 barriers_count = 0;
|
Struct(TmpBarrier) { TmpBarrier *next; GPU_D12_Resource *r; };
|
||||||
Struct(TmpBarrier) { TmpBarrier *next; GPU_D12_Resource *r; D3D12_RESOURCE_BARRIER_TYPE type; D3D12_RESOURCE_STATES state; };
|
u32 max_barriers_count = 0;
|
||||||
TmpBarrier *first_barrier = 0;
|
TmpBarrier *first_barrier = 0;
|
||||||
TmpBarrier *last_barrier = 0;
|
TmpBarrier *last_barrier = 0;
|
||||||
while (cmd && (cmd->kind == GPU_D12_CommandKind_TransitionToSrv
|
while (cmd && (cmd->kind == GPU_D12_CommandKind_TransitionToSrv
|
||||||
@ -1249,25 +1268,26 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
|
|||||||
|| cmd->kind == GPU_D12_CommandKind_FlushUav))
|
|| cmd->kind == GPU_D12_CommandKind_FlushUav))
|
||||||
{
|
{
|
||||||
D3D12_RESOURCE_BARRIER_TYPE type = ZI;
|
D3D12_RESOURCE_BARRIER_TYPE type = ZI;
|
||||||
D3D12_RESOURCE_STATES state = ZI;
|
D3D12_RESOURCE_STATES state_after = ZI;
|
||||||
GPU_D12_Resource *resource = cmd->barrier.resource;
|
GPU_D12_Resource *resource = cmd->barrier.resource;
|
||||||
|
|
||||||
switch (cmd->kind)
|
switch (cmd->kind)
|
||||||
{
|
{
|
||||||
case GPU_D12_CommandKind_TransitionToSrv:
|
case GPU_D12_CommandKind_TransitionToSrv:
|
||||||
{
|
{
|
||||||
|
|
||||||
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
state = D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE;
|
state_after = D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE;
|
||||||
} break;
|
} break;
|
||||||
case GPU_D12_CommandKind_TransitionToUav:
|
case GPU_D12_CommandKind_TransitionToUav:
|
||||||
{
|
{
|
||||||
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
|
state_after = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
|
||||||
} break;
|
} break;
|
||||||
case GPU_D12_CommandKind_TransitionToRtv:
|
case GPU_D12_CommandKind_TransitionToRtv:
|
||||||
{
|
{
|
||||||
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
state = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
state_after = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||||
i32 slot = cmd->barrier.rt_slot;
|
i32 slot = cmd->barrier.rt_slot;
|
||||||
if (slot >= 0 && slot < countof(slotted_render_targets))
|
if (slot >= 0 && slot < countof(slotted_render_targets))
|
||||||
{
|
{
|
||||||
@ -1277,12 +1297,12 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
|
|||||||
case GPU_D12_CommandKind_TransitionToCopySrc:
|
case GPU_D12_CommandKind_TransitionToCopySrc:
|
||||||
{
|
{
|
||||||
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
state = D3D12_RESOURCE_STATE_COPY_SOURCE;
|
state_after = D3D12_RESOURCE_STATE_COPY_SOURCE;
|
||||||
} break;
|
} break;
|
||||||
case GPU_D12_CommandKind_TransitionToCopyDst:
|
case GPU_D12_CommandKind_TransitionToCopyDst:
|
||||||
{
|
{
|
||||||
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
state = D3D12_RESOURCE_STATE_COPY_DEST;
|
state_after = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||||
} break;
|
} break;
|
||||||
case GPU_D12_CommandKind_FlushUav:
|
case GPU_D12_CommandKind_FlushUav:
|
||||||
{
|
{
|
||||||
@ -1291,49 +1311,64 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
b32 skip = 0;
|
b32 skip = 0;
|
||||||
if (type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION)
|
if (type == D3D12_RESOURCE_BARRIER_TYPE_UAV && resource->barrier_gen == barrier_gen)
|
||||||
{
|
{
|
||||||
skip = resource->state == state;
|
/* Skip UAV transitions on resources that already have transition in the batch */
|
||||||
|
skip = 1;
|
||||||
|
}
|
||||||
|
if (type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION && resource->barrier_state_after == state_after)
|
||||||
|
{
|
||||||
|
/* Skip transitions into existing state */
|
||||||
|
skip = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip)
|
if (!skip)
|
||||||
{
|
{
|
||||||
TmpBarrier *b = PushStruct(scratch.arena, TmpBarrier);
|
resource->barrier_type = type;
|
||||||
b->r = resource;
|
resource->barrier_state_after = state_after;
|
||||||
b->type = type;
|
if (resource->barrier_gen != barrier_gen)
|
||||||
b->state = state;
|
{
|
||||||
QueuePush(first_barrier, last_barrier, b);
|
TmpBarrier *b = PushStruct(scratch.arena, TmpBarrier);
|
||||||
++barriers_count;
|
resource->barrier_gen = barrier_gen;
|
||||||
|
b->r = resource;
|
||||||
|
QueuePush(first_barrier, last_barrier, b);
|
||||||
|
++max_barriers_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = cmd->next;
|
cmd = cmd->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Submit batched barriers */
|
/* Submit batched barriers */
|
||||||
if (barriers_count > 0)
|
/* FIXME: Transitions from UAV -> UAV should insert UAV barrier */
|
||||||
|
u32 barriers_count = 0;
|
||||||
|
D3D12_RESOURCE_BARRIER *rbs = PushStructs(scratch.arena, D3D12_RESOURCE_BARRIER, max_barriers_count);
|
||||||
|
for (TmpBarrier *b = first_barrier; b; b = b->next)
|
||||||
{
|
{
|
||||||
D3D12_RESOURCE_BARRIER *rbs = PushStructs(scratch.arena, D3D12_RESOURCE_BARRIER, barriers_count);
|
GPU_D12_Resource *resource = b->r;
|
||||||
|
D3D12_RESOURCE_BARRIER_TYPE type = resource->barrier_type;
|
||||||
|
D3D12_RESOURCE_STATES state_before = resource->state;
|
||||||
|
D3D12_RESOURCE_STATES state_after = resource->barrier_state_after;
|
||||||
|
if (!(type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION && state_before == state_after))
|
||||||
{
|
{
|
||||||
i32 i = 0;
|
D3D12_RESOURCE_BARRIER *rb = &rbs[barriers_count++];
|
||||||
for (TmpBarrier *b = first_barrier; b; b = b->next)
|
rb->Type = resource->barrier_type;
|
||||||
|
if (rb->Type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION)
|
||||||
{
|
{
|
||||||
D3D12_RESOURCE_BARRIER *rb = &rbs[i];
|
rb->Transition.pResource = resource->d3d_resource;
|
||||||
rb->Type = b->type;
|
rb->Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||||
if (b->type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION)
|
rb->Transition.StateBefore = state_before;
|
||||||
{
|
rb->Transition.StateAfter = state_after;
|
||||||
rb->Transition.pResource = b->r->d3d_resource;
|
resource->state = state_after;
|
||||||
rb->Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
}
|
||||||
rb->Transition.StateBefore = b->r->state;
|
else if (rb->Type == D3D12_RESOURCE_BARRIER_TYPE_UAV)
|
||||||
rb->Transition.StateAfter = b->state;
|
{
|
||||||
b->r->state = rb->Transition.StateAfter;
|
rb->UAV.pResource = resource->d3d_resource;
|
||||||
}
|
|
||||||
else if (b->type == D3D12_RESOURCE_BARRIER_TYPE_UAV)
|
|
||||||
{
|
|
||||||
rb->UAV.pResource = b->r->d3d_resource;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (barriers_count > 0)
|
||||||
|
{
|
||||||
ID3D12GraphicsCommandList_ResourceBarrier(rcl, barriers_count, rbs);
|
ID3D12GraphicsCommandList_ResourceBarrier(rcl, barriers_count, rbs);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -1485,7 +1520,7 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set index buffer */
|
/* Set index buffer */
|
||||||
/*TODO: Only set dirty */
|
/* TODO: Only set dirty */
|
||||||
u32 indices_count = 0;
|
u32 indices_count = 0;
|
||||||
{
|
{
|
||||||
GPU_D12_Resource *indices = cmd->rasterize.index_buffer;
|
GPU_D12_Resource *indices = cmd->rasterize.index_buffer;
|
||||||
|
|||||||
@ -97,6 +97,10 @@ Struct(GPU_D12_Resource)
|
|||||||
GPU_D12_Descriptor *rtv_descriptor;
|
GPU_D12_Descriptor *rtv_descriptor;
|
||||||
GPU_D12_Descriptor *sampler_descriptor;
|
GPU_D12_Descriptor *sampler_descriptor;
|
||||||
|
|
||||||
|
u64 barrier_gen;
|
||||||
|
D3D12_RESOURCE_BARRIER_TYPE barrier_type;
|
||||||
|
D3D12_RESOURCE_STATES barrier_state_after;
|
||||||
|
|
||||||
D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address;
|
D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -259,6 +263,8 @@ Struct(GPU_D12_SharedState)
|
|||||||
{
|
{
|
||||||
GPU_D12_FiberState *fiber_states[MaxFibers];
|
GPU_D12_FiberState *fiber_states[MaxFibers];
|
||||||
|
|
||||||
|
Atomic64Padded resource_barrier_gen;
|
||||||
|
|
||||||
/* Queues */
|
/* Queues */
|
||||||
GPU_D12_Queue *queues[GPU_NumQueues];
|
GPU_D12_Queue *queues[GPU_NumQueues];
|
||||||
|
|
||||||
|
|||||||
@ -407,6 +407,20 @@ JobDef(Step, sig, id)
|
|||||||
{
|
{
|
||||||
String shaders_out_dir = shader_store_name;
|
String shaders_out_dir = shader_store_name;
|
||||||
OS_Mkdir(shaders_out_dir);
|
OS_Mkdir(shaders_out_dir);
|
||||||
|
{
|
||||||
|
/* Remove all old shaders */
|
||||||
|
StringList files = ZI;
|
||||||
|
F_FilesFromDir(arena, &files, shaders_out_dir, F_IterFlag_None);
|
||||||
|
for (StringListNode *n = files.first; n; n = n->next)
|
||||||
|
{
|
||||||
|
String file = n->s;
|
||||||
|
/* Safety check to prevent non-shader files from being removed */
|
||||||
|
if (StringEndsWith(file, Lit("VS")) || StringEndsWith(file, Lit("CS")) || StringEndsWith(file, Lit("PS")))
|
||||||
|
{
|
||||||
|
OS_Rm(n->s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//- Generate GPU file & shader entries
|
//- Generate GPU file & shader entries
|
||||||
String gpu_out_file = F_GetFull(arena, Lit("pp_gen_gpu.gpu"));
|
String gpu_out_file = F_GetFull(arena, Lit("pp_gen_gpu.gpu"));
|
||||||
@ -519,13 +533,14 @@ JobDef(Step, sig, id)
|
|||||||
: Lit("vs_6_6");
|
: Lit("vs_6_6");
|
||||||
String *compile_cmd = &compile_cmds[i];
|
String *compile_cmd = &compile_cmds[i];
|
||||||
*compile_cmd = StringF(arena,
|
*compile_cmd = StringF(arena,
|
||||||
"cmd /c dxc.exe -T %F -E %F -Fo %F/%F %F %F",
|
"cmd /c dxc.exe -T %F -E %F -Fo %F/%F %F %F %F",
|
||||||
FmtString(target),
|
FmtString(target),
|
||||||
FmtString(e->name),
|
FmtString(e->name),
|
||||||
FmtString(shaders_out_dir),
|
FmtString(shaders_out_dir),
|
||||||
FmtString(e->name),
|
FmtString(e->name),
|
||||||
FmtString(gpu_out_file),
|
FmtString(gpu_out_file),
|
||||||
FmtString(StringFromList(arena, cp.defs, Lit(" "))));
|
FmtString(StringFromList(arena, cp.defs, Lit(" "))),
|
||||||
|
FmtString(StringFromList(arena, cp.flags_dxc, Lit(" "))));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,6 @@ b32 OS_FileOrDirExists(String path);
|
|||||||
b32 OS_FileExists(String path);
|
b32 OS_FileExists(String path);
|
||||||
b32 OS_DirExists(String path);
|
b32 OS_DirExists(String path);
|
||||||
void OS_Mkdir(String path);
|
void OS_Mkdir(String path);
|
||||||
void OS_RmDir(String path);
|
|
||||||
void OS_Rm(String path);
|
void OS_Rm(String path);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@ -189,14 +189,6 @@ void OS_Mkdir(String path)
|
|||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_RmDir(String dir)
|
|
||||||
{
|
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
|
||||||
wchar_t *path_wstr = WstrFromString(scratch.arena, dir);
|
|
||||||
RemoveDirectory(path_wstr);
|
|
||||||
EndScratch(scratch);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OS_Rm(String path)
|
void OS_Rm(String path)
|
||||||
{
|
{
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
|
|||||||
@ -398,11 +398,12 @@ JobDef(P_W32_StartWindowMsgProcessing, sig, id)
|
|||||||
/* Win32 limitation: Window must be initialized on same thread that processes events */
|
/* Win32 limitation: Window must be initialized on same thread that processes events */
|
||||||
window->hwnd = P_W32_InitWindow(window);
|
window->hwnd = P_W32_InitWindow(window);
|
||||||
P_W32_UpdateWindowFromSystem(window);
|
P_W32_UpdateWindowFromSystem(window);
|
||||||
BringWindowToTop(window->hwnd);
|
|
||||||
SetFence(&window->ready_fence, 1);
|
SetFence(&window->ready_fence, 1);
|
||||||
|
SetForegroundWindow(window->hwnd);
|
||||||
|
|
||||||
while (!Atomic32Fetch(&window->shutdown))
|
while (!Atomic32Fetch(&window->shutdown))
|
||||||
{
|
{
|
||||||
|
SetFocus(window->hwnd);
|
||||||
MSG msg = ZI;
|
MSG msg = ZI;
|
||||||
{
|
{
|
||||||
GetMessageW(&msg, 0, 0, 0);
|
GetMessageW(&msg, 0, 0, 0);
|
||||||
@ -585,12 +586,11 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
|||||||
P_W32_ProcessWindowEvent(
|
P_W32_ProcessWindowEvent(
|
||||||
window,
|
window,
|
||||||
(P_WindowEvent)
|
(P_WindowEvent)
|
||||||
{
|
{
|
||||||
.kind = event_kind,
|
.kind = event_kind,
|
||||||
.button = button,
|
.button = button,
|
||||||
.is_repeat = is_repeat
|
.is_repeat = is_repeat
|
||||||
}
|
});
|
||||||
);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
/* Text */
|
/* Text */
|
||||||
@ -637,11 +637,10 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
|||||||
P_W32_ProcessWindowEvent(
|
P_W32_ProcessWindowEvent(
|
||||||
window,
|
window,
|
||||||
(P_WindowEvent)
|
(P_WindowEvent)
|
||||||
{
|
{
|
||||||
.kind = P_WindowEventKind_Text,
|
.kind = P_WindowEventKind_Text,
|
||||||
.text_codepoint = codepoint
|
.text_codepoint = codepoint
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,11 +693,10 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
|||||||
P_W32_ProcessWindowEvent(
|
P_W32_ProcessWindowEvent(
|
||||||
window,
|
window,
|
||||||
(P_WindowEvent)
|
(P_WindowEvent)
|
||||||
{
|
{
|
||||||
.kind = event_kind,
|
.kind = event_kind,
|
||||||
.button = button
|
.button = button
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@ -724,11 +722,10 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
|||||||
P_W32_ProcessWindowEvent(
|
P_W32_ProcessWindowEvent(
|
||||||
window,
|
window,
|
||||||
(P_WindowEvent)
|
(P_WindowEvent)
|
||||||
{
|
{
|
||||||
.kind = P_WindowEventKind_CursorMove,
|
.kind = P_WindowEventKind_CursorMove,
|
||||||
.cursor_position = VEC2(x, y)
|
.cursor_position = VEC2(x, y)
|
||||||
}
|
});
|
||||||
);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
/* Raw mouse move */
|
/* Raw mouse move */
|
||||||
@ -756,11 +753,10 @@ LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
|
|||||||
P_W32_ProcessWindowEvent(
|
P_W32_ProcessWindowEvent(
|
||||||
window,
|
window,
|
||||||
(P_WindowEvent)
|
(P_WindowEvent)
|
||||||
{
|
{
|
||||||
.kind = P_WindowEventKind_MouseMove,
|
.kind = P_WindowEventKind_MouseMove,
|
||||||
.mouse_delta = delta
|
.mouse_delta = delta
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
|
|||||||
169
src/pp/pp.c
169
src/pp/pp.c
@ -26,6 +26,20 @@ void StartupUser(void)
|
|||||||
g->user_blended_client = AcquireClient(g->user_client_store);
|
g->user_blended_client = AcquireClient(g->user_client_store);
|
||||||
g->ss_blended = NilSnapshot();
|
g->ss_blended = NilSnapshot();
|
||||||
|
|
||||||
|
/* Sampler */
|
||||||
|
{
|
||||||
|
GPU_ResourceDesc desc = ZI;
|
||||||
|
desc.kind = GPU_ResourceKind_Sampler;
|
||||||
|
desc.sampler.filter = GPU_Filter_MinMagMipPoint;
|
||||||
|
desc.sampler.x = GPU_AddressMode_Clamp;
|
||||||
|
desc.sampler.y = GPU_AddressMode_Clamp;
|
||||||
|
desc.sampler.z = GPU_AddressMode_Clamp;
|
||||||
|
desc.sampler.max_anisotropy = 1;
|
||||||
|
desc.sampler.comparison = GPU_ComparisonFunc_Always;
|
||||||
|
desc.sampler.max_lod = F32Infinity;
|
||||||
|
g->pt_sampler = GPU_AcquireResource(desc);
|
||||||
|
}
|
||||||
|
|
||||||
/* Renderer data arenas */
|
/* Renderer data arenas */
|
||||||
g->material_instances_arena = AcquireArena(Gibi(64));
|
g->material_instances_arena = AcquireArena(Gibi(64));
|
||||||
g->ui_rect_instances_arena = AcquireArena(Gibi(64));
|
g->ui_rect_instances_arena = AcquireArena(Gibi(64));
|
||||||
@ -397,7 +411,6 @@ GPU_Resource *AcquireGbuffer(GPU_Format format, Vec2I32 size)
|
|||||||
desc.flags = GPU_ResourceFlag_Writable | GPU_ResourceFlag_Renderable;
|
desc.flags = GPU_ResourceFlag_Writable | GPU_ResourceFlag_Renderable;
|
||||||
desc.texture.format = format;
|
desc.texture.format = format;
|
||||||
desc.texture.size = VEC3I32(size.x, size.y, 1);
|
desc.texture.size = VEC3I32(size.x, size.y, 1);
|
||||||
desc.texture.mip_levels = 1;
|
|
||||||
return GPU_AcquireResource(desc);
|
return GPU_AcquireResource(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,7 +1015,6 @@ void UpdateUser(P_Window *window)
|
|||||||
//- Draw grid
|
//- Draw grid
|
||||||
|
|
||||||
/* FIXME: Enable this */
|
/* FIXME: Enable this */
|
||||||
#if 0
|
|
||||||
{
|
{
|
||||||
f32 thickness = 2;
|
f32 thickness = 2;
|
||||||
|
|
||||||
@ -1013,10 +1025,23 @@ void UpdateUser(P_Window *window)
|
|||||||
Vec2 size = InvertXformBasisMulV2(g->world_to_render_xf, VEC2(g->render_size.x, g->render_size.y));
|
Vec2 size = InvertXformBasisMulV2(g->world_to_render_xf, VEC2(g->render_size.x, g->render_size.y));
|
||||||
u32 color0 = Rgba32F(0.17f, 0.17f, 0.17f, 1.f);
|
u32 color0 = Rgba32F(0.17f, 0.17f, 0.17f, 1.f);
|
||||||
u32 color1 = Rgba32F(0.15f, 0.15f, 0.15f, 1.f);
|
u32 color1 = Rgba32F(0.15f, 0.15f, 0.15f, 1.f);
|
||||||
D_DrawGrid(g->render_sig, XformFromRect(RectFromVec2(pos, size)), color0, color1, Rgba32(0x3f, 0x3f, 0x3f, 0xFF), ColorRed, ColorGreen, thickness, spacing, offset);
|
|
||||||
|
MaterialGrid *grid = PushStruct(g->grids_arena, MaterialGrid);
|
||||||
|
*grid = DefaultMaterialGrid;
|
||||||
|
grid->line_thickness = thickness;
|
||||||
|
grid->line_spacing = spacing;
|
||||||
|
grid->offset = offset;
|
||||||
|
grid->bg0_srgb = color0;
|
||||||
|
grid->bg1_srgb = color1;
|
||||||
|
grid->line_srgb = Rgba32(0x3f, 0x3f, 0x3f, 0xFF);
|
||||||
|
grid->x_srgb = ColorRed;
|
||||||
|
grid->y_srgb = ColorGreen;
|
||||||
|
|
||||||
|
MaterialInstance *mat = PushStruct(g->material_instances_arena, MaterialInstance);
|
||||||
|
*mat = DefaultMaterialInstance;
|
||||||
|
mat->grid_id = grid - (MaterialGrid *)ArenaBase(g->grids_arena);
|
||||||
|
mat->xf = XformFromRect(RectFromVec2(pos, size));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//- Acquire / release tile cache entries
|
//- Acquire / release tile cache entries
|
||||||
@ -1226,7 +1251,6 @@ void UpdateUser(P_Window *window)
|
|||||||
{
|
{
|
||||||
S_Sheet *sheet = S_SheetFromResourceAsync(sprite);
|
S_Sheet *sheet = S_SheetFromResourceAsync(sprite);
|
||||||
S_Texture *texture = S_TextureFromResourceAsync(sprite);
|
S_Texture *texture = S_TextureFromResourceAsync(sprite);
|
||||||
|
|
||||||
/* TODO: Fade in placeholder if texture isn't loaded */
|
/* TODO: Fade in placeholder if texture isn't loaded */
|
||||||
if (sheet->loaded && texture->loaded)
|
if (sheet->loaded && texture->loaded)
|
||||||
{
|
{
|
||||||
@ -1234,16 +1258,15 @@ void UpdateUser(P_Window *window)
|
|||||||
Vec3 emittance = ent->sprite_emittance;
|
Vec3 emittance = ent->sprite_emittance;
|
||||||
u32 tint = ent->sprite_tint;
|
u32 tint = ent->sprite_tint;
|
||||||
S_Frame frame = S_FrameFromIndex(sheet, ent->animation_frame);
|
S_Frame frame = S_FrameFromIndex(sheet, ent->animation_frame);
|
||||||
/* FIXME: Enable this */
|
MaterialInstance *mat = PushStruct(g->material_instances_arena, MaterialInstance);
|
||||||
#if 0
|
*mat = DefaultMaterialInstance;
|
||||||
D_MaterialParams params = D_MATERIALPARAMS(.xf = sprite_xform, .texture = texture->gpu_resource, .tint = tint, .clip = frame.clip, .is_light = is_light, .light_emittance = emittance);
|
mat->xf = sprite_xform;
|
||||||
D_DrawMaterial(g->render_sig, params);
|
mat->tex_nurid = GPU_GetReadableId(texture->gpu_texture);
|
||||||
#else
|
mat->tint_srgb = tint;
|
||||||
LAX is_light;
|
mat->uv0 = frame.clip.p0;
|
||||||
LAX emittance;
|
mat->uv1 = frame.clip.p1;
|
||||||
LAX tint;
|
mat->is_light = is_light;
|
||||||
LAX frame;
|
mat->light_emittance_srgb = emittance;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1264,22 +1287,19 @@ void UpdateUser(P_Window *window)
|
|||||||
Vec2I32 local_tile_index = VEC2I32(tile_x, tile_y);
|
Vec2I32 local_tile_index = VEC2I32(tile_x, tile_y);
|
||||||
TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
|
TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
|
||||||
/* FIXME: Enable this */
|
/* FIXME: Enable this */
|
||||||
#if 0
|
|
||||||
//if (tile > -1)
|
//if (tile > -1)
|
||||||
if (tile == TileKind_Wall)
|
if (tile == TileKind_Wall)
|
||||||
{
|
{
|
||||||
Vec2I32 world_tile_index = WorldTileIndexFromLocalTileIndex(chunk_index, local_tile_index);
|
Vec2I32 world_tile_index = WorldTileIndexFromLocalTileIndex(chunk_index, local_tile_index);
|
||||||
Vec2 pos = PosFromWorldTileIndex(world_tile_index);
|
Vec2 pos = PosFromWorldTileIndex(world_tile_index);
|
||||||
Xform tile_xf = XformFromRect(RectFromVec2(pos, VEC2(tile_size, tile_size)));
|
Xform tile_xf = XformFromRect(RectFromVec2(pos, VEC2(tile_size, tile_size)));
|
||||||
D_MaterialParams params = D_MATERIALPARAMS(.xf = tile_xf, .texture = tile_texture->gpu_resource, .is_light = 1, .light_emittance = VEC3(0, 0, 0));
|
MaterialInstance *mat = PushStruct(g->material_instances_arena, MaterialInstance);
|
||||||
D_DrawMaterial(g->render_sig, params);
|
*mat = DefaultMaterialInstance;
|
||||||
|
mat->xf = tile_xf;
|
||||||
|
mat->tex_nurid = GPU_GetReadableId(tile_texture->gpu_texture);
|
||||||
|
mat->is_light = 1;
|
||||||
|
mat->light_emittance_srgb = VEC3(0, 0, 0);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
LAX local_tile_index;
|
|
||||||
LAX tile;
|
|
||||||
LAX tile_size;
|
|
||||||
LAX chunk_index;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2172,12 +2192,12 @@ void UpdateUser(P_Window *window)
|
|||||||
if (!g->shade_target)
|
if (!g->shade_target)
|
||||||
{
|
{
|
||||||
__profn("Acquire sig resources");
|
__profn("Acquire sig resources");
|
||||||
g->albedo = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->render_size);
|
g->albedo = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->render_size);
|
||||||
g->emittance = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
|
g->emittance = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
|
||||||
g->emittance_flood_read = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size);
|
g->emittance_flood_read = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size);
|
||||||
g->emittance_flood_target = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size);
|
g->emittance_flood_target = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size);
|
||||||
g->shade_read = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
|
g->shade_read = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
|
||||||
g->shade_target = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
|
g->shade_target = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Acquire ui buffers */
|
/* Acquire ui buffers */
|
||||||
@ -2192,15 +2212,60 @@ void UpdateUser(P_Window *window)
|
|||||||
g->ui_target = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->ui_size);
|
g->ui_target = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->ui_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Upload noise texture */
|
||||||
|
if (!g->noise)
|
||||||
|
{
|
||||||
|
Vec3I32 noise_size = VEC3I32(128, 128, 64);
|
||||||
|
Resource noise_resource = ResourceFromStore(&GameResources, Lit("noise_128x128x64_16.dat"));
|
||||||
|
String noise_res_data = DataFromResource(noise_resource);
|
||||||
|
if (noise_res_data.len != noise_size.x * noise_size.y * noise_size.z * 2)
|
||||||
|
{
|
||||||
|
Panic(Lit("Unexpected noise texture size"));
|
||||||
|
}
|
||||||
|
GPU_ResourceDesc desc = ZI;
|
||||||
|
desc.kind = GPU_ResourceKind_Texture3D;
|
||||||
|
desc.texture.format = GPU_Format_R16_Uint;
|
||||||
|
desc.texture.size = noise_size;
|
||||||
|
GPU_Resource *noise = GPU_AcquireResource(desc);
|
||||||
|
GPU_Resource *upload = 0;
|
||||||
|
{
|
||||||
|
u64 footprint_size = GPU_GetFootprintSize(noise);
|
||||||
|
GPU_ResourceDesc upload_desc = ZI;
|
||||||
|
upload_desc.kind = GPU_ResourceKind_Buffer;
|
||||||
|
upload_desc.buffer.heap_kind = GPU_HeapKind_Upload;
|
||||||
|
upload_desc.buffer.size = footprint_size;
|
||||||
|
upload = GPU_AcquireResource(upload_desc);
|
||||||
|
GPU_Mapped mapped = GPU_Map(upload);
|
||||||
|
GPU_CopyBytesToFootprint(mapped.mem, noise_res_data.text, noise);
|
||||||
|
GPU_Unmap(mapped);
|
||||||
|
}
|
||||||
|
GPU_CommandList *cl = GPU_BeginCommandList(gpu_render_queue);
|
||||||
|
{
|
||||||
|
GPU_TransitionToCopyDst(cl, noise);
|
||||||
|
GPU_CopyResource(cl, noise, upload);
|
||||||
|
GPU_TransitionToReadable(cl, noise);
|
||||||
|
}
|
||||||
|
g->gpu_render_fence_target = GPU_EndCommandList(cl);
|
||||||
|
YieldOnFence(render_fence, g->gpu_render_fence_target);
|
||||||
|
GPU_ReleaseResource(upload, GPU_ReleaseFlag_None);
|
||||||
|
g->noise = noise;
|
||||||
|
}
|
||||||
|
Vec3I32 noise_size = GPU_GetTextureSize3D(g->noise);
|
||||||
|
|
||||||
/* Acquire transfer buffers */
|
/* Acquire transfer buffers */
|
||||||
/* TODO: Make these static */
|
/* TODO: Make quad indices static */
|
||||||
u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
||||||
GPU_Resource *quad_index_buffer = AcquireUploadBuffer(quad_indices, u16, countof(quad_indices));
|
GPU_Resource *quad_index_buffer = AcquireUploadBuffer(quad_indices, u16, countof(quad_indices));
|
||||||
GPU_Resource *material_instance_buffer = AcquireUploadBufferFromArena(g->material_instances_arena, MaterialInstance);
|
GPU_Resource *material_instance_buffer = AcquireUploadBufferFromArena(g->material_instances_arena, MaterialInstance);
|
||||||
GPU_Resource *ui_rect_instance_buffer = AcquireUploadBufferFromArena(g->ui_rect_instances_arena, UiRectInstance);
|
GPU_Resource *ui_rect_instance_buffer = AcquireUploadBufferFromArena(g->ui_rect_instances_arena, UiRectInstance);
|
||||||
GPU_Resource *ui_shape_verts_buffer = AcquireUploadBufferFromArena(g->ui_shape_verts_arena, UiShapeVert);
|
GPU_Resource *ui_shape_verts_buffer = AcquireUploadBufferFromArena(g->ui_shape_verts_arena, UiShapeVert);
|
||||||
GPU_Resource *ui_shape_indices_buffer = AcquireUploadBufferFromArena(g->ui_shape_indices_arena, u32);
|
GPU_Resource *ui_shape_indices_buffer = AcquireUploadBufferFromArena(g->ui_shape_indices_arena, u32);
|
||||||
GPU_Resource *grids_buffer = AcquireUploadBufferFromArena(g->grids_arena, MaterialGrid);
|
GPU_Resource *grids_buffer = AcquireUploadBufferFromArena(g->grids_arena, MaterialGrid);
|
||||||
|
u64 material_instances_count = g->material_instances_arena->pos / sizeof(MaterialInstance);
|
||||||
|
u64 ui_rect_instances_count = g->ui_rect_instances_arena->pos / sizeof(UiRectInstance);
|
||||||
|
u64 ui_shape_verts_count = g->ui_shape_verts_arena->pos / sizeof(UiShapeVert);
|
||||||
|
u64 ui_shape_indices_count = g->ui_shape_indices_arena->pos / sizeof(u32);
|
||||||
|
u64 grids_count = g->grids_arena->pos / sizeof(MaterialGrid);
|
||||||
|
|
||||||
GPU_CommandList *cl = GPU_BeginCommandList(gpu_render_queue);
|
GPU_CommandList *cl = GPU_BeginCommandList(gpu_render_queue);
|
||||||
{
|
{
|
||||||
@ -2235,7 +2300,7 @@ void UpdateUser(P_Window *window)
|
|||||||
GPU_Scissor scissor = GPU_ScissorFromRect(render_viewport);
|
GPU_Scissor scissor = GPU_ScissorFromRect(render_viewport);
|
||||||
|
|
||||||
MaterialSig sig = ZI;
|
MaterialSig sig = ZI;
|
||||||
/* FIXME: set sampler urid id here */
|
sig.tex_sampler_urid = GPU_GetSamplerId(g->pt_sampler);
|
||||||
sig.projection = world_to_render_vp_matrix;
|
sig.projection = world_to_render_vp_matrix;
|
||||||
sig.instances_urid = GPU_GetReadableId(material_instance_buffer);
|
sig.instances_urid = GPU_GetReadableId(material_instance_buffer);
|
||||||
sig.grids_urid = GPU_GetReadableId(grids_buffer);
|
sig.grids_urid = GPU_GetReadableId(grids_buffer);
|
||||||
@ -2245,7 +2310,7 @@ void UpdateUser(P_Window *window)
|
|||||||
2,
|
2,
|
||||||
viewport,
|
viewport,
|
||||||
scissor,
|
scissor,
|
||||||
g->material_instances_count,
|
material_instances_count,
|
||||||
quad_index_buffer,
|
quad_index_buffer,
|
||||||
GPU_RasterizeMode_TriangleList);
|
GPU_RasterizeMode_TriangleList);
|
||||||
}
|
}
|
||||||
@ -2327,7 +2392,7 @@ void UpdateUser(P_Window *window)
|
|||||||
sig.flags = shade_flags;
|
sig.flags = shade_flags;
|
||||||
sig.tex_width = g->render_size.x;
|
sig.tex_width = g->render_size.x;
|
||||||
sig.tex_height = g->render_size.y;
|
sig.tex_height = g->render_size.y;
|
||||||
sig.frame_seed = VEC4I32((u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF),
|
sig.frame_seed = VEC4U32((u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF),
|
||||||
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF),
|
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF),
|
||||||
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF),
|
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF),
|
||||||
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF));
|
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF));
|
||||||
@ -2338,6 +2403,10 @@ void UpdateUser(P_Window *window)
|
|||||||
sig.emittance_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_read);
|
sig.emittance_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_read);
|
||||||
sig.read_tex_urid = GPU_GetWritableId(g->shade_read);
|
sig.read_tex_urid = GPU_GetWritableId(g->shade_read);
|
||||||
sig.target_tex_urid = GPU_GetWritableId(g->shade_target);
|
sig.target_tex_urid = GPU_GetWritableId(g->shade_target);
|
||||||
|
sig.noise_tex_urid = GPU_GetReadableId(g->noise);
|
||||||
|
sig.noise_tex_width = noise_size.x;
|
||||||
|
sig.noise_tex_height = noise_size.y;
|
||||||
|
sig.noise_tex_depth = noise_size.z;
|
||||||
GPU_Compute(cl, &sig, ShadeCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
|
GPU_Compute(cl, &sig, ShadeCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
|
||||||
|
|
||||||
/* Swap */
|
/* Swap */
|
||||||
@ -2364,6 +2433,7 @@ void UpdateUser(P_Window *window)
|
|||||||
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
||||||
|
|
||||||
UiBlitSig sig = ZI;
|
UiBlitSig sig = ZI;
|
||||||
|
sig.tex_sampler_urid = GPU_GetSamplerId(g->pt_sampler);
|
||||||
sig.projection = blit_vp_matrix;
|
sig.projection = blit_vp_matrix;
|
||||||
sig.flags = UiBlitFlag_ToneMap | UiBlitFlag_GammaCorrect;
|
sig.flags = UiBlitFlag_ToneMap | UiBlitFlag_GammaCorrect;
|
||||||
sig.exposure = 2.0;
|
sig.exposure = 2.0;
|
||||||
@ -2389,6 +2459,7 @@ void UpdateUser(P_Window *window)
|
|||||||
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
||||||
|
|
||||||
UiRectSig sig = ZI;
|
UiRectSig sig = ZI;
|
||||||
|
sig.tex_sampler_urid = GPU_GetSamplerId(g->pt_sampler);
|
||||||
sig.projection = ui_vp_matrix;
|
sig.projection = ui_vp_matrix;
|
||||||
sig.instances_urid = GPU_GetReadableId(ui_rect_instance_buffer);
|
sig.instances_urid = GPU_GetReadableId(ui_rect_instance_buffer);
|
||||||
GPU_Rasterize(cl,
|
GPU_Rasterize(cl,
|
||||||
@ -2397,7 +2468,7 @@ void UpdateUser(P_Window *window)
|
|||||||
1,
|
1,
|
||||||
viewport,
|
viewport,
|
||||||
scissor,
|
scissor,
|
||||||
g->ui_rect_instances_count,
|
ui_rect_instances_count,
|
||||||
quad_index_buffer,
|
quad_index_buffer,
|
||||||
GPU_RasterizeMode_TriangleList);
|
GPU_RasterizeMode_TriangleList);
|
||||||
}
|
}
|
||||||
@ -2435,6 +2506,7 @@ void UpdateUser(P_Window *window)
|
|||||||
ui_rect_instance_buffer,
|
ui_rect_instance_buffer,
|
||||||
ui_shape_verts_buffer,
|
ui_shape_verts_buffer,
|
||||||
ui_shape_indices_buffer,
|
ui_shape_indices_buffer,
|
||||||
|
grids_buffer,
|
||||||
};
|
};
|
||||||
Job *job = OpenJob(DelayReleaseGpuResources, JobPool_Inherit);
|
Job *job = OpenJob(DelayReleaseGpuResources, JobPool_Inherit);
|
||||||
{
|
{
|
||||||
@ -2454,21 +2526,8 @@ void UpdateUser(P_Window *window)
|
|||||||
ResetArena(g->ui_shape_verts_arena);
|
ResetArena(g->ui_shape_verts_arena);
|
||||||
ResetArena(g->ui_shape_indices_arena);
|
ResetArena(g->ui_shape_indices_arena);
|
||||||
ResetArena(g->grids_arena);
|
ResetArena(g->grids_arena);
|
||||||
g->material_instances_count = 0;
|
|
||||||
g->ui_rect_instances_count = 0;
|
|
||||||
g->ui_shape_verts_count = 0;
|
|
||||||
g->ui_shape_indices_count = 0;
|
|
||||||
g->grids_count = 0;
|
|
||||||
}
|
}
|
||||||
|
g->gpu_render_fence_target = GPU_PresentSwapchain(g->swapchain, g->ui_target, 0);
|
||||||
#if 1
|
|
||||||
g->gpu_render_fence_target = GPU_PresentSwapchain(g->swapchain, g->ui_target, 1);
|
|
||||||
#else
|
|
||||||
/* TODO: Remove this */
|
|
||||||
Resource test_sprite = ResourceFromStore(&GameResources, Lit("sprite/gun.ase"));
|
|
||||||
S_Texture *test = S_TextureFromResource(test_sprite);
|
|
||||||
g->gpu_render_fence_target = GPU_PresentSwapchain(g->swapchain, test->gpu_texture, 1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
|
|||||||
10
src/pp/pp.h
10
src/pp/pp.h
@ -173,6 +173,9 @@ Struct(SharedUserState)
|
|||||||
SecondsStat net_bytes_sent;
|
SecondsStat net_bytes_sent;
|
||||||
|
|
||||||
//- Gpu resources
|
//- Gpu resources
|
||||||
|
GPU_Resource *pt_sampler;
|
||||||
|
GPU_Resource *noise;
|
||||||
|
|
||||||
GPU_Resource *albedo;
|
GPU_Resource *albedo;
|
||||||
GPU_Resource *emittance;
|
GPU_Resource *emittance;
|
||||||
GPU_Resource *emittance_flood_read;
|
GPU_Resource *emittance_flood_read;
|
||||||
@ -189,13 +192,8 @@ Struct(SharedUserState)
|
|||||||
Arena *ui_shape_verts_arena;
|
Arena *ui_shape_verts_arena;
|
||||||
Arena *ui_shape_indices_arena;
|
Arena *ui_shape_indices_arena;
|
||||||
Arena *grids_arena;
|
Arena *grids_arena;
|
||||||
u32 material_instances_count;
|
|
||||||
u32 ui_rect_instances_count;
|
|
||||||
u32 ui_shape_verts_count;
|
|
||||||
u32 ui_shape_indices_count;
|
|
||||||
u32 grids_count;
|
|
||||||
|
|
||||||
u64 gpu_render_fence_target;
|
i64 gpu_render_fence_target;
|
||||||
|
|
||||||
//- Bind state
|
//- Bind state
|
||||||
BindState bind_states[BindKind_Count];
|
BindState bind_states[BindKind_Count];
|
||||||
|
|||||||
@ -117,6 +117,7 @@ MaterialPS_Output PSDef(MaterialPS, MaterialPS_Input input)
|
|||||||
|
|
||||||
output.SV_Target0 = albedo;
|
output.SV_Target0 = albedo;
|
||||||
output.SV_Target1 = emittance;
|
output.SV_Target1 = emittance;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,12 +198,21 @@ float RandAngle(uint2 pos, u32 ray_index)
|
|||||||
ConstantBuffer<ShadeSig> sig = shade_sig;
|
ConstantBuffer<ShadeSig> sig = shade_sig;
|
||||||
Texture3D<u32> noise_tex = GpuResourceFromUrid(sig.noise_tex_urid);
|
Texture3D<u32> noise_tex = GpuResourceFromUrid(sig.noise_tex_urid);
|
||||||
|
|
||||||
Vec3I32 noise_coord = Vec3I32(1, 1, 1);
|
Vec3U32 noise_coord = Vec3U32(1, 1, 1);
|
||||||
noise_coord += Vec3I32(pos.xy, ray_index);
|
noise_coord += Vec3I32(pos.xy, ray_index);
|
||||||
noise_coord.xyz += sig.frame_seed.xyz;
|
noise_coord.xyz += sig.frame_seed.xyz;
|
||||||
// noise_coord.xy -= sig.camera_offset;
|
// noise_coord.xy -= sig.camera_offset;
|
||||||
|
|
||||||
|
#if 0
|
||||||
u32 noise = noise_tex[noise_coord % uint3(sig.noise_tex_width, sig.noise_tex_height, sig.noise_tex_depth)];
|
u32 noise = noise_tex[noise_coord % uint3(sig.noise_tex_width, sig.noise_tex_height, sig.noise_tex_depth)];
|
||||||
|
#else
|
||||||
|
u32 x = sig.noise_tex_width;
|
||||||
|
u32 y = sig.noise_tex_height;
|
||||||
|
u32 z = sig.noise_tex_depth;
|
||||||
|
noise_coord = noise_coord % Vec3U32(x, y, z);
|
||||||
|
u32 noise = noise_tex[noise_coord];
|
||||||
|
#endif
|
||||||
|
|
||||||
return ((float)noise / (float)0xFFFF) * Tau;
|
return ((float)noise / (float)0xFFFF) * Tau;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +221,6 @@ Vec3 ColorFromDir(uint2 ray_start, Vec2 ray_dir)
|
|||||||
ConstantBuffer<ShadeSig> sig = shade_sig;
|
ConstantBuffer<ShadeSig> sig = shade_sig;
|
||||||
Texture2D<uint2> flood_tex = GpuResourceFromUrid(sig.emittance_flood_tex_urid);
|
Texture2D<uint2> flood_tex = GpuResourceFromUrid(sig.emittance_flood_tex_urid);
|
||||||
Texture2D<Vec4> emittance_tex = GpuResourceFromUrid(sig.emittance_tex_urid);
|
Texture2D<Vec4> emittance_tex = GpuResourceFromUrid(sig.emittance_tex_urid);
|
||||||
Texture3D<u32> noise_tex = GpuResourceFromUrid(sig.noise_tex_urid);
|
|
||||||
|
|
||||||
Vec3 result = Vec3(0, 0, 0);
|
Vec3 result = Vec3(0, 0, 0);
|
||||||
Vec2 at_float = ray_start;
|
Vec2 at_float = ray_start;
|
||||||
@ -289,7 +298,6 @@ void CSDef(ShadeCS, Semantic(uint3, SV_DispatchThreadID))
|
|||||||
// hysterisis = 0.5;
|
// hysterisis = 0.5;
|
||||||
// hysterisis = 0.9;
|
// hysterisis = 0.9;
|
||||||
color.rgb = lerp(color.rgb, read_tex[id].rgb, hysterisis);
|
color.rgb = lerp(color.rgb, read_tex[id].rgb, hysterisis);
|
||||||
|
|
||||||
target_tex[id] = color;
|
target_tex[id] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,13 +369,7 @@ UiBlitPS_Output PSDef(UiBlitPS, UiBlitPS_Input input)
|
|||||||
color = pow(abs(color), 1/sig.gamma);
|
color = pow(abs(color), 1/sig.gamma);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Enable this */
|
|
||||||
#if 0
|
|
||||||
output.SV_Target = color;
|
output.SV_Target = color;
|
||||||
#else
|
|
||||||
output.SV_Target = Vec4(1, 0, 0, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,13 @@ Struct(MaterialInstance)
|
|||||||
u32 is_light;
|
u32 is_light;
|
||||||
Vec3 light_emittance_srgb;
|
Vec3 light_emittance_srgb;
|
||||||
};
|
};
|
||||||
|
#define DefaultMaterialInstance (MaterialInstance) { \
|
||||||
|
.tex_nurid = U32Max, \
|
||||||
|
.grid_id = U32Max, \
|
||||||
|
.xf = XformIdentity, \
|
||||||
|
.uv1 = VEC2(1, 1), \
|
||||||
|
.tint_srgb = ColorWhite, \
|
||||||
|
}
|
||||||
|
|
||||||
Struct(MaterialGrid)
|
Struct(MaterialGrid)
|
||||||
{
|
{
|
||||||
@ -37,6 +44,12 @@ Struct(MaterialGrid)
|
|||||||
u32 x_srgb;
|
u32 x_srgb;
|
||||||
u32 y_srgb;
|
u32 y_srgb;
|
||||||
};
|
};
|
||||||
|
#define DefaultMaterialGrid (MaterialGrid) { \
|
||||||
|
.line_thickness = 1, \
|
||||||
|
.line_spacing = 1, \
|
||||||
|
.bg0_srgb = ColorBlack, \
|
||||||
|
.bg0_srgb = ColorWhite \
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Flood types
|
//~ Flood types
|
||||||
@ -66,7 +79,7 @@ AssertRootConst(FloodSig, 8);
|
|||||||
Struct(ShadeSig)
|
Struct(ShadeSig)
|
||||||
{
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
Vec4I32 frame_seed; /* 04 consts */
|
Vec4U32 frame_seed; /* 04 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
u32 flags; /* 01 consts */
|
u32 flags; /* 01 consts */
|
||||||
u32 _pad0; /* 01 consts (padding) */
|
u32 _pad0; /* 01 consts (padding) */
|
||||||
@ -135,7 +148,6 @@ AssertRootConst(UiRectSig, 20);
|
|||||||
Struct(UiRectInstance)
|
Struct(UiRectInstance)
|
||||||
{
|
{
|
||||||
u32 tex_nurid;
|
u32 tex_nurid;
|
||||||
u32 grid_id;
|
|
||||||
Xform xf;
|
Xform xf;
|
||||||
Vec2 uv0;
|
Vec2 uv0;
|
||||||
Vec2 uv1;
|
Vec2 uv1;
|
||||||
|
|||||||
@ -25,12 +25,8 @@ JobDef(S_LoadTexture, sig, _)
|
|||||||
GPU_ResourceDesc desc = ZI;
|
GPU_ResourceDesc desc = ZI;
|
||||||
desc.kind = GPU_ResourceKind_Texture2D;
|
desc.kind = GPU_ResourceKind_Texture2D;
|
||||||
desc.flags = GPU_ResourceFlag_None;
|
desc.flags = GPU_ResourceFlag_None;
|
||||||
|
|
||||||
/* FIXME: Use srgb format */
|
|
||||||
desc.texture.format = GPU_Format_R8G8B8A8_Unorm_Srgb;
|
desc.texture.format = GPU_Format_R8G8B8A8_Unorm_Srgb;
|
||||||
|
|
||||||
desc.texture.size = VEC3I32(decoded.width, decoded.height, 1);
|
desc.texture.size = VEC3I32(decoded.width, decoded.height, 1);
|
||||||
desc.texture.mip_levels = 1;
|
|
||||||
texture->gpu_texture = GPU_AcquireResource(desc);
|
texture->gpu_texture = GPU_AcquireResource(desc);
|
||||||
texture->width = decoded.width;
|
texture->width = decoded.width;
|
||||||
texture->height = decoded.height;
|
texture->height = decoded.height;
|
||||||
@ -130,10 +126,8 @@ JobDef(S_LoadSheet, sig, _)
|
|||||||
S_Frame *dst = &sheet->frames[src->index];
|
S_Frame *dst = &sheet->frames[src->index];
|
||||||
dst->index = src->index;
|
dst->index = src->index;
|
||||||
dst->duration = src->duration;
|
dst->duration = src->duration;
|
||||||
dst->clip.p0.x = src->x1;
|
dst->clip.p0 = VEC2((f32)src->x1 / (f32)image_size.x, (f32)src->y1 / (f32)image_size.y);
|
||||||
dst->clip.p0.y = src->y1;
|
dst->clip.p1 = VEC2((f32)src->x2 / (f32)image_size.x, (f32)src->y2 / (f32)image_size.y);
|
||||||
dst->clip.p1.x = src->x2;
|
|
||||||
dst->clip.p1.y = src->y2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init spans */
|
/* Init spans */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user