-
-
Notifications
You must be signed in to change notification settings - Fork 45
Store binding slots #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pusewicz
wants to merge
4
commits into
RandyGaul:master
Choose a base branch
from
pusewicz:324-binfings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Store binding slots #332
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -369,9 +369,11 @@ CF_ShaderCompilerResult cute_shader_compile(const char* source, CF_ShaderCompile | |
| int num_uniform_members; | ||
| CF_ShaderUniformMemberInfo* uniform_members = NULL; | ||
| uint32_t num_inputs = 0; | ||
| int* image_binding_slots = NULL; | ||
| CF_ShaderInputInfo* inputs = NULL; | ||
| { | ||
| std::vector<const char*> image_names_vec; | ||
| std::vector<int> image_binding_slots_vec; | ||
| std::vector<CF_ShaderUniformInfo> uniforms_vec; | ||
| std::vector<CF_ShaderUniformMemberInfo> uniform_members_vec; | ||
|
|
||
|
|
@@ -389,6 +391,7 @@ CF_ShaderCompilerResult cute_shader_compile(const char* source, CF_ShaderCompile | |
| case SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: | ||
| { | ||
| image_names_vec.push_back(strdup(binding->name)); | ||
| image_binding_slots_vec.push_back(binding->binding); | ||
| } // Fall-thru. | ||
| case SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER: ++num_samplers; break; | ||
| case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE: ++num_storage_textures; break; | ||
|
|
@@ -432,6 +435,8 @@ CF_ShaderCompilerResult cute_shader_compile(const char* source, CF_ShaderCompile | |
| if (num_images > 0) { | ||
| image_names = (const char**)malloc(sizeof(char*) * num_images); | ||
| memcpy(image_names, image_names_vec.data(), sizeof(char*) * num_images); | ||
| image_binding_slots = (int*)malloc(sizeof(int) * num_images); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be freed in |
||
| memcpy(image_binding_slots, image_binding_slots_vec.data(), sizeof(int) * num_images); | ||
| } | ||
|
|
||
| num_uniforms = (int)uniforms_vec.size(); | ||
|
|
@@ -480,6 +485,7 @@ CF_ShaderCompilerResult cute_shader_compile(const char* source, CF_ShaderCompile | |
|
|
||
| .num_images = num_images, | ||
| .image_names = image_names, | ||
| .image_binding_slots = image_binding_slots, | ||
|
|
||
| .num_uniforms = num_uniforms, | ||
| .uniforms = uniforms, | ||
|
|
@@ -520,6 +526,7 @@ void cute_shader_free_result(CF_ShaderCompilerResult result) | |
| free((char*)shader_info->image_names[i]); | ||
| } | ||
| free(shader_info->image_names); | ||
| free((int*)shader_info->image_binding_slots); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the cast to free is not necessary if it wasn't const in the struct in the first place. |
||
|
|
||
| free((void*)result.bytecode.content); | ||
| free((char*)result.preprocessed_source); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I only meant the global variable generated by the shader compiler.
Because they get used by the static initializer later.
This doesn't have to be const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually has to, as otherwise the generated values cannot be assigned to the struct member:
This is what it's generated as:
static const int* const s_backbuffer_fs_bytecode_image_binding_slots = NULL;And here it's being assigned:
.image_binding_slots = s_backbuffer_fs_bytecode_image_binding_slots,So unless there's a better way of doing it, it has to stay as is?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the problem is not in the generated code.
The declaration in the struct member does not have to be
const int*.It can just be
int* image_binding_slots.It's only
const int* constin the generated code because some compilers in C mode complains that static initializer has to be constant expression.