1 module sbylib.graphics.layer.setting; 2 3 import std; 4 5 struct LayerSettings { 6 LayerSetting[] settings; 7 8 enum fileName = "vk_layer_settings.txt"; 9 10 void finalize() { 11 import std.file : fremove = remove; 12 if (fileName.exists) 13 fremove(fileName); 14 } 15 16 string[] use() { 17 writeToFile(); 18 return getNames(); 19 } 20 21 private string[] getNames() { 22 return settings.map!(s => s.getName()).array; 23 } 24 25 private void writeToFile() { 26 foreach (setting; settings) 27 setting.writeToFile(fileName); 28 } 29 } 30 31 class LayerSetting { 32 33 enum setting; 34 35 protected string vendorName; 36 protected string layerName; 37 38 enum ReportFlag { 39 info = "info", 40 warn = "warn", 41 perf = "perf", 42 error = "error", 43 debug_ = "debug" 44 } 45 46 enum DebugAction { 47 Ignore = "VK_DBG_LAYER_ACTION_IGNORE", 48 LogMessage = "VK_DBG_LAYER_ACTION_LOG_MSG", 49 DebugOutput = "VK_DBG_LAYER_ACTION_DEBUG_OUTPUT", 50 } 51 52 @setting { 53 ReportFlag[] report_flags; 54 DebugAction debugAction; 55 string log_filename; 56 } 57 58 this(string vendorName, string layerName) { 59 this.vendorName = vendorName; 60 this.layerName = layerName; 61 } 62 63 string getName() { 64 return format!"VK_LAYER_%s_%s"(vendorName.toUpper, layerName); 65 } 66 67 abstract void writeToFile(string path); 68 69 mixin template Impl() { 70 override void writeToFile(string path) { 71 import std : format, join; 72 import std.file : fwrite = write; 73 import sbylib.graphics.util.member : getMembersByUDA; 74 75 string[] content; 76 static foreach (memberInfo; getMembersByUDA!(typeof(this), setting)) { 77 content ~= format!"%s_%s.%s = %s"(vendorName, layerName, memberInfo.name, write(memberInfo.member)); 78 } 79 path.fwrite(content.join("\n")); 80 } 81 82 private string write(T : bool)(T value) { 83 return value ? "TRUE" : "FALSE"; 84 } 85 86 private string write(T : string)(T value) { 87 return value; 88 } 89 90 private string write(T : E[], E)(T value) { 91 import std : map, join; 92 return value.map!(v => write(v)).join(","); 93 } 94 95 private string write(T)(T value) { 96 import std : to; 97 return value.to!string; 98 } 99 } 100 }