Skip to content
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

XGL cache creator tool #64

Closed
5 of 7 tasks
s-perron opened this issue Sep 16, 2020 · 4 comments
Closed
5 of 7 tasks

XGL cache creator tool #64

s-perron opened this issue Sep 16, 2020 · 4 comments
Labels

Comments

@s-perron
Copy link
Contributor

s-perron commented Sep 16, 2020

Background

There has been a lot of work in LLPC over the past 9 months to implement relocatable shaders. These were intended to provide a way to compile shaders “offline”, that is without running a vulkan application. However for that to be useful, there must be a way for a vulkan application to make use of the precompiled shaders.

To this end, we want to write a tool that will take the precompiled shaders and build a file whose contents can be passed as the initial data to vkCreatePipelineCache. This tool should live in the XGL repository because XGL controls the format of the cache when it is serialized by vkGetPipelineCacheData.

This will be a standalone tool that will have its own subdirectory in the tools directory.

Implementation details

Prerequisites

  • Game developers must be able to use amdllpc to compile shaders and get an elf file.
  • The elf file will contain the cache hash for the shader/pipeline in the PAL metadata.
    • The PAL metadata already contains the internal pipeline hash, but that seems to be compacted to 64-bits before it is assigned. Could this be expanded to 128-bits?
    • This entry is only added during pipeline finalization, so the PAL metadata for a relocatable shader does not currently contain it.
    • If we decide we only want this to work for relocatable shaders, then we could add something specific to relocatable shaders, but I would like something more general.

XGL cache creator

Command line interface

xlg_cache_creator [options] <input elf files>

Options:

-o <filename>          - The filename to output the cache data to. 
                         Required.
-device_id=<device id> - The device id of the device this cache will be used on.
                         The device id can be found at
                         https://devicehunt.com/view/type/pci/vendor/1002.
                         If this option is not provided, the device id will be
                         queried from the runtime.
-uuid=<uuid>           - The uuid for the specific driver and machine.
                         <How can the uuid be found?>
                         If this option is not provided, the device id will be
                         queried from the runtime.

Algorithm

  • Open the output file and set the position past the header size
  • Initialize the key platform using the uuid.
  • For each input elf file
    • Open the file, and copy the contents to the output buffer.
    • Add the contents of the file to the hash context
      • I would like to avoid having everything in memory at the same time.
  • Output the PipelineBinaryCachePrivateHeader using the standard malloc and free as the allocators.
  • Output the header generated by vkGetPipelineCacheData

Task list

  • Modify the internal pipeline hash to be a 128-bit value for the cache hash. (Cannot do)
  • Modify LLPC to emit a new elf section llpc_cache_hash contianing the 128-bit hash for the ELF file being generated.
  • Modify the unlinked shader path in LLPC to add the internal pipeline hash to the metadata.
  • Refactor PhysicalDevice::InitializePlatformKey so:
    • The UUID is passed in as a parameter and used in place of the device properties.
    • Allocation functions are passed as parameters so the vk instance is not needed.
    • The time stamp is not used since the UUID is already the result of hashing the time stamp.
    • The platform key that is created is returned.
    • Make it available to the cache creator tool without needing a PhysicalDevice.
  • Refactor CalculateHashId:
    • Replace the pInstance parameter with the allocation and deallocation functions, so that an Instance is not needed.
    • Make it available to the cache creator tool.
  • Refactor vkGetPipelineCacheData code that writes the header into a function (WriteVkCacheHeader?) the cache creator tool can call.
  • Write the cache creator tool:
    • Uses the new InitializePlatformKey, CalculateHashId, and WriteVkCacheHeader.
    • Uses the ElfReader to read the elf and extract the PAL metadata.
    • Uses MsgPackReader to read the PAL metadata to get the hash.
@s-perron
Copy link
Contributor Author

Modify the internal pipeline hash to be a 128-bit value for the cache hash.

This might not be so easy. PAL makes use of the internal pipeline cache hash, and they expect it to be 64-bits. Changing that would be a big change.

@JonCampbell407
Copy link

Can you modify amdllpc to output the 128 bit hash in addition to the elf? Then the input to xgl_cache_creator would be a set of 128 bit hash and elf pairs.

Not really tied to this proposal but it is a bit concerning that we have two different mechanisms for calculating a hash that is stored in the same cache. I'm not sure if this is going to cause issues.

I think the refactoring you mention should be fine. Are you planning to keep the code in the same files they are now or put them in a separate file to minimize what needs to be compiled into xgl_cache_creator?

@s-perron
Copy link
Contributor Author

Can you modify amdllpc to output the 128 bit hash in addition to the elf? Then the input to xgl_cache_creator would be a set of 128 bit hash and elf pairs.

If you are thinking of amdllpc output two separate files then I would not like that idea. I want to the hash to somehow be included in the elf file so that less book keeping needs to be down both other tools. However, I am will to do that if that is what you want.

