On Tue, Jan 2, 2018 at 4:55 PM, Ian Romanick <i...@freedesktop.org> wrote:
> On 01/02/2018 04:24 PM, Grazvydas Ignotas wrote: > > On Tue, Jan 2, 2018 at 6:30 PM, Jason Ekstrand <ja...@jlekstrand.net> > wrote: > >> --- > >> src/compiler/spirv/spirv_to_nir.c | 29 +++++++++++++++++++++++++++++ > >> src/compiler/spirv/vtn_private.h | 1 + > >> 2 files changed, 30 insertions(+) > >> > >> diff --git a/src/compiler/spirv/spirv_to_nir.c > b/src/compiler/spirv/spirv_to_nir.c > >> index dcff56f..751fb03 100644 > >> --- a/src/compiler/spirv/spirv_to_nir.c > >> +++ b/src/compiler/spirv/spirv_to_nir.c > >> @@ -31,6 +31,9 @@ > >> #include "nir/nir_constant_expressions.h" > >> #include "spirv_info.h" > >> > >> +#include <fcntl.h> > >> +#include <unistd.h> > >> + > >> void > >> vtn_log(struct vtn_builder *b, enum nir_spirv_debug_level level, > >> size_t spirv_offset, const char *message) > >> @@ -94,6 +97,27 @@ vtn_log_err(struct vtn_builder *b, > >> ralloc_free(msg); > >> } > >> > >> +static void > >> +vtn_dump_shader(struct vtn_builder *b, const char *path, const char > *prefix) > >> +{ > >> + static int idx = 0; > >> + > >> + char filename[1024]; > >> + int len = snprintf(filename, sizeof(filename), "%s/%s-%d.spirv", > >> + path, prefix, idx++); > >> + if (len < 0 || len >= sizeof(filename)) > >> + return; > >> + > >> + int fd = open(filename, O_CREAT | O_CLOEXEC | O_WRONLY, 0777); > >> + if (fd < 0) > >> + return; > >> + > >> + write(fd, b->spirv, b->spirv_word_count * 4); > > > > Feel free to ignore, but what about * sizeof(b->spirv[0]) ? > > > > also, this emits a not-so-useful warning for me: > > warning: ignoring return value of ‘write’, declared with attribute > > warn_unused_result [-Wunused-result] > > (and no, sticking (void) before write() doesn't help) > > Oh, that's annoying... but technically correct. The problem is that > write() might only write part of your data. If the returned size is > less than the size you asked, you have to try again. This is why people > use fopen/fwrite/fclose. :) Either that or: > fopen/fwrite/fclose it is! > > ssize_t remain = b->spirv_word_count * 4; > unsigned offset = 0; > > do { > ssize_t written = > write(fd, (uint8_t *) b->spriv + offset, remain); > > if (written < 0) { > /* Error. Bail out. */ > break; > } > > remain -= written; > offset += written; > } while (remain > 0); > > I'll let Jason pick. :D > > > Gražvydas > > _______________________________________________ > > mesa-dev mailing list > > mesa-dev@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/mesa-dev >
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev