Skip to content

Commit

Permalink
- quick addition to support groupshared in global scope
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Apr 21, 2023
1 parent 8b1d8f2 commit 32bee31
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
18 changes: 18 additions & 0 deletions examples/v2/v2_examples.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,22 @@ struct indirect_args {
vs_output vs_test_nested_structures() {
vs_output output = vs_output_default();
return output;
}

//
// global types / compute sync
//

groupshared uint4 accumulated;

void cs_mip_chain_texture2d(uint2 did: SV_DispatchThreadID) {

accumulated = uint4(0, 0, 0, 0);

GroupMemoryBarrierWithGroupSync();

uint original;
InterlockedAdd(accumulated.x, 1, original);

GroupMemoryBarrierWithGroupSync();
}
25 changes: 23 additions & 2 deletions pmfx_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ def get_resource_categories():
]


# return global types we want to check for within source
def get_global_types():
return [
"groupshared"
]


# returns info for types, (num_elements, element_size, total_size)
def get_type_size_info(type):
lookup = {
Expand Down Expand Up @@ -727,7 +734,8 @@ def generate_shader_info(pmfx, entry_point, stage, permute=None):
if entry_point not in pmfx["functions"]:
build_pmfx.print_error(" error: missing shader entry point: {}".format(entry_point))
return None
# start with entry point src code

# start globals then with entry point src code
src = pmfx["functions"][entry_point]["source"]
resources = dict()
vertex_elements = None
Expand Down Expand Up @@ -786,6 +794,11 @@ def generate_shader_info(pmfx, entry_point, stage, permute=None):
resources[r] = add_used_shader_resource(resource, stage)
break

# add any globals..
globals = ""
for g in pmfx["globals"]:
globals += g + "\n"

# create resource src code
res = ""

Expand Down Expand Up @@ -823,7 +836,7 @@ def generate_shader_info(pmfx, entry_point, stage, permute=None):
res += fwd + "\n"

# join resource src and src
src = cgu.format_source(res, 4) + "\n // source\n" + cgu.format_source(src, 4)
src = cgu.format_source(res, 4) + "\n // source\n" + globals + "\n" + cgu.format_source(src, 4)

if permute:
# evaluate permutations on the full source including resources
Expand Down Expand Up @@ -1129,6 +1142,14 @@ def generate_pmfx(file, root):
continue
pmfx["resources"][map["category"]][decl["name"]] = decl

# parse globals
pmfx["globals"] = set()
src_lines = pmfx["source"].splitlines()
for global_type in get_global_types():
for line in src_lines:
if line.startswith(global_type):
pmfx["globals"].add(line)

# fill state default parameters
for state_type in get_states():
if state_type in pmfx["pmfx"]:
Expand Down

0 comments on commit 32bee31

Please sign in to comment.