Skip to content

Commit

Permalink
- update jsn, render graph / views docs. add infor about import
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Mar 15, 2023
1 parent aa803d2 commit 852f7a7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 33 deletions.
45 changes: 38 additions & 7 deletions docs/v2.pmfx_doc
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/// this is the full schema for pmfx -v2 specification
/// members are listed with their default values, possible values for enums and type ranges are listed in the comments.

/// you can import other .pmfx files, and utilise jsn merging and inheritence
import other_files.pmfx

/// top level structure, you can omit any sub objects if you do not need them.
/// optional (null) members can be omited entirely
pmfx: {
{
/// list of include files
include: [
/// include hlsl source code
"shader_file.hlsl"
/// include other pmfx files to share pipelines / render states
"pmfx_file.pmfx"
]
pipelines: {
/// key-value objects of `pipeline`
Expand Down Expand Up @@ -313,9 +314,21 @@ raster_states: {
conservative_raster_mode: false
}

/// specify a texture or render target
/// specify a texture or render target.. spec is still work in progress, but here is a current example
texture: {

main_colour: {
ratio: {
window: "main_window",
scale: 1.0
}
format: RGBA8n
usage: [ShaderResource, RenderTarget]
samples: 8
}
main_depth(main_colour): {
format: D24nS8u
usage: [ShaderResource, DepthStencil]
}
}

/// specify a view (a render pass into a render target)
Expand All @@ -340,7 +353,25 @@ view: {
camera: ""
}

/// specify a render graph (collection of views with dependencies)
/// specify a render graph (collection of views with dependencies).. spec is still work in progress, but here is a current example
render_graph: {

mesh_debug: {
grid: {
view: "main_view"
pipelines: ["imdraw_3d"]
function: "render_grid"
}
meshes: {
view: "main_view_no_clear"
pipelines: ["mesh_debug"]
function: "render_meshes"
depends_on: ["grid"]
}
wireframe: {
view: "main_view_no_clear"
pipelines: ["wireframe_overlay"]
function: "render_meshes"
depends_on: ["meshes", "grid"]
}
}
}
29 changes: 25 additions & 4 deletions jsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
import platform


# print error with colour
def print_error(msg):
ERROR = '\033[91m'
ENDC = '\033[0m'
print(ERROR + msg + ENDC, flush=True)


# print wanring with colour
def print_warning(msg):
WARNING = '\033[93m'
ENDC = '\033[0m'
print(WARNING + msg + ENDC, flush=True)


# print error with colour
def print_ok(msg):
OK = '\033[92m'
ENDC = '\033[0m'
print(OK + msg + ENDC, flush=True)


# struct to store the build info for jobs from parsed commandline args
class BuildInfo:
inputs = [] # list of files
Expand Down Expand Up @@ -539,7 +560,7 @@ def inherit_dict_recursive(d, d2):
if i in d2.keys():
inherit_dict(d, d2[i])
else:
print("[jsn error] missing key `" + i + "` used by jsn_inherit")
print_error("[jsn error] missing key `" + i + "` used by jsn_inherit")
sys.exit(1)
for k, v in d.items():
if type(v) == dict:
Expand Down Expand Up @@ -571,7 +592,7 @@ def get_imports(jsn, import_dirs):
found = True
break
if not found:
print("[jsn error]: cannot find import file " + stripped)
print_error("[jsn error]: cannot find import file " + stripped)
sys.exit(1)
return jsn[bp:], imports

Expand Down Expand Up @@ -616,7 +637,7 @@ def resolve_vars(value, vars):
else:
return vars[var_name]
else:
print("[jsn error] undefined variable '" + var_name + "'")
print_error("[jsn error] undefined variable '" + var_name + "'")
sys.exit(1)
count += 1
return None
Expand Down Expand Up @@ -681,7 +702,7 @@ def resolve_platform_keys(d):
if platform.system() in name_lookup:
platform_name = name_lookup[platform.system()]
else:
print("[jsn warning] unknown platform system " + platform.system())
print_warning("[jsn warning] unknown platform system " + platform.system())
resolve_platform_keys_recursive(d, platform_name)


Expand Down
13 changes: 11 additions & 2 deletions pmfx_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ def generate_shader_info(pmfx, entry_point, stage, permute=None):
# resource categories
resource_categories = get_resource_categories()
# start with entry point src code
if entry_point not in pmfx["functions"]:
build_pmfx.print_error(" error: {} missing shader entry point: {}".format(entry_point))
return None
src = pmfx["functions"][entry_point]["source"]
resources = dict()
vertex_elements = None
Expand Down Expand Up @@ -594,7 +597,8 @@ def generate_shader_info(pmfx, entry_point, stage, permute=None):
# generate shader info permutations
def generate_shader_info_permutation(pmfx, entry_point, stage, permute, define_list):
info = generate_shader_info(pmfx, entry_point, stage, permute)
info["permutation_id"] = build_pmfx.generate_permutation_id(define_list, permute)
if info:
info["permutation_id"] = build_pmfx.generate_permutation_id(define_list, permute)
return stage, entry_point, info


Expand Down Expand Up @@ -637,6 +641,9 @@ def generate_pipeline_permutation(pipeline_name, pipeline, output_pmfx, shaders,
for stage in get_shader_stages():
if stage in pipeline:
entry_point = pipeline[stage]
if entry_point not in shaders[stage]:
output_pipeline["error_code"] = 1
continue
# lookup shader info, and redirect to shared shaders
shader_info = shaders[stage][entry_point][pemutation_id]
if "lookup" in shader_info:
Expand Down Expand Up @@ -689,7 +696,7 @@ def generate_pipeline_permutation(pipeline_name, pipeline, output_pmfx, shaders,

# load a pmfx file into dictionary()
def load_pmfx_jsn(filepath, root):
pmfx = jsn.loads(open(os.path.join(root, filepath), "r").read())
pmfx = jsn.load_from_file(os.path.join(root, filepath), [], False)
all_included_files = []
all_shader_source = ""
if "include" in pmfx:
Expand Down Expand Up @@ -833,6 +840,8 @@ def generate_pmfx(file, root):
added_hashes = dict()
for job in permutation_jobs:
stage, entry_point, info = job.get()
if not info:
continue
# add an entry
if entry_point not in shaders[stage]:
shaders[stage][entry_point] = dict()
Expand Down
43 changes: 23 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,14 @@ Version 2 is currently work in progress, currently only HLSL is the only support
Use `.hlsl` files and hlsl source code, create a `.pmfx` which can create pipelines from small amount of meta data:

```jsonnet
pmfx: {
import other_files.pmfx
{
// include shader source files
include: [
"imdraw.hlsl"
]
// create pipelines
pipelines: {
imdraw_2d: {
vs: vs_2d
Expand All @@ -491,32 +495,31 @@ pmfx: {
topology: "LineList"
}
}
}
```

Pipeline states can be specified and included in `.pmfx` files:

```jsonnet
pmfx: {
depth_stencil_states: {
depth_test_less: {
depth_enabled: true
depth_write_mask: All
depth_func: Less
}
depth_stencil_states: {
depth_test_less: {
depth_enabled: true
depth_write_mask: All
depth_func: Less
}
raster_states: {
wireframe: {
fill_mode: Wireframe
depth_bias: -5
}
cull_back: {
cull_mode: Back
}
}
raster_states: {
wireframe: {
fill_mode: Wireframe
depth_bias: -5
}
pipelines: {
imdraw_mesh: {
depth_stencil_state: "depth_test_less"
}
cull_back: {
cull_mode: Back
}
}
pipelines: {
imdraw_mesh: {
depth_stencil_state: "depth_test_less"
}
}
```
Expand Down

0 comments on commit 852f7a7

Please sign in to comment.