brought back functionality from previous builds but now cross-platform
This commit is contained in:
@@ -2,21 +2,32 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "runner.h"
|
||||
#include "target.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
void build_shader( const char *szName )
|
||||
{
|
||||
IFileSystem2::MakeDirectory(CUtlString("build/funnygame/assets/gfx"));
|
||||
IFileSystem2::MakeDirectory(CUtlString("build/funnygame/metal/gfx"));
|
||||
IFileSystem2::MakeDirectory(CUtlString("build/funnygame/vulkan/gfx"));
|
||||
|
||||
CUtlVector<CUtlString> slang_args = {
|
||||
CUtlString("funnyassets/gfx_shaders/%s.slang", szName),
|
||||
"-g",
|
||||
"-target",
|
||||
"spirv",
|
||||
"-D",
|
||||
"__SPIRV__=1",
|
||||
"-o",
|
||||
CUtlString("build/funnygame/assets/gfx/%s.spv", szName),
|
||||
CUtlString("build/funnygame/vulkan/gfx/%s.shader", szName),
|
||||
};
|
||||
|
||||
IRunner::Run("slangc", slang_args);
|
||||
|
||||
slang_args[3] = "metal";
|
||||
slang_args[5] = "__METAL__=1";
|
||||
slang_args[7] = CUtlString("build/funnygame/metal/gfx/%s.shader", szName);
|
||||
IRunner::Run("slangc", slang_args);
|
||||
IRunner::Wait();
|
||||
};
|
||||
|
||||
int assets_build()
|
||||
@@ -29,17 +40,34 @@ int assets_build()
|
||||
IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/materials");
|
||||
build_shader("mesh_frag");
|
||||
build_shader("mesh_vert");
|
||||
build_shader("agx_comp");
|
||||
build_shader("mesh_edge_detection_comp");
|
||||
CUtlVector<CUtlString> python_args = {
|
||||
"build/tools/makepak64.py",
|
||||
CUtlString("build/funnygame/assets"),
|
||||
bStaticBuild ? CUtlString("%s/bin/%s.pak", szOutputDir.GetString(), "rtt") : CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "rtt"),
|
||||
};
|
||||
V_printf("%s\n",
|
||||
bStaticBuild ? CUtlString("%s/bin/%s.pak", szOutputDir.GetString(), "rtt").GetString() : CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "rtt").GetString()
|
||||
);
|
||||
IRunner::Run("python3", python_args);
|
||||
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS ||Target_t::DefaultTarget().kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
python_args = {
|
||||
"build/tools/makepak64.py",
|
||||
CUtlString("build/funnygame/metal"),
|
||||
bStaticBuild ? CUtlString("%s/bin/%s.pak", szOutputDir.GetString(), "metal") : CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "metal"),
|
||||
};
|
||||
IRunner::Run("python3", python_args);
|
||||
} else {
|
||||
python_args = {
|
||||
"build/tools/makepak64.py",
|
||||
CUtlString("build/funnygame/vulkan"),
|
||||
bStaticBuild ? CUtlString("%s/bin/%s.pak", szOutputDir.GetString(), "vulkan") : CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "vulkan"),
|
||||
};
|
||||
IRunner::Run("python3", python_args);
|
||||
}
|
||||
IRunner::Wait();
|
||||
|
||||
if (bStaticBuild)
|
||||
IFileSystem2::CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), "funnyassets/default.cfg");
|
||||
else
|
||||
IFileSystem2::CopyFile(szOutputDir.GetString(), "funnyassets/default.cfg");
|
||||
return 0;
|
||||
};
|
||||
DECLARE_BUILD_STAGE(assets, assets_build);
|
||||
|
||||
5
funnyassets/default.cfg
Normal file
5
funnyassets/default.cfg
Normal file
@@ -0,0 +1,5 @@
|
||||
bind esc exit;
|
||||
bind a +left;
|
||||
bind d +right;
|
||||
bind w +forward;
|
||||
bind s +back;
|
||||
34
funnyassets/gfx/ml_quad.metal
Normal file
34
funnyassets/gfx/ml_quad.metal
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct VertexOut {
|
||||
float4 position [[position]];
|
||||
float2 texCoord;
|
||||
};
|
||||
|
||||
vertex VertexOut vertex_main(uint vertexID [[vertex_id]]) {
|
||||
float2 pos[] = {
|
||||
{-1.0, -1.0},
|
||||
{ 1.0, -1.0},
|
||||
{-1.0, 1.0},
|
||||
{ 1.0, 1.0},
|
||||
};
|
||||
|
||||
float2 uv[] = {
|
||||
{0.0, 1.0},
|
||||
{1.0, 1.0},
|
||||
{0.0, 0.0},
|
||||
{1.0, 0.0},
|
||||
};
|
||||
|
||||
VertexOut out;
|
||||
out.position = float4(pos[vertexID], 0.0, 1.0);
|
||||
out.texCoord = uv[vertexID];
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 fragment_main(VertexOut in [[stage_in]],
|
||||
texture2d<float> tex [[texture(0)]]) {
|
||||
constexpr sampler s(filter::linear);
|
||||
return pow(tex.sample(s, in.texCoord), 0.45f);
|
||||
}
|
||||
1
funnyassets/gfx_shaders/mesh_bindings.h
Normal file
1
funnyassets/gfx_shaders/mesh_bindings.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "shader_base.h"
|
||||
@@ -1,23 +1,12 @@
|
||||
#include "mesh_shared.slang"
|
||||
|
||||
uint32_t hash32(uint32_t x) {
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
x = (x >> 16) ^ x;
|
||||
return x;
|
||||
}
|
||||
|
||||
[[vk::binding(1)]]
|
||||
uniform Sampler2D textures[];
|
||||
|
||||
[shader("fragment")]
|
||||
float4 main(
|
||||
float4 _main(
|
||||
VertexOutput input,
|
||||
uint triid: SV_PrimitiveID,
|
||||
uniform PushConstants constants,
|
||||
) : SV_TARGET
|
||||
{
|
||||
return float4(textures[constants.albedoID].Sample(input.uv).xyz, 1);
|
||||
|
||||
return float4(SampleTexture(albedoID, input.uv).xyz,1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "shader_base.h"
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
@@ -6,10 +7,17 @@ struct VertexOutput
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PushConstants
|
||||
DECLARE_CONSTANTS()
|
||||
{
|
||||
float4x4 modelMatrix;
|
||||
uint albedoID;
|
||||
uint roughnessID;
|
||||
uint metalnessID;
|
||||
};
|
||||
|
||||
DECLARE_CBUFFER(0)
|
||||
{
|
||||
float4x4 projection;
|
||||
};
|
||||
|
||||
DECLARE_TEXTURES(1)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "shader_base.h"
|
||||
#include "mesh_shared.slang"
|
||||
|
||||
struct VertexInput
|
||||
@@ -6,20 +7,13 @@ struct VertexInput
|
||||
float2 uv: TEXCOORD0;
|
||||
};
|
||||
|
||||
[[vk::binding(0)]]
|
||||
cbuffer CameraInfo
|
||||
{
|
||||
float4x4 projection;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexOutput main(
|
||||
VertexOutput _main(
|
||||
VertexInput input,
|
||||
uniform PushConstants constants,
|
||||
)
|
||||
{
|
||||
VertexOutput output;
|
||||
output.position = mul(projection, mul(constants.modelMatrix, float4(input.position,1)));
|
||||
output.position = mul(projection, mul(modelMatrix, float4(input.position,1)));
|
||||
output.uv = input.uv;
|
||||
return output;
|
||||
}
|
||||
|
||||
85
funnyassets/gfx_shaders/shader_base.h
Normal file
85
funnyassets/gfx_shaders/shader_base.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#ifndef SHADER_BASE_SLANG
|
||||
#define SHADER_BASE_SLANG
|
||||
|
||||
/*
|
||||
* I hope you are not looking at these war crimes.
|
||||
* They are truly horrible crimes.
|
||||
* Don't even try to understand what the fuck is happening here.
|
||||
*/
|
||||
|
||||
#if defined(__METAL__)
|
||||
/* We hijack all the argument buffers, which allows to use a bit more textures at cost of buffers */
|
||||
#define DECLARE_TEXTURES(b) \
|
||||
struct TextureBinding {Texture2D textures[96];}; \
|
||||
[[vk::binding(21)]] ParameterBlock<TextureBinding> g_textures0 : register(t21); \
|
||||
ParameterBlock<TextureBinding> g_textures1 : register(t22); \
|
||||
ParameterBlock<TextureBinding> g_textures2 : register(t23); \
|
||||
ParameterBlock<TextureBinding> g_textures3 : register(t24); \
|
||||
ParameterBlock<TextureBinding> g_textures4 : register(t25); \
|
||||
ParameterBlock<TextureBinding> g_textures5 : register(t26); \
|
||||
ParameterBlock<TextureBinding> g_textures6 : register(t27); \
|
||||
ParameterBlock<TextureBinding> g_textures7 : register(t28);
|
||||
|
||||
void _mlGetSampler()
|
||||
{
|
||||
__intrinsic_asm R"(
|
||||
constexpr sampler s(filter::linear, address::repeat);
|
||||
return s;
|
||||
)";
|
||||
}
|
||||
SamplerState mlGetSampler()
|
||||
{
|
||||
_mlGetSampler();
|
||||
};
|
||||
|
||||
float4 SampleTexture(uint32_t binding, float2 uv)
|
||||
{
|
||||
SamplerState sampler = mlGetSampler();
|
||||
uint8_t textureArray = 0;
|
||||
uint8_t textureSamplerArray = (binding >> 16) & 0xFF;
|
||||
uint8_t textureSampler = (binding >> 8) & 0xFF;
|
||||
uint8_t textureIndex = 1;
|
||||
return g_textures0.textures[1].Sample(sampler, uv);
|
||||
};
|
||||
|
||||
#define DECLARE_CBUFFER(b) \
|
||||
[[vk::binding(b)]] cbuffer cbuffer_##b : register(t##b)
|
||||
|
||||
#define DECLARE_CONSTANTS() \
|
||||
[[vk::push_constant]] \
|
||||
cbuffer cbuffer_constants : register(t29)
|
||||
|
||||
|
||||
#elif defined(__SPIRV__)
|
||||
|
||||
#define DECLARE_TEXTURES(b) \
|
||||
[[vk::binding(b)]] \
|
||||
Sampler2D g_textures[];
|
||||
|
||||
float4 SampleTexture(uint32_t binding, float2 uv)
|
||||
{
|
||||
return g_textures[binding].Sample(uv);
|
||||
};
|
||||
|
||||
#define DECLARE_CBUFFER(b) \
|
||||
[[vk::binding(b)]] \
|
||||
cbuffer cbuffer_##b
|
||||
|
||||
|
||||
#define DECLARE_DATA(b,r) \
|
||||
[[vk::binding(b)]] \
|
||||
r
|
||||
|
||||
#define DECLARE_CONSTANTS() \
|
||||
[[vk::push_constant]] \
|
||||
cbuffer cbuffer_constants
|
||||
|
||||
#else
|
||||
#define DECLARE_TEXTURES()
|
||||
float4 SampleTexture(uint32_t binding, float2 uv);
|
||||
#define DECLARE_CBUFFER() cbuffer cbuffer_constats
|
||||
#define DECLARE_DATA() cbuffer cbuffer_constats
|
||||
#define DECLARE_CONSTANTS() cbuffer cbuffer_constats
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user