浏览代码

sokol_debugtext.h: add D3D11 shaders and MSVC fixes

Andre Weissflog 5 年之前
父节点
当前提交
bf0152db85
共有 1 个文件被更改,包括 119 次插入14 次删除
  1. 119 14
      util/sokol_debugtext.h

+ 119 - 14
util/sokol_debugtext.h

@@ -260,6 +260,9 @@ SOKOL_API_DECL int sdtx_printf(const char* fmt, ...) SOKOL_DEBUGTEXT_PRINTF_ATTR
 #ifndef SOKOL_UNREACHABLE
 #ifndef SOKOL_UNREACHABLE
     #define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
     #define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
 #endif
 #endif
+#ifndef _SOKOL_UNUSED
+    #define _SOKOL_UNUSED(x) (void)(x)
+#endif
 
 
 #ifndef SOKOL_SNPRINTF
 #ifndef SOKOL_SNPRINTF
 #define SOKOL_SNPRINTF snprintf
 #define SOKOL_SNPRINTF snprintf
@@ -2767,8 +2770,102 @@ static const char _sdtx_fs_src_metal_sim[475] = {
     0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
     0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
 };
 };
 #elif defined(SOKOL_D3D11)
 #elif defined(SOKOL_D3D11)
-static const char* _sdtx_vs_src = "FIXME!";
-static const char* _sdtx_fs_src = "FIXME!";
+static const uint8_t _sdtx_vs_bytecode_d3d11[760] = {
+    0x44,0x58,0x42,0x43,0x7f,0xd0,0x1e,0x5d,0x42,0x4e,0xb0,0xd4,0x54,0x92,0xcf,0x65,
+    0x76,0x7b,0x1c,0x75,0x01,0x00,0x00,0x00,0xf8,0x02,0x00,0x00,0x05,0x00,0x00,0x00,
+    0x34,0x00,0x00,0x00,0xa0,0x00,0x00,0x00,0x04,0x01,0x00,0x00,0x74,0x01,0x00,0x00,
+    0x5c,0x02,0x00,0x00,0x52,0x44,0x45,0x46,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x05,0xfe,0xff,
+    0x10,0x81,0x00,0x00,0x3c,0x00,0x00,0x00,0x52,0x44,0x31,0x31,0x3c,0x00,0x00,0x00,
+    0x18,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x24,0x00,0x00,0x00,
+    0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4d,0x69,0x63,0x72,0x6f,0x73,0x6f,0x66,
+    0x74,0x20,0x28,0x52,0x29,0x20,0x48,0x4c,0x53,0x4c,0x20,0x53,0x68,0x61,0x64,0x65,
+    0x72,0x20,0x43,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x72,0x20,0x31,0x30,0x2e,0x31,0x00,
+    0x49,0x53,0x47,0x4e,0x5c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
+    0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x50,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x03,0x00,0x00,
+    0x50,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
+    0x02,0x00,0x00,0x00,0x0f,0x0f,0x00,0x00,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,
+    0x00,0xab,0xab,0xab,0x4f,0x53,0x47,0x4e,0x68,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
+    0x08,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0c,0x00,0x00,0x50,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
+    0x0f,0x00,0x00,0x00,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
+    0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x54,0x45,0x58,0x43,
+    0x4f,0x4f,0x52,0x44,0x00,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,
+    0x00,0xab,0xab,0xab,0x53,0x48,0x45,0x58,0xe0,0x00,0x00,0x00,0x50,0x00,0x01,0x00,
+    0x38,0x00,0x00,0x00,0x6a,0x08,0x00,0x01,0x5f,0x00,0x00,0x03,0x32,0x10,0x10,0x00,
+    0x00,0x00,0x00,0x00,0x5f,0x00,0x00,0x03,0x32,0x10,0x10,0x00,0x01,0x00,0x00,0x00,
+    0x5f,0x00,0x00,0x03,0xf2,0x10,0x10,0x00,0x02,0x00,0x00,0x00,0x65,0x00,0x00,0x03,
+    0x32,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x65,0x00,0x00,0x03,0xf2,0x20,0x10,0x00,
+    0x01,0x00,0x00,0x00,0x67,0x00,0x00,0x04,0xf2,0x20,0x10,0x00,0x02,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x36,0x00,0x00,0x05,0x32,0x20,0x10,0x00,0x00,0x00,0x00,0x00,
+    0x46,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x36,0x00,0x00,0x05,0xf2,0x20,0x10,0x00,
+    0x01,0x00,0x00,0x00,0x46,0x1e,0x10,0x00,0x02,0x00,0x00,0x00,0x32,0x00,0x00,0x0f,
+    0x32,0x20,0x10,0x00,0x02,0x00,0x00,0x00,0x46,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
+    0x02,0x40,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x80,0xbf,0x00,0x00,0x80,0x3f,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x08,0xc2,0x20,0x10,0x00,
+    0x02,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,0x3e,0x00,0x00,0x01,0x53,0x54,0x41,0x54,
+    0x94,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x06,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+};
+static const uint8_t _sdtx_fs_bytecode_d3d11[696] = {
+    0x44,0x58,0x42,0x43,0xb9,0x33,0xcb,0x45,0x85,0x4c,0xa6,0xca,0x23,0x8b,0xb3,0x35,
+    0xa0,0x86,0x23,0x02,0x01,0x00,0x00,0x00,0xb8,0x02,0x00,0x00,0x05,0x00,0x00,0x00,
+    0x34,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0x74,0x01,0x00,0x00,
+    0x1c,0x02,0x00,0x00,0x52,0x44,0x45,0x46,0xb8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x05,0xff,0xff,
+    0x10,0x81,0x00,0x00,0x8d,0x00,0x00,0x00,0x52,0x44,0x31,0x31,0x3c,0x00,0x00,0x00,
+    0x18,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x24,0x00,0x00,0x00,
+    0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x89,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
+    0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x5f,0x74,0x65,0x78,0x5f,0x73,0x61,0x6d,
+    0x70,0x6c,0x65,0x72,0x00,0x74,0x65,0x78,0x00,0x4d,0x69,0x63,0x72,0x6f,0x73,0x6f,
+    0x66,0x74,0x20,0x28,0x52,0x29,0x20,0x48,0x4c,0x53,0x4c,0x20,0x53,0x68,0x61,0x64,
+    0x65,0x72,0x20,0x43,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x72,0x20,0x31,0x30,0x2e,0x31,
+    0x00,0xab,0xab,0xab,0x49,0x53,0x47,0x4e,0x44,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
+    0x08,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x38,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
+    0x0f,0x0f,0x00,0x00,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x00,0xab,0xab,0xab,
+    0x4f,0x53,0x47,0x4e,0x2c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
+    0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,
+    0x74,0x00,0xab,0xab,0x53,0x48,0x45,0x58,0xa0,0x00,0x00,0x00,0x50,0x00,0x00,0x00,
+    0x28,0x00,0x00,0x00,0x6a,0x08,0x00,0x01,0x5a,0x00,0x00,0x03,0x00,0x60,0x10,0x00,
+    0x00,0x00,0x00,0x00,0x58,0x18,0x00,0x04,0x00,0x70,0x10,0x00,0x00,0x00,0x00,0x00,
+    0x55,0x55,0x00,0x00,0x62,0x10,0x00,0x03,0x32,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
+    0x62,0x10,0x00,0x03,0xf2,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x65,0x00,0x00,0x03,
+    0xf2,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x68,0x00,0x00,0x02,0x01,0x00,0x00,0x00,
+    0x45,0x00,0x00,0x8b,0xc2,0x00,0x00,0x80,0x43,0x55,0x15,0x00,0x12,0x00,0x10,0x00,
+    0x00,0x00,0x00,0x00,0x46,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x46,0x7e,0x10,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x07,
+    0xf2,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
+    0x46,0x1e,0x10,0x00,0x01,0x00,0x00,0x00,0x3e,0x00,0x00,0x01,0x53,0x54,0x41,0x54,
+    0x94,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+};
 #elif defined(SOKOL_WGPU)
 #elif defined(SOKOL_WGPU)
 static const uint8_t _sdtx_vs_bytecode_wgpu[1648] = {
 static const uint8_t _sdtx_vs_bytecode_wgpu[1648] = {
     0x03,0x02,0x23,0x07,0x00,0x00,0x01,0x00,0x08,0x00,0x08,0x00,0x2e,0x00,0x00,0x00,
     0x03,0x02,0x23,0x07,0x00,0x00,0x01,0x00,0x08,0x00,0x08,0x00,0x2e,0x00,0x00,0x00,
@@ -2937,8 +3034,8 @@ static const uint8_t _sdtx_vs_bytecode_wgpu[940] = {
     0x19,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00,
     0x19,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00,
 };
 };
 #elif defined(SOKOL_DUMMY_BACKEND)
 #elif defined(SOKOL_DUMMY_BACKEND)
-static const char* _sdtx_vs_src = "";
-static const char* _sdtx_fs_src = "";
+static const char* _sdtx_vs_src_dummy = "";
+static const char* _sdtx_fs_src_dummy = "";
 #else
 #else
 #error "Please define one of SOKOL_GLCORE33, SOKOL_GLES2, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!"
 #error "Please define one of SOKOL_GLCORE33, SOKOL_GLES2, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!"
 #endif
 #endif
@@ -3249,9 +3346,12 @@ static void _sdtx_setup_common(void) {
     shd_desc.attrs[0].name = "position";
     shd_desc.attrs[0].name = "position";
     shd_desc.attrs[1].name = "texcoord0";
     shd_desc.attrs[1].name = "texcoord0";
     shd_desc.attrs[2].name = "color0";
     shd_desc.attrs[2].name = "color0";
-    shd_desc.attrs[0].sem_name = "POSITION";
+    shd_desc.attrs[0].sem_name = "TEXCOORD";
+    shd_desc.attrs[0].sem_index = 0;
     shd_desc.attrs[1].sem_name = "TEXCOORD";
     shd_desc.attrs[1].sem_name = "TEXCOORD";
-    shd_desc.attrs[2].sem_name = "COLOR";
+    shd_desc.attrs[1].sem_index = 1;
+    shd_desc.attrs[2].sem_name = "TEXCOORD";
+    shd_desc.attrs[2].sem_index = 2;
     shd_desc.fs.images[0].name = "tex";
     shd_desc.fs.images[0].name = "tex";
     shd_desc.fs.images[0].type = SG_IMAGETYPE_2D;
     shd_desc.fs.images[0].type = SG_IMAGETYPE_2D;
     #if defined(SOKOL_GLCORE33)
     #if defined(SOKOL_GLCORE33)
@@ -3286,14 +3386,18 @@ static void _sdtx_setup_common(void) {
                 break;
                 break;
         }
         }
     #elif defined(SOKOL_D3D11)
     #elif defined(SOKOL_D3D11)
-        shd_desc.vs.source = _sdtc_vs_bytecode_d3d11;
-        shd_desc.fs.source = _sdtc_fs_bytecode_d3d11;
+        shd_desc.vs.byte_code = _sdtx_vs_bytecode_d3d11;
+        shd_desc.vs.byte_code_size = sizeof(_sdtx_vs_bytecode_d3d11);
+        shd_desc.fs.byte_code = _sdtx_fs_bytecode_d3d11;
+        shd_desc.fs.byte_code_size = sizeof(_sdtx_fs_bytecode_d3d11);
     #elif defined(SOKOL_WGPU)
     #elif defined(SOKOL_WGPU)
-        shd_desc.vs.source = _sdtc_vs_wgpu;
-        shd_desc.fs.source = _sdtc_fs_wgpu;
+        shd_desc.vs.byte_code = _sdtx_vs_bytecode_wgpu;
+        shd_desc.vs.byte_code_size = sizeof(_sdtx_vs_bytecode_wgpu);
+        shd_desc.fs.byte_code = _sdtx_fs_bytecode_wgpu;
+        shd_desc.fs.byte_code_size = sizeof(_sdtx_fs_bytecode_wgpu);
     #else
     #else
-        shd_desc.vs.source = _sdtc_vs_dummy;
-        shd_desc.fs.source = _sdtc_fs_dummy;
+        shd_desc.vs.source = _sdtx_vs_src_dummy;
+        shd_desc.fs.source = _sdtx_fs_src_dummy;
     #endif
     #endif
     _sdtx.shader = sg_make_shader(&shd_desc);
     _sdtx.shader = sg_make_shader(&shd_desc);
     SOKOL_ASSERT(SG_INVALID_ID != _sdtx.shader.id);
     SOKOL_ASSERT(SG_INVALID_ID != _sdtx.shader.id);
@@ -3647,7 +3751,7 @@ SOKOL_API_DECL void sdtx_puts(const char* str) {
     _sdtx_context_t* ctx = _sdtx.cur_ctx;
     _sdtx_context_t* ctx = _sdtx.cur_ctx;
     if (ctx) {
     if (ctx) {
         char chr;
         char chr;
-        while ( (chr = *str++) ) {
+        while (0 != (chr = *str++)) {
             _sdtx_put_char(ctx, chr);
             _sdtx_put_char(ctx, chr);
         }
         }
     }
     }
@@ -3670,6 +3774,7 @@ SOKOL_API_DECL void sdtx_putr(const char* str, int len) {
 SOKOL_API_DECL int sdtx_printf(const char* fmt, ...) {
 SOKOL_API_DECL int sdtx_printf(const char* fmt, ...) {
     SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     // FIXME
     // FIXME
+    _SOKOL_UNUSED(fmt);
     return 0;
     return 0;
 }
 }
 
 
@@ -3677,7 +3782,7 @@ SOKOL_API_IMPL void sdtx_draw(void) {
     SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
     _sdtx_context_t* ctx = _sdtx.cur_ctx;
     _sdtx_context_t* ctx = _sdtx.cur_ctx;
     if (ctx) {
     if (ctx) {
-        const int num_verts = ctx->cur_vertex_ptr - ctx->vertices;
+        const int num_verts = (int) (ctx->cur_vertex_ptr - ctx->vertices);
         if (num_verts > 0) {
         if (num_verts > 0) {
             SOKOL_ASSERT((num_verts % 6) == 0);
             SOKOL_ASSERT((num_verts % 6) == 0);
             int vbuf_offset = sg_append_buffer(ctx->vbuf, ctx->vertices, num_verts * sizeof(_sdtx_vertex_t));
             int vbuf_offset = sg_append_buffer(ctx->vbuf, ctx->vertices, num_verts * sizeof(_sdtx_vertex_t));