My preference would be to do something like add a new section to the elf that contains the hash, or a new pal metadata entry. The elf section would partially do what you want, "minimize what needs to be compiled into xlg_cache_creator", because the tool won't need to read the pal metadata.

Are you planning to keep the code in the same files they are now or put them in a separate file to minimize what needs to be compiled into xgl_cache_creator?

I would like a separate file, but I'm not too concerned about that.

@JonCampbell407
Copy link

You can have a section of the elf that PAL ignores. GetGenericSection() and SetGenericSection() are the functions to do that in PAL.

kuhar added a commit to kuhar/xgl that referenced this issue Nov 12, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 12, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 12, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 12, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 12, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 13, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 16, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 16, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 16, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 16, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 16, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
kuhar added a commit to kuhar/xgl that referenced this issue Nov 17, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See GPUOpen-Drivers#64 for more details on
the high-level direction.
JaxLinAMD pushed a commit that referenced this issue Nov 19, 2020
This refactoring in preparation to be able to use PipelineBinaryCache in
an offline tool, without having to run with a Vulkan device installed.

See #64 for more details on
the high-level direction.
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 8, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 11, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 11, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 11, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 11, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 12, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 12, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 12, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 12, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 13, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 13, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 13, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

V1: Remove dependency of `util`, `llpc` from `lgc` to fix build failure.
V2: Fix typo "PiplineHashCode" -> "PipelineHashCode".
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 14, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a seperate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new ".note" section and its section header
for cache hash:

```
|-------------|        |-------------|
| ELF header  |        | ELF header  |
|-------------|        |-------------|
| Sections    |        | Sections    |
| ...         |        | ...         |
|-------------|  ==>   |-------------|
| Section     |        | Section     |
| headers     |        | headers     |
| ...         |        | ...         |
|-------------|        |-------------|
| Sections    |        | New section |
| ...         |---|    | header for  |
|-------------|   |    | hash note   |    This new section header's
                  |    | section    +|--| offset must be the new
   Remaining      |    |-------------|  | note section for cache hash
   sections after |    | New note    |  |
   section header |    | section for |<-/
   table must be  |    | cache hash  |
   shifted        |    |-------------|
                  \--->| Sections    |
                       | ...         |
                       |-------------|
```

The new note section for the cache hash will contain two note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), the new note section will be

```
.note (size = 80 bytes)
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 20, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 20, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 21, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 21, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 21, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 22, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
jaebaek added a commit to jaebaek/llpc that referenced this issue Jan 28, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
JaxLinAMD pushed a commit to GPUOpen-Drivers/llpc that referenced this issue Jan 29, 2021
When LLPC checks shader and pipeline caches, it uses the hash for
the identifier to check if required ELF files exist in the cache file.
Since the cache file keeps the mapping between the hashes and the ELF
files, we do not keep the hash value in the ELF file.

On the other hand, we need the cache creator proposed in
GPUOpen-Drivers/xgl#64 to build the cache
for relocatable shader ELFs, but the cache creator does not have any
information about the hash. It is because the hash is generated by
LLPC (or amdllpc) and the cache creator is a separate program.

We want to let the LLPC compiler create a new note section for the
cache hash.  It can be used for the cache creator to create the cache
file with the correct mapping between the hash and ELF.

ELF layouts before/after adding new note entries for cache hash and
LLPC version to the existing note section:

```
|-------------|             |-------------|
| ELF header  |             | ELF header  |
|-------------|             |-------------|
| Sections    |             | Sections    |
| ...         |             | ...         |
|-------------|             |-------------|
| Note section|     ==>     | Note section|
| ...         |             |             |
|-------------|<--(Will be  | + New note  |
| ...         |    Shifted) |   entries   |
|-------------| |        |  | ...         |
| Section     | |        \->|-------------|
| headers     | V           | ...         |
| ...         |             |-------------|
                            | Section     |
                            | headers     |
                            | ...         |
```

New note entries:
 1. Note name with "llpc_cache_hash" and note description with the cache hash used for the cache lookup.
 2. Note name with "llpc_version" and note description with the LLPC version - both major and minor.
    The LLPC version information will help us to understand the hash generation algorithm. We have to
    use a correct hash algorithm for the cache lookup.

For example, if the hash is "4EDBED25 ADF15238 B8C92579 423DA423" and the LLPC version is 45.4
(the major version is 45=0x2D and the minor version is 4=0x04), two new note entries will be

```
 Unknown(0)                (name = llpc_cache_hash  size = 16)
       0:4EDBED25 ADF15238 B8C92579 423DA423
 Unknown(0)                (name = llpc_version  size = 8)
       0:0000002D 00000004
```
@jinjianrong jinjianrong added the doc label Mar 9, 2021
@kuhar kuhar closed this as completed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants