From 1d01df1a7cae40a4de64757f951fa772830d6167 Mon Sep 17 00:00:00 2001 From: AllMeatball <181806857+AllMeatball@users.noreply.github.com> Date: Sun, 25 May 2025 15:35:44 -0500 Subject: [PATCH] Rebase with anders' camera code --- .../shaders/generated/PositionColor.vert.h | 18 +++++++++--------- .../sdl3gpu/shaders/generated/ShaderIndex.cpp | 6 +++--- .../shaders/src/PositionColor.vert.hlsl | 5 +++++ .../shaders/src/PositionColor.vert.hlsl.json | 2 +- miniwin/sdl3gpu/src/miniwin_d3drmviewport.cpp | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/miniwin/sdl3gpu/shaders/generated/PositionColor.vert.h b/miniwin/sdl3gpu/shaders/generated/PositionColor.vert.h index c80a1874..e92ee1e7 100644 --- a/miniwin/sdl3gpu/shaders/generated/PositionColor.vert.h +++ b/miniwin/sdl3gpu/shaders/generated/PositionColor.vert.h @@ -268,24 +268,24 @@ static const Uint8 PositionColor_vert_spirv[624] = { 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0xf8, 0x00, 0x02, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0xf8, 0x00, 0x02, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, diff --git a/miniwin/sdl3gpu/shaders/generated/ShaderIndex.cpp b/miniwin/sdl3gpu/shaders/generated/ShaderIndex.cpp index e03eb204..5baa0407 100644 --- a/miniwin/sdl3gpu/shaders/generated/ShaderIndex.cpp +++ b/miniwin/sdl3gpu/shaders/generated/ShaderIndex.cpp @@ -21,7 +21,7 @@ static const SDL_GPUShaderCreateInfo VertexShaderDXILCodes[] = { /* num_samplers */ 0, /* num_storage_textures */ 0, /* num_storage_buffers */ 0, - /* num_uniform_buffers */ 0, + /* num_uniform_buffers */ 1, }, }; #endif @@ -37,7 +37,7 @@ static const SDL_GPUShaderCreateInfo VertexShaderMSLCodes[] = { /* num_samplers */ 0, /* num_storage_textures */ 0, /* num_storage_buffers */ 0, - /* num_uniform_buffers */ 0, + /* num_uniform_buffers */ 1, }, }; #endif @@ -52,7 +52,7 @@ static const SDL_GPUShaderCreateInfo VertexShaderSPIRVCodes[] = { /* num_samplers */ 0, /* num_storage_textures */ 0, /* num_storage_buffers */ 0, - /* num_uniform_buffers */ 0, + /* num_uniform_buffers */ 1, }, }; diff --git a/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl b/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl index 8b106f16..14a0c2df 100644 --- a/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl +++ b/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl @@ -10,6 +10,11 @@ struct Output float4 Position : SV_Position; }; +cbuffer ViewportUniforms : register(b0, space1) +{ + float4x4 projection; +}; + Output main(Input input) { Output output; diff --git a/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl.json b/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl.json index 0560c97d..7b6b17cc 100644 --- a/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl.json +++ b/miniwin/sdl3gpu/shaders/src/PositionColor.vert.hlsl.json @@ -2,5 +2,5 @@ "num_samplers": 0, "num_storage_textures": 0, "num_storage_buffers": 0, - "num_uniform_buffers": 0 + "num_uniform_buffers": 1 } diff --git a/miniwin/sdl3gpu/src/miniwin_d3drmviewport.cpp b/miniwin/sdl3gpu/src/miniwin_d3drmviewport.cpp index bd842b98..39dcd00a 100644 --- a/miniwin/sdl3gpu/src/miniwin_d3drmviewport.cpp +++ b/miniwin/sdl3gpu/src/miniwin_d3drmviewport.cpp @@ -82,6 +82,10 @@ void ComputeFrameWorldMatrix(IDirect3DRMFrame* frame, D3DRMMATRIX4D out) memcpy(out, acc, sizeof(acc)); } +typedef struct { + D3DRMMATRIX4D projection; +} ViewportUniforms; + HRESULT Direct3DRMViewport_SDL3GPUImpl::CollectSceneData(IDirect3DRMFrame* group) { MINIWIN_NOT_IMPLEMENTED(); // Lights, camera, textures, materials @@ -264,6 +268,17 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::Render(IDirect3DRMFrame* group) SDL_GPURenderPass* renderPass = SDL_BeginGPURenderPass(cmdbuf, &colorTargetInfo, 1, NULL); SDL_BindGPUGraphicsPipeline(renderPass, m_pipeline); + ViewportUniforms viewportUniforms = {0}; + D3DRMMATRIX4D matrix = { + {1.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 0.f}, + {0.f, 0.f, 1.f, 0.f}, + {0.f, 0.f, 0.f, 1.f} + }; + + memcpy(viewportUniforms.projection, matrix, sizeof(viewportUniforms.projection)); + SDL_PushGPUVertexUniformData(cmdbuf, 0, &viewportUniforms, sizeof(viewportUniforms)); + if (m_vertexCount) { SDL_GPUBufferBinding vertexBufferBinding = {}; vertexBufferBinding.buffer = m_vertexBuffer;