Skip to content

Commit b4b31bd

Browse files
authored
Multiple dx11 fixes (#1213)
* This is an awful workflow. Probably still need to update dx11 program ver * Yea, going to despise this workflow * Whoops * Weewoo * Fix comp error * Bump dx11 ver due to it having an extremely limited number of inputs
1 parent 37f4b2e commit b4b31bd

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/pc/gfx/gfx_direct3d11.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ struct ShaderProgramD3D11 {
7777
static struct {
7878
HMODULE d3d11_module;
7979
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice;
80-
80+
8181
HMODULE d3dcompiler_module;
8282
pD3DCompile D3DCompile;
83-
83+
8484
D3D_FEATURE_LEVEL feature_level;
85-
85+
8686
ComPtr<ID3D11Device> device;
8787
ComPtr<IDXGISwapChain1> swap_chain;
8888
ComPtr<ID3D11DeviceContext> context;
@@ -272,7 +272,7 @@ static void gfx_d3d11_init(void) {
272272
ZeroMemory(&vertex_buffer_desc, sizeof(D3D11_BUFFER_DESC));
273273

274274
vertex_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
275-
vertex_buffer_desc.ByteWidth = 256 * 26 * 3 * sizeof(float); // Same as buf_vbo size in gfx_pc
275+
vertex_buffer_desc.ByteWidth = 256 * 28 * 3 * sizeof(float); // Same as buf_vbo size in gfx_pc
276276
vertex_buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
277277
vertex_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
278278
vertex_buffer_desc.MiscFlags = 0;
@@ -342,14 +342,14 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(struct ColorCo
342342
UINT compile_flags = D3DCOMPILE_OPTIMIZATION_LEVEL2;
343343
#endif
344344

345-
HRESULT hr = d3d.D3DCompile(buf, len, nullptr, nullptr, nullptr, "VSMain", "vs_4_0_level_9_1", compile_flags, 0, vs.GetAddressOf(), error_blob.GetAddressOf());
345+
HRESULT hr = d3d.D3DCompile(buf, len, nullptr, nullptr, nullptr, "VSMain", "vs_4_0", compile_flags, 0, vs.GetAddressOf(), error_blob.GetAddressOf());
346346

347347
if (FAILED(hr)) {
348348
MessageBox(gfx_dxgi_get_h_wnd(), (char *) error_blob->GetBufferPointer(), "Error", MB_OK | MB_ICONERROR);
349349
throw hr;
350350
}
351351

352-
hr = d3d.D3DCompile(buf, len, nullptr, nullptr, nullptr, "PSMain", "ps_4_0_level_9_1", compile_flags, 0, ps.GetAddressOf(), error_blob.GetAddressOf());
352+
hr = d3d.D3DCompile(buf, len, nullptr, nullptr, nullptr, "PSMain", "ps_4_0", compile_flags, 0, ps.GetAddressOf(), error_blob.GetAddressOf());
353353

354354
if (FAILED(hr)) {
355355
MessageBox(gfx_dxgi_get_h_wnd(), (char *) error_blob->GetBufferPointer(), "Error", MB_OK | MB_ICONERROR);
@@ -365,11 +365,13 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(struct ColorCo
365365

366366
// Input Layout
367367

368-
D3D11_INPUT_ELEMENT_DESC ied[7];
368+
D3D11_INPUT_ELEMENT_DESC ied[16];
369369
uint8_t ied_index = 0;
370370
ied[ied_index++] = { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
371-
if (cc_features.used_textures[0] || cc_features.used_textures[1]) {
372-
ied[ied_index++] = { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
371+
for (unsigned int t = 0; t < 2; t++) {
372+
if (cc_features.used_textures[t]) {
373+
ied[ied_index++] = { "TEXCOORD", t, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
374+
}
373375
}
374376
if (cc->cm.use_fog) {
375377
ied[ied_index++] = { "FOG", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };

src/pc/gfx/gfx_direct3d_common.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
146146

147147
append_line(buf, &len, "struct PSInput {");
148148
append_line(buf, &len, " float4 position : SV_POSITION;");
149-
if (ccf.used_textures[0] || ccf.used_textures[1]) {
150-
append_line(buf, &len, " float2 uv : TEXCOORD;");
151-
num_floats += 2;
149+
for (int t = 0; t < 2; t++) {
150+
if (ccf.used_textures[t]) {
151+
len += sprintf(buf + len, " float2 uv%d : TEXCOORD%d;", t, t);
152+
num_floats += 2;
153+
}
152154
}
153155
if ((cc.cm.use_alpha && cc.cm.use_dither) || ccf.do_noise) {
154156
append_line(buf, &len, " float4 screenPos : TEXCOORD1;");
@@ -218,8 +220,10 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
218220
// Vertex shader
219221

220222
append_str(buf, &len, "PSInput VSMain(float4 position : POSITION");
221-
if (ccf.used_textures[0] || ccf.used_textures[1]) {
222-
append_str(buf, &len, ", float2 uv : TEXCOORD");
223+
for (int t = 0; t < 2; t++) {
224+
if (ccf.used_textures[t]) {
225+
len += sprintf(buf + len, ", float2 uv%d : TEXCOORD%d", t, t);
226+
}
223227
}
224228
if (cc.cm.use_fog) {
225229
append_str(buf, &len, ", float4 fog : FOG");
@@ -236,8 +240,10 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
236240
if ((cc.cm.use_alpha && cc.cm.use_dither) || ccf.do_noise) {
237241
append_line(buf, &len, " result.screenPos = position;");
238242
}
239-
if (ccf.used_textures[0] || ccf.used_textures[1]) {
240-
append_line(buf, &len, " result.uv = uv;");
243+
for (int t = 0; t < 2; t++) {
244+
if (ccf.used_textures[t]) {
245+
len += sprintf(buf + len, " result.uv%d = uv%d;", t, t);
246+
}
241247
}
242248
if (cc.cm.use_fog) {
243249
append_line(buf, &len, " result.fog = fog;");
@@ -266,11 +272,11 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
266272
if (three_point_filtering) {
267273
append_line(buf, &len, " float4 texVal0;");
268274
append_line(buf, &len, " if (textures[0].linear_filtering)");
269-
append_line(buf, &len, " texVal0 = tex2D3PointFilter(g_texture0, g_sampler0, input.uv, float2(textures[0].width, textures[0].height));");
275+
append_line(buf, &len, " texVal0 = tex2D3PointFilter(g_texture0, g_sampler0, input.uv0, float2(textures[0].width, textures[0].height));");
270276
append_line(buf, &len, " else");
271-
append_line(buf, &len, " texVal0 = g_texture0.Sample(g_sampler0, input.uv);");
277+
append_line(buf, &len, " texVal0 = g_texture0.Sample(g_sampler0, input.uv0);");
272278
} else {
273-
append_line(buf, &len, " float4 texVal0 = g_texture0.Sample(g_sampler0, input.uv);");
279+
append_line(buf, &len, " float4 texVal0 = g_texture0.Sample(g_sampler0, input.uv0);");
274280
}
275281
}
276282
if (ccf.used_textures[1]) {
@@ -289,11 +295,11 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
289295
if (three_point_filtering) {
290296
append_line(buf, &len, " float4 texVal1;");
291297
append_line(buf, &len, " if (textures[1].linear_filtering)");
292-
append_line(buf, &len, " texVal1 = tex2D3PointFilter(g_texture1, g_sampler1, input.uv, float2(textures[1].width, textures[1].height));");
298+
append_line(buf, &len, " texVal1 = tex2D3PointFilter(g_texture1, g_sampler1, input.uv1, float2(textures[1].width, textures[1].height));");
293299
append_line(buf, &len, " else");
294-
append_line(buf, &len, " texVal1 = g_texture1.Sample(g_sampler1, input.uv);");
300+
append_line(buf, &len, " texVal1 = g_texture1.Sample(g_sampler1, input.uv1);");
295301
} else {
296-
append_line(buf, &len, " float4 texVal1 = g_texture1.Sample(g_sampler1, input.uv);");
302+
append_line(buf, &len, " float4 texVal1 = g_texture1.Sample(g_sampler1, input.uv1);");
297303
}
298304
}
299305
}

0 commit comments

Comments
 (0